早上我一直在互联网上寻找答案,但是我无法使其正常工作。如果您能帮助我,我将不胜感激。
我的设置:服务器:eth1:192.168.6.2(已连接到Internet-> WAN)eth0:192.168.0.1(LAN)
本地计算机:在IP地址为192.168.0.3的端口8848上运行服务
IPtables封闭了一切,使建筑物中的人们无法访问本地LAN(192.168.0.x),并且LAN通过eth1使用Internet:
### Set Variables
IPTABLES='/sbin/iptables -v'
WAN='eth1'
LAN='eth0'
#EXTERNAL_INTERFACE=WAN
#EXTERNAL_IP=WAN_IP
WAN_IP=$( ifconfig $WAN | grep 'inet[^6]' | sed 's/[a-zA-Z:]//g' | awk '{print $1}' )
LAN_IP=$( ifconfig $LAN | grep 'inet[^6]' | sed 's/[a-zA-Z:]//g' | awk '{print $1}' )
echo '########################################################## NAT config WAN <=> LAN #'
$IPTABLES -t nat --append POSTROUTING --out-interface $WAN --jump MASQUERADE
$IPTABLES --append FORWARD --in-interface $WAN --out-interface $LAN -m state --state RELATED,ESTABLISHED --jump ACCEPT
$IPTABLES --append FORWARD --in-interface $LAN --out-interface $WAN --jump ACCEPT
echo '############################### Allow unlimited traffic on the loopback interface #'
$IPTABLES --append INPUT --in-interface lo --jump ACCEPT
$IPTABLES --append OUTPUT --out-interface lo --jump ACCEPT
$IPTABLES --append INPUT --in-interface $LAN --jump ACCEPT
$IPTABLES --append OUTPUT --out-interface $LAN --jump ACCEPT
echo '################################################ Allow unlimited outbound traffic #'
# Previously initiated and accepted exchanges bypass rule checking
$IPTABLES --append INPUT -m state --state ESTABLISHED,RELATED --jump ACCEPT
$IPTABLES --append OUTPUT -m state --state NEW,ESTABLISHED,RELATED --jump ACCEPT
服务器(LAN 192.168.0.1和WAN 192.168.6.2)运行Apache,打开一个用于WAN的服务器就可以正常工作(经过测试),我可以通过192.168.6范围内的IP地址访问连接到192.168.6.2的网站。 x:
$IPTABLES --append INPUT --proto tcp --source 0/0 --dport 80 -m state --state NEW --jump ACCEPT
所以我首先打开了端口8848:
$IPTABLES --append INPUT --proto tcp --source 0/0 --dport 8848 -m state --state NEW --jump ACCEPT
然后我被卡住了。 )
你能帮我吗?
[edit]要完成整个bash脚本,请在设置LAN和WAN变量后使用以下方法进行清理:
echo '####################################################################### clear all #'
$IPTABLES --flush
$IPTABLES --delete-chain
for TABLE in filter nat mangle; do
$IPTABLES --table $TABLE --flush # delete the table's rules
$IPTABLES --table $TABLE --delete-chain # delete the table's chains
$IPTABLES --table $TABLE --zero # zero the table's counters
done
然后我的bash脚本以:结尾]
echo '############################################################ Set default policies #' $IPTABLES --policy INPUT DROP $IPTABLES --policy OUTPUT DROP $IPTABLES --policy FORWARD ACCEPT echo '########################### Have these rules take effect when iptables is started #' /sbin/service iptables save /sbin/service iptables restart`
[答案/解决方案]
多亏了this page,我终于使它运行稳定:
echo '################################################################# Port forwarding #'
FROM_PORT='8848'
TO_PORT='8848'
TO_IP='192.168.0.3'
$IPTABLES -t nat -A PREROUTING -p tcp -d $WAN_IP --dport $FROM_PORT -j DNAT --to-destination $TO_IP:$TO_PORT
$IPTABLES -t nat -A POSTROUTING -p tcp -d $TO_IP --dport $TO_PORT -j SNAT --to-source $WAN_IP
早上我一直在互联网上寻找答案,但是我无法使其正常工作。如果您能帮助我,我将不胜感激。我的设置:服务器:eth1:192.168.6.2(已连接到Internet-> WAN)...
尝试一下:
谢谢!它对我有用。