-1

I have a question regarding Linux NAT-ing on my own IP address.

Suppose I have an network interface, say eth0. It is given an IP address of 127.0.0.2. Now I apply a NAT rule in Linux saying that:

Any traffic with a source IP of 127.0.0.2 should be changed to a source IP of 192.168.0.2.

What source IP will I see in the packets sent out of eth0? In other words, will the NAT rule be applied to the packets originating from my own machine?

Thanks! Jin

Jin Teng
  • 3
  • 3
  • Welcome to StackOverflow which is a community about programming. Your question has nothing to do with programming and is much more relevant on Stack's sister site http://serverfault.com – Martin Oct 14 '13 at 19:56
  • Thanks for the reminder. I will move it to serverfault.com. If you think it is appropriate, you can delete this post for me. – Jin Teng Oct 15 '13 at 17:25

1 Answers1

0

you can use postrouting for the same

iptables -t nat -A POSTROUTING -s 127.0.0.2 -o eth0 -j SNAT --to 192.168.0.2
suhas
  • 733
  • 5
  • 13
  • Thanks for the reply. Do you mean with post-routing, I will see packets with source IP 192.168.0.2 sent out of eth0? – Jin Teng Oct 14 '13 at 18:26
  • yes the post routing the packets sent to 127.0.0.2 can be seen on 192.168.0.2 – suhas Oct 14 '13 at 18:32
  • Postrouting and Prerouting both happen with incoming packets (from an ingress port). But in this case, there is no ingress port, nor incoming packet. Will postrouting still work? Thanks. – Jin Teng Oct 14 '13 at 19:27