Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

@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)

share|improve this answer
    
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 Feb 1 '13 at 20:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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