ipTables portforwarding 的安裝方法

下面是ipTables 的安裝方法,供日後參考。

Iptables 安裝過程

1. 增加一個邏輯端口
Ifconfig lo:1 192.168.254.1 netmask 255.255.255.0

2. 修改iptables,增加DNAT的配置

iptables -t nat -F
iptables -t filter -F
iptables -A PREROUTING -t nat -p tcp --dport 80 -j DNAT --to 192.168.254.1:8800
iptables -A FORWARD -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

3. 修改redir 的配置
root@jack-laptop:~# cat /etc/rinetd.conf

# bindadress bindport connectaddress connectport
192.168.254.1 8800 61.180.1.4 80

# logging information
logfile /var/log/rinetd.log

修改後sudo /et/init.d/rinetd restart

4. 現在打開http://218.64.79.106/ 可以打開Portal 頁面
第一次NAT轉換
root@jack-laptop:~# iptables -t nat -n -L -v
Chain PREROUTING (policy ACCEPT 7 packets, 316 bytes)
pkts bytes target prot opt in out source destination
45 2880 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:192.168.254.1:8800

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
45 2700 MASQUERADE all -- * eth0 0.0.0.0/0 0.0.0.0/0

Chain OUTPUT (policy ACCEPT 45 packets, 2700 bytes)
pkts bytes target prot opt in out source destination

內部的Redir轉換
root@jack-laptop:/var/log# tail -f rinetd.log
04/Jul/2009:22:34:18 210.74.155.90 192.168.254.1 8800 61.180.1.4 80 450 104 done-local-closed
04/Jul/2009:22:34:19 210.74.155.90 192.168.254.1 8800 61.180.1.4 80 452 104 done-local-closed
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章