*************************************************************************************
---nat笔记--
**
1,同一个网段的最linux ping 192.168.2.2ping 不通,最后发现是xp的防火墙在做怪,关掉一切正常
**
2,防火墙中应用到nat的必须将forward功能开启,否则不能进行nat操作。
echo "1"> /proc/sys/net/ipv4/ip_forward
但这样依然存在一个问题,重启后问题依旧。可修改对应的配置文件或者修改/etc/rc.d/rc.local
**
3,nat做法
加载NAT模块:
modprobe iptable_nat
源地址转化:
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.2.0/24 -j SNAT --to 192.168.1.115
iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.255.0 -j SNAT --to 192.168.1.115
端口映射:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 3389 -j DNAT --to-destination 192.168.2.2:3389
iptables -t nat -I PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.2.2:80
iptables -t nat -A PREROUTING -d 192.168.1.115 -p tcp --dport 80 -j DNAT --to-destination192.168.0.2:80
查看与删除
iptables -t filter -D INPUT 3
iptables -t PREROUTING -F
iptables -t filter -L
iptables -t nat -A PREROUTING -i eth2 -p tcp --dport 8080 -j DNAT --to-destination 192.168.1.111:80
iptables -I FORWARD -d 219.133.49.206 -j DROP
iptables -I FORWARD -d 219.133.49.6 -j DROP
4,IPTABLES 配置文件
位置:/etc/sysconfig/iptables
# Completed
# Generated by webmin
*nat
:OUTPUT ACCEPT [0:0]
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A PREROUTING -d 192.168.1.115 -p tcp --dport 80 -j DNAT --to-destination 192.168.2.2:80
-A POSTROUTING -o eth0 -s 192.168.2.0/24 -j SNAT --to 192.168.1.115
COMMIT
# Completed
默认的防火墙规则:
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT