[home] [packages] [docs] [apt] [links] [mirrors] [lists] [misc] [about]

Some quick tips n' tricks

Dedicated, fixed network address translation for a single host

It's in fact quite easy. Say we have a gateway server with :

eth0 (LAN) :
eth1 (WAN) :

We will pretend the network is routable. From the LAN, we want to "masquerade" the client to always appear as when going out through the gateway, so :

iptables -t nat -A PREROUTING -i eth1 -s -j DNAT --to-destination

This will apply destination network address translation, and will take care of mangling all further packets. It is only necessary if you want the LAN host reachable from the outside on the aliased address (probably a bad idea security-wise).

iptables -t nat -A POSTROUTING -i eth0 -s -j SNAT --to-source

This will apply source network address translation (changes the source of the packet from the LAN address to the WAN one). This is similar to what the MASQUERADE does, but better suited for fixed connections as you can read in the man page "if you have a static IP address, you should use the SNAT target".

iptables -A FORWARD -i eth1 -o eth0 -d -j ACCEPT

This will allow the mangled packets from the PREROUTING rule to reach the LAN host if your default FORWARD policy is not ACCEPT. You can of course place firewall or logging rules to your liking. Read the iptables(8) man page for all details.

Useful commands :

iptables -L -v
iptables -t nat -L -v
service iptables save

Password-less ssh access

On the client, as the user who will be starting the ssh connections :

ssh-keygen -d

Just press enter when prompted for the passphrase. You'll then get both the private (~/.ssh/id_dsa) and the public (~/.ssh/id_dsa.pub) keys.
On the server, append the content of the client's public key file to the ~/.ssh/authorized_keys file (with some older openssh versions, this may be ~/.ssh/authorized_keys2). Make sure there are no permissions set for group or other on the ~/.ssh/ directories (mode 700) and the files they contain (mode 600).