How to NAT a Windows PC through a Linux server?

2

I have to NAT a Windows PC with IP 10.10.10.10 through a Linux server with two network cards. The IP addresses of the NICs are 20.20.20.50 (connected to an external network) and 10.10.10.9. The second NIC is conneted to the Windows PC. My requirement is that I should be able to reach the Windows PC from the external network, so I need to NAT 20.20.20.40 (this is the IP through which the external network should be able to access the Windows PC) to 10.10.10.10.

How should I set up iptables on the Linux server to accomplish this?

user2007247

Posted 2013-01-30T20:22:02.757

Reputation: 21

Answers

1

@John Siu is only partially correct - while the steps he pointed out are needed to get forwarding to work the magic NAT sauce is definitely needed as 20.20.20.50 is a real IP adddress but 10.10.10.x is not.

For Outbound Connectivity (which it sounds like you may already have)

Assuming the External Interface is eth0 and the internal interface is eth1 you additionally need a rule like

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

or similarly, but with much tighter control

/sbin/iptables -t nat -A POSTROUTING -s 10.10.10.10 -o eth0 -j SNAT --to 20.20.20.40

For Inbound Connectivity from the world to your PC

/sbin/iptables -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 10.10.10.10:80

This will allow requests coming from the world on TCP port 80 to your Windows PC. (You would, of-course modify the ports and protocol as required)

davidgo

Posted 2013-01-30T20:22:02.757

Reputation: 49 152

LOL, I didn't pay attention the 20.20.20.50 is a public ip, it look so "private" to me :P. I will just remove mine and up vote yours +1. – John Siu – 2013-02-01T20:10:26.380