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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With