【问题标题】:Iptables NAT one-to-oneiptables NAT 一对一
【发布时间】:2018-06-18 15:26:23
【问题描述】:

我使用 linux 服务 Fedora 4.14.33-51.37.amzn1.x86_64。我想使用 NAT 1 对 1。 例如是否相同problem 我的方案是: 我的服务器有两个网络接口。

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc mq state UP group default qlen 1000
    link/ether 0a:8a:59:b9:2d:b8 brd ff:ff:ff:ff:ff:ff
    inet 172.10.1.72/25 brd 172.10.1.127 scope global eth0
       valid_lft forever preferred_lft forever
    inet 172.10.1.32/25 brd 172.10.1.127 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet 172.10.1.39/25 brd 172.10.1.127 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet 172.10.1.101/25 brd 172.10.1.127 scope global secondary eth0

eth1:
 inet 172.10.1.246/28 brd 172.10.1.255 scope global eth1

net.ipv4.ip_forward = 1

NAT如何工作

(eth0)172.10.1.101 - (server1)192.168.1.10
(eth0)172.10.1.32 - (server2)192.168.1.11

等等... NAT服务器上的路由表

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.10.1.1      0.0.0.0         UG    0      0        0 eth0
0.0.0.0         172.10.1.241    0.0.0.0         UG    10001  0        0 eth1
10.0.0.0        172.10.1.1      255.0.0.0       UG    0      0        0 eth0
169.254.169.254 0.0.0.0         255.255.255.255 UH    0      0        0 eth0
172.10.1.0      0.0.0.0         255.255.255.128 U     0      0        0 eth0
172.10.1.240    0.0.0.0         255.255.255.240 U     0      0        0 eth1
192.168.1.0     172.10.1.241    255.255.255.240 UG    0      0        0 eth1

我目前的 iptables 设置:

iptables -nvL

    Chain INPUT (policy ACCEPT 1726 packets, 115K bytes)
     pkts bytes target     prot opt in     out     source               destination
     1827  121K LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            LOG flags 0 level 4

    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
     pkts bytes target     prot opt in     out     source               destination
      664 55128 ACCEPT     all  --  eth0   eth1    0.0.0.0/0            0.0.0.0/0
        0     0 ACCEPT     all  --  eth1   eth0    0.0.0.0/0            0.0.0.0/0
        0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            LOG flags 0 level 4

    Chain OUTPUT (policy ACCEPT 2123 packets, 668K bytes)
     pkts bytes target     prot opt in     out     source               destination
     2123  668K LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            LOG flags 0 level 4

iptables -nvL -t nat
Chain PREROUTING (policy ACCEPT 36 packets, 2476 bytes)
 pkts bytes target     prot opt in     out     source               destination
    8   528 DNAT       all  --  eth0   *       0.0.0.0/0            172.10.1.101         to:192.168.1.10

Chain INPUT (policy ACCEPT 36 packets, 2476 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 195 packets, 14344 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 202 packets, 14788 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 SNAT       all  --  *      eth0    192.168.1.10         0.0.0.0/0            to:172.10.1.101

当我尝试将我的 NAT 服务器检查为 telnet 172.10.1.101 4016 时出现错误

telnet: connect to address 172.10.1.101: Connection timed out

我的服务器 192.168.1.10 监听了 4016 端口。

在我的 NAT 服务器上,我没有日志。

But I try connect to another ip on my eth0 interface and saw in log
Jun 18 15:04:39 ip-172-10-1-72 kernel: [ 1245.059113] IN= OUT=eth0 SRC=172.10.1.39 DST=10.68.72.90 LEN=40 TOS=0x10 PREC=0x00 TTL=255 ID=57691 DF PROTO=TCP SPT=4016 DPT=47952 WINDOW=0 RES=0x00 ACK RST URGP=0 

10.68.72.90 是我在 NAT 之前的服务器。在 iptables 中添加角色后,我无法 ping 我的 ip 172.10.1.101。

【问题讨论】:

    标签: linux iptables nat


    【解决方案1】:

    我有正确的规则。

    iptables -t nat -A POSTROUTING -s 192.168.1.11 -o eth0 -j SNAT --to-source 172.10.1.32
    iptables -t nat -A PREROUTING -d 172.10.1.32 -i eth0 -j DNAT --to-destination 192.168.1.11
    

    问题出在 AWS 中。我应该在界面菜单中打开 NAT 服务器“检查源”。并且所有静态路由都必须在子网的路由表中,我的服务器在哪里,而不是在服务器 192.168.1.10 和 192.168.1.11 上。

    【讨论】:

      猜你喜欢
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-18
      • 2014-05-01
      相关资源
      最近更新 更多