It is of 2 types - SNAT & DNAT
SNAT means Source NAT, deals with Postrouting/Masquerading. The SNAT target means that this target will rewrite the Source IP address in the IP header of the packet. It's used for hiding the private IPs from the internet. Packets leaving from an internal LAN when reaches the public IP or the firewall (visible to internet) is SNATed & then transferred to the destination. It appears to the external internet as if our external public IP is the originator of the packet. Postrouting is used in case of static IPs whereas Masquerading is used in case of dynamic IPs
The `-o' option is used as it is an outgoing interface. `-j SNAT' specifies Source NAT and the `--to-source' option specifies an IP address, a range of IP addresses, and
an optional port or range of ports (for UDP and TCP protocols only).
Now go through some SNAT examples.
##Change source addresses to 10.0.0.5.
Rule 1:
# iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 10.0.0.5
## Change source addresses to 10.0.0.5-10.0.0.10.
Rule 2:
#iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 10.0.0.5-10.0.0.10
##Change source addresses to 10.0.0.5, ports 1-1023
Rule 3:
#iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT --to-source 10.0.0.5:1-1023
Rule 4:
#iptables -A POSTROUTING -t nat -s 192.168.0.0/24 -o eth0 -j SNAT --to-source 10.0.0.1
Rule 5:
#iptables -t nat -A POSTROUTING -p tcp -o eth0 -j SNAT --to-source 192.168.0.1-192.168.0.160:1024-32000
## Masquerade everything out eth0.
Rule 6:
#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Rule 7:
#iptables -t nat -A POSTROUTING -p TCP -j MASQUERADE --to-ports 1024-31000
In next post DNAT is discussed.
No comments:
Post a Comment