標籤:撥號連線 轉換 post 6.2 表示 ping 防火 內網 x86_64
MASQUERADE同樣是做源地址轉換,只不過防火牆會根據該策略自動尋找可用的公網IP地址,適應變化的情況
?若介面使用ppp+,表示匹配ppp0、ppp1……中任意可用的撥號連線
?若需要示範操作,可以針對前一個SNAT策略的例子進行改寫(因沒有ADSL串連,介面仍然使用eth0):
先執行“iptables -t nat -F”清空nat表
再添加規則“iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE”
?講解應用DNAT策略的基本步驟,其中涉及到的相關操作
?同樣可適當強調:外網測試機並不需要將預設閘道地址設為該Linux網關主機的IP地址
?確認路由功能狀態時,可以執行sysctl命令查看:
[[email protected] ~]# sysctl -a | grep "ip_forward"
net.ipv4.ip_forward = 1
執行 “elinks http://218.29.30.29” 或者“lynx http://218.29.30.29”均可以進行測試
[[email protected] ~]# tail -f /var/log/httpd/access_log
218.29.30.29 - - [04/Jun/2009:14:35:53 +0800] "GET / HTTP/1.1" 200 15 "-" "ELinks/0.11.1 (textmode; Linux; 80x25-2)"
NAT轉換
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth1 -j SNAT --to-source 218.29.30.31
先執行“iptables -t nat -F”清空nat表
再添加規則“iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE”
[[email protected] ~]# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE
[[email protected] ~]# sysctl -a | grep "ip_forward" net.ipv4.ip_forward = 1
iptables -t nat -A PREROUTING -i eth0 -d 218.29.30.31 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.6
[[email protected] ~]# iptables -t nat -A PREROUTING -i eth0 -d 218.29.30.31 -p tcp --dport 2222 -j DNAT --to-destination
192.168.1.5:22
--------------------------理解ESTABLISHED
vm1
# iptables -P INPUT DROP
ping 192.168.56.201
ssh 192.168.56.201
全部失敗
# iptables -A INPUT -p all -m state --state ESTABLISHED -j ACCEPT
ping 192.168.56.201
ssh 192.168.56.201
全部成功
vm2關閉防火牆
成功穿越反向防火牆。
tracerout 192.168.56.201 失敗 ,原因看下面
--------------------------理解RELATE
vm1
# iptables -P INPUT DROP
# iptables -F
# iptables -A INPUT -p all -m state --state RELATED -j ACCEPT
tracerout 192.168.56.201 成功。由第一個包產生的其他回包都屬於RELATE狀態。
--------------------------理解NEW
vm1
OUTPUT預設策略為DROP。其他策略為ACCEPT
# iptables -P INPUT ACCEPT
# iptables -P OUTPUT DROP
# iptables -F
ping 192.168.56.201
ssh 192.168.56.201
全部失敗
# iptables -A OUTPUT -p all -m state --state ESTABLISHED,NEW -j ACCEPT
--------------------------理解INVALID
他需要特殊的第一條駭客工具產生,所以這裡面緊急下面的用法。
通常應用在INPUT表的第一條。
# iptables -A INPUT -p all -m state --state INVALID -j DROP
--------------------------SNAT-內網訪問外網
-------外網 --------------------網關防火牆-------------------內網PC1 192.168.56.202
10.0.100 eth0 eth1
10.0.1.200 192.168.56.200
內網:yum install elinks lynx -y
網關防火牆
# iptables -t nat -A POSTROUTING -s 192.168.56.202 -o eth0 -j SNAT --to-source 10.0.1.200
外網:httpd
# tailf /var/log/httpd/access_log
--------------------------DNAT-對外發布連接埠
外網:yum install elinks lynx -y
網關防火牆:
# iptables -t nat -A PREROUTING -i eth0 -d 10.0.1.200 -p tcp --dport 2345 -j DNAT --to-destination 192.168.56.202:80
內網:httpd
# tailf /var/log/httpd/access_log
核心模組存放位置
# ls /lib/modules/2.6.32-431.el6.x86_64/kernel/net/ipv4/netfilter/ //ipv4支援
# ls /lib/modules/2.6.32-431.el6.x86_64/kernel/net/ipv6/netfilter/ //ipv6支援
# ls /lib/modules/2.6.32-431.el6.x86_64/kernel/net/netfilter/ //同時支援
lsmod 查看當前的模組
iptables(2)