我试图路由所有传出的HTTP请求离开我的服务器去通过另一台服务器上的代理(tinyproxy)。 我希望传输到代理使用我们的eth1上的LAN。 无论我尝试什么,eth0都会发出请求。
我创build了这个规则:
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT -o eth1 --to-destination 123.123.123.123:8888
但是,这是行不通的。 请求正在eth0上。 我知道我在这里错过了一些大事,但我没有想法。 任何帮助,将不胜感激。
组态:
eth0 Link encap:Ethernet HWaddr 04:01:33:0E: inet addr:111.111.111.111 Bcast:111.111.111.255 Mask:255.255.255.0 inet6 addr: fe80::601:33ff:121:4f01/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1068434 errors:0 dropped:0 overruns:0 frame:0 TX packets:499051 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1087084291 (1.0 GiB) TX bytes:104089629 (99.2 MiB) eth1 Link encap:Ethernet HWaddr 04:01:33:0E: inet addr:10.11.10.10 Bcast:10.11.255.255 Mask:255.255.0.0 inet6 addr: fe80::601:33ff:121:4f02/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8243 errors:0 dropped:0 overruns:0 frame:0 TX packets:4746 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:10948267 (10.4 MiB) TX bytes:633381 (618.5 KiB) route -n; cat /etc/network/interfaces Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 162.243.xx.xx 0.0.0.0 255.255.255.0 U 0 0 0 eth0 10.128.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1 0.0.0.0 162.243..xx.xx 0.0.0.0 UG 0 0 0 eth0 cat: /etc/network/interfaces: No such file or directory iptables -t nat -vnL Chain PREROUTING (policy ACCEPT 5983 packets, 352K bytes) pkts bytes target prot opt in out source destination Chain POSTROUTING (policy ACCEPT 15734 packets, 1020K bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 4693 packets, 331K bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- * * 0.0.0.0/0 162.243..xx.xx 3550 239K ACCEPT all -- * * 0.0.0.0/0 127.0.0.1 0 0 ACCEPT all -- * * 0.0.0.0/0 10.128.95.89 7491 449K DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:10.128.3.132:8888
以下是您的问题:根据您的configuration,两个网卡都使用度量标准:1如果要将ETH1用作主NIC, 请将度量标准更改为0 。
您的configuration:
eth0 Link encap:Ethernet HWaddr 04:01:33:0E:UP BROADCAST运行多播MTU:1500 度量标准:1
eth1 Link encap:Ethernet HWaddr 04:01:33:0E:UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
你的路由表在这里玩。
您的代理位于Internet路由的IP地址上。 您的eth0接口也configuration了可通过因特网路由的IP地址,并可能使用指向WAN网关(Comcast,AT&T等)的默认路由。 您的eth1接口configuration了非Internet路由IP地址。 发生了什么事是你的路由表通过eth0接口看到你的目的地址(代理服务器)的路由,因此数据包在该路由上传播。
我敢打赌,你的iptables规则没有看到任何命中,这就解释了为什么。 您在当前configuration中尝试完成的操作需要 eth0接口。
希望这可以帮助