我正在运行 debian 并且具有以下网络配置:
eth0 Link encap:Ethernet
inet addr:192.168.16.6 Bcast:192.168.16.255 Mask:255.255.255.0
inet6 addr: fe80::204:75ff:fe9b:50e5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:167010058 errors:0 dropped:0 overruns:1 frame:0
TX packets:286396455 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3019943786 (2.8 GiB) TX bytes:161811580 (154.3 MiB)
Interrupt:16 Base address:0x2c00
eth1 Link encap:Ethernet
inet6 addr: fe80::202:55ff:fe07:6d6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:276813626 errors:2444616 dropped:0 overruns:0 frame:0
TX packets:87946731 errors:0 dropped:0 overruns:0 carrier:0
collisions:2444616 txqueuelen:1000
RX bytes:1634441886 (1.5 GiB) TX bytes:2402441796 (2.2 GiB)
Interrupt:29
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:3896208 errors:0 dropped:0 overruns:0 frame:0
TX packets:3896208 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:828004427 (789.6 MiB) TX bytes:828004427 (789.6 MiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:XXX.XXX.XXX P-t-P:XXX.XXX.XXX.XXX Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
RX packets:3324045 errors:0 dropped:0 overruns:0 frame:0
TX packets:740415 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:301507344 (287.5 MiB) TX bytes:100747638 (96.0 MiB)
eth0 用于局域网,eht1 连接到 DSL 调制解调器。我希望将所有来自互联网(端口 81)的传入流量重定向到我的局域网中的一台机器(192.168.16.8:3000)。我正在使用 ufw,但我禁用了它以使用干净的 iptables。我打算在配置完成后再次打开它。
我尝试过这个:
iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 81 -j DNAT --to 192.168.16.8:3000
iptables -I FORWARD -p tcp --dport 81 -i eth1 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW --dport 81 -i eth1 -j ACCEPT
但没用!以下是包含 iptables -L 的完整日志:http://pastebin.com/5vXZ7pQu 以下是 iptables-save 日志:http://pastebin.com/KPSCxL0x
我使用:net.ipv4.ip_forward = 1
谢谢!
答案1
界面不正确,情况如下:
iptables -t nat -i ppp0 -A PREROUTING -p tcp --dport 81 -j DNAT --to-destination 192.168.16.8:3000
iptables -t nat -A POSTROUTING -p tcp --dport 81 -j MASQUERADE