IPTables 仅从我的服务器上的一个 IP 转发

IPTables 仅从我的服务器上的一个 IP 转发

我能够让我的服务器将某个端口上的连接转发到另一个 IP,但当我添加 -d 来指定要转发的 IP 时,它不起作用。这就是我正在尝试的,

iptables -t nat -A PREROUTING -d 173.208.230.107 -p tcp --dport 80
iptables -t nat -nvL-j DNAT --to-destination 38.105.20.226:80

没有 -d 也可以正常工作。这是我的 ifconfig 转储:

em1       Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.106  Bcast:173.208.230.111  Mask:255.255.255.248
          inet6 addr: fe80::2a0:d1ff:feed:d054/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:100058 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18941701 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12779711 (12.1 MiB)  TX bytes:825498499 (787.2 MiB)
          Memory:fbde0000-fbe00000

em1:9     Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.107  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

em1:10    Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.108  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

em1:11    Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.109  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

em1:12    Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.110  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

答案1

我相信您只需要nat表格中的一条规则以及一条接受规则。将您-d-dst添加到第一条规则。

iptables -t nat -p 6 --dport 80 -j DNAT --to-destination 38.105.20.226
iptables -A INPUT -p 6 --dport 25 -d 38.105.20.226 -j ACCEPT

相关内容