我尝试将137.74.9.193从服务器A路由到服务器B(Ubuntu 16.04)。
如果我尝试从服务器A ping 137.74.9.193它按预期方式工作,但是当我尝试从我的个人计算机上ping它不起作用。
服务器A:
Public IP (ens3): 213.32.69.16 Public IP: 137.74.9.193 Local Tunnel IP: 10.0.0.1
服务器B:
Public IP (eth0): 139.59.131.76 Local Tunnel IP: 10.0.0.2
服务器A上的configuration:
nano / etc / network / interfaces
auto lo iface lo inet loopback auto ens3 iface ens3 inet dhcp auto tun1 iface tun1 inet static address 10.0.0.1 netmask 255.255.255.252 pre-up iptunnel add tun1 mode gre local 213.32.69.16 remote 139.59.131.76 ttl 255 up ifconfig tun1 multicast up ifconfig tun1 arp up ifconfig tun1 broadcast pointopoint 10.0.0.2 post-up ip route add 137.74.9.193 via 10.0.0.2 dev tun1 post-down iptunnel del tun1
执行的命令:
# enable ip forward $ echo 1 > /proc/sys/net/ipv4/ip_forward $ echo 1 > /proc/sys/net/ipv4/conf/ens3/proxy_arp # Add ip to arp to complete the loop. $ arp -s 137.74.9.193 fa:16:3e:76:31:ea -i ens3 pub
结果内核IP路由表:
Destination Gateway Genmask Flags Metric Ref Use Iface default 213.32.64.1 0.0.0.0 UG 0 0 0 ens3 10.0.0.2 * 255.255.255.255 UH 0 0 0 tun1 ip193.ip-137-74 10.0.0.2 255.255.255.255 UGH 0 0 0 tun1 213.32.64.1 * 255.255.255.255 UH 0 0 0 ens3
服务器B上的configuration:
nano / etc / network / interfaces
auto eth0 iface eth0 inet static address 139.59.131.76 netmask 255.255.240.0 gateway 139.59.128.1 iface eth0:0 inet static address 137.74.9.193 netmask 255.255.255.255 broadcast 137.74.9.193 auto tun1 iface tun1 inet static address 10.0.0.2 netmask 255.255.255.252 pre-up iptunnel add tun1 mode gre local 139.59.131.76 remote 213.32.69.16 ttl 255 up ifconfig tun1 multicast up ifconfig tun1 arp up ifconfig tun1 broadcast pointopoint 10.0.0.1 post-down iptunnel del tun1
执行的命令:
# enable ip forward $ echo 1 > /proc/sys/net/ipv4/ip_forward # Route to tun1 ip route add 10.0.0.1 dev tun1
内核IP路由表:
Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 0 0 0 eth0 10.0.0.1 * 255.255.255.255 UH 0 0 0 tun1 10.19.0.0 * 255.255.0.0 U 0 0 0 eth0 139.59.128.0 * 255.255.240.0 U 0 0 0 eth0
谢谢你的帮助 :)
更新(14.11.2016):在服务器B上添加路由命令
据我所知,在你的问题中,你的问题就是这个
arp -s 137.74.9.193 fa:16:3e:76:31:ea -i ens3 pub
不做你认为的事情。 这个命令会在你的服务器上创build一个新的ARP表项,这样如果你的服务器通过ens3发送数据包到137.74.9.193 ,它将不会执行任何ARP请求,因为你已经指定了一个目标MAC地址。
但是您还需要确保路由器知道将数据包发送到您的服务器。 路由器将发送一个137.74.9.193的ARP请求。 但是由于该IP地址未分配给服务器上的任何接口,因此您的服务器将不会响应这些ARP请求。
要完成这项工作,您需要启用代理ARP,您可以使用以下命令来执行代理ARP:
echo 1 > /proc/sys/net/ipv4/conf/ens3/proxy_arp
如果您使用该命令而不是arp命令,我认为它会工作。 (我知道一个事实,这与点对点接口的对等IP协同工作,我没有testing相同的设置,通过隧道接口发送stream量的路由表条目,我不确定是否需要额外的步骤。)
如果ISP托pipe服务器B根据源IP地址过滤stream量,则可能无法使用137.74.9.193作为源地址发送来自那里的数据包。 如果从外部ping 137.74.9.193并在服务器B的eth0上捕获ICMP数据包,则应该看看是否在该接口上发送ICMP回显响应。
如果您发现服务器B正在发送ICMP回应响应,并且他们永远不会到达目的地,最可能的解释是ISP正在根据源IP地址进行过滤。
在这种情况下,你有两个select。 您可以联系ISP并解释您需要使用此源IP发起数据包,以便他们可以更新其filter。 或者你可以通过服务器A隧道返回的stream量。
通过A来隧道返回stream量的最简单方法是在B上创build一个路由表,如下所示:
Destination Gateway Genmask Flags Metric Ref Use Iface default * 0.0.0.0 UG 0 0 0 tun1 213.32.69.16 gateway 255.255.255.255 UG 0 0 0 eth0 10.0.0.1 * 255.255.255.255 UH 0 0 0 tun1 10.19.0.0 * 255.255.0.0 U 0 0 0 eth0 139.59.128.0 * 255.255.240.0 U 0 0 0 eth0
然而,这将使互联网的其他部分无法访问139.59.131.76 。 如果您希望B通过两个IP地址同时可达,则需要创build两个不同的默认路由和一个路由策略,以便根据数据包源IP在两者之间进行select。