Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iptables Postrouting with SNAT for a paritcular destination IP [closed]

Tags:

iptables

I want to define a rule in iptables for postrouting in ubuntu as below:

$IPTABLES -t nat -A POSTROUTING  -o $EXTIF -p tcp -d xxx.xx.xx.8 -j SNAT --to-source xxx.xx.xx.238

It means for destination with IP xxx.xx.xx.8 (a oublic IP) , I want its source IP to be xxx.xx.xx.238.

The above rule is not working . Any suggestions. Thank you.

like image 560
Shyamkkhadka Avatar asked Aug 05 '13 06:08

Shyamkkhadka


1 Answers

I got the solution myself as below: I added a new IP in sub interface(eth0:0), with my required NATting IP. For example xxx.xx.xx.238 with eth0:0. Now I added a new rule in IPTABLE as

$IPTABLES  -t nat -A POSTROUTING  -o eth0.0 -p tcp -d xxx.xx.xx.8 -j SNAT --to-source xxx.xx.xx.238

.

When accessing the application in IP xxx.xx.xx.8, It shows the NATting IP to be xxx.xx.xx.238.

like image 122
Shyamkkhadka Avatar answered Oct 31 '22 03:10

Shyamkkhadka