Desired scenario: a small subnetwork of Linux machines, all accessible through another Linux machine (acting as an IP router). These machines would be pre-configured with addresses on a private network (192.168.x.x or 10.x.x.x). However, each would be accessible though the routing machine with public IP addresses, one for each, configured on the routing machine.

This would be similar to NAT or IP masquerading, but with separate public IP addresses. (It is acceptable to assume that the public network will have a gateway address: external router.)

It seems like this should be doable with address translation but I cannot figure out how to configure this. I am not able to find anything searching.

Can this be configured, and if so, how?


Assuming, IP_EXT1 and IP_EXT2 are the external IP addresses for respectively machines #1 and #2, and IP_INT1 and IP_INT2 their respective internal IP addresses.

IP_EXT1 and IP_EXT2 are in fact addresses of the routing machine, either aliases for the same network interface or two distinct interfaces.

Then, the iptables configuration on the routing machine should be as simple as (untested):

iptables -t nat -A POSTROUTING --destination $IP_EXT1 -j DNAT --to-destination $IP_INT1
iptables -t nat -A POSTROUTING --source $IP_INT1 -j SNAT --to-source $IP_EXT1
iptables -t nat -A POSTROUTING --destination $IP_EXT2 -j DNAT --to-destination $IP_INT2
iptables -t nat -A POSTROUTING --source $IP_INT2 -j SNAT --to-source $IP_EXT2
  • Thank you - one more question. I also don't want to configure the public network's gateway on the internal machines. Would I do the same thing for $IP_INTG and $IP_EXTG? – DoxyLover Nov 15 '14 at 18:40
  • Hmmm, I'm not sure to understand. You need some rules on the gateway to route the packets correctly, but the internal machines do not need to know the gateway's external IP address. – lgeorget Nov 15 '14 at 18:51
  • Nevermind, I think I understand now. Thanks again. – DoxyLover Nov 15 '14 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.