Setup NAT with iptables
TheĀ Setup Having this setup where Machine A like to connect the Internet via Machine B.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
+-------------------+ +-----------------+ | | | Machine B | | Machine A | | (the gateway) | | (the client) | | | | | | | | eth0 +----------+ eth0 eth1 | +-------------------+ +-------------+---+ | | .-~~~-. | .- ~ ~-( )_ _ | / ~ -. | | internet \<----+ \ .' ~- . _____________ . -~ |
Add the following lines to the iptables
1 2 3 |
iptables -I FORWARD -o eth0 -m comment --comment "NAT" -j ACCEPT iptables -I FORWARD -i eth0 -m comment --comment "NAT" -j ACCEPT iptables -I POSTROUTING -o eth1 -m comment --comment "NAT" -j MASQUERADE -t nat |
and make sure to enable forwarding on Machine B...