我正在尝试使用iptables将eth0上的传入数据包redirect到在回送接口上监听的服务。 基于这个链接,我试图制定以下规则:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT -o lo --to-port 80
但是我得到了如下所示的错误:
Can't use -o with PREROUTING
手册页解释了为什么这不起作用:
(REDIRECT) redirects the packet to the machine itself by changing the destination IP to the primary address of the incoming interface
我如何接收传入的数据包并将它们馈送到回送接口?
你为什么要加上-o lo
? 这不是必需的,不起作用,甚至在你所链接的教程中都没有。 只要删除它。
使用演示iptables及其伪装function的模型,尝试redirect到127.0.0.1这是你的环回,对吧?
你的iptables的解决scheme应该可以工作,但不幸的是,Linux内核不允许它,因为内核代码认为目的地址127/8的每个传入数据包都是“火星人”,它不会接受它。
你可以看到这个:
为了让它stream量到127/8子网使用route_localnet
要么
并检查设置。
在设置/ proc / sys / net / ipv4 / conf / eth0 / route_localnet之后,127.0.0.1的dnat将会工作。