如何使用远程Linux服务器的IP作为我当前Linux服务器的附加IP?

我有2个Linux服务器'X'和'Y'。

服务器X有大量的资源,但有2个公共IP(1个主IP绑定为eth0,另有1个IP绑定为eth0:0)。

服务器Y有9个公共IP(1个主IP绑定为eth0,另有8个IP绑定为eth0:0到eth0:7),但资源有限。

我想在服务器X上使用服务器Y的附加IP(8个IP),这样服务器X将总共有10个IP。

我search了一下,我认为有可能使用IPIP隧道/ GRE隧道我已经尝试了几天,但迄今没有运气。

以下是我在两台服务器上所做的工作:

服务器X

sysctl -w net.ipv4.conf.default.rp_filter=0; ip tunnel add tunx mode gre remote |Y's Main IP| local |X's Main IP| ttl 255 dev eth0; ip link set tunx up; ip addr add 10.10.1.1/32 dev tunx peer 10.10.1.2; ip addr add |One of Y's Additional IPs|/29 dev eth0; 

服务器Y

 sysctl -w net.ipv4.conf.all.forwarding=1; sysctl -w net.ipv4.ip_forward=1; sysctl -w net.ipv4.conf.all.proxy_arp=1; sysctl -w net.ipv4.conf.eth0.rp_filter=0; sysctl -w net.ipv4.conf.tun0.rp_filter=0; ip tunnel add tuny mode gre remote |X's Main IP| local |Y's Main IP| ttl 255 dev eth0; ip link set tuny up; ip addr add 10.10.1.2/32 dev tuny; ip route add |Y's first additional IP|/29 via 10.10.1.2; 

在两个服务器上面的命令后,当我从X尝试下面的命令:

 traceroute -s|One of Y's additional IPs| google.com I get this: traceroute to google.com (173.194.70.113), 30 hops max, 60 byte packets 1 * * * 2 * * * 3 * * * 4 * * * 5 * * * 6 * * * 7 * * * 8 * * * 9 * * * 10 * * * 11 * * * 12 * * * 13 * * * 14 * * * 15 * * * 

您的设置中至less有两个错误:

  1. ServerX需要路由规则将stream量从Y1转发到隧道。
  2. ServerY上的tuny需要一个对等地址。

同样使用/ 32路由和掩码来迁移地址,以防止路由循环。

让:

  1. ServerX主IP = X
  2. ServerY主IP = Y
  3. ServerY附加IP = Y1

那么下面我相信更接近工作configuration:

ServerX:

 ... ip tunnel add tun0 mode gre remote Y local X ttl 255 ip link set tun0 up ip addr add Y1/32 dev eth0 ip addr add 10.10.1.1 dev tun0 peer 10.10.1.2 ip route add default via 10.10.1.2 dev tun0 table 100 ip rule add from Y1 table 100 

的servery

 ip tunnel add tun0 mode gre remote X local Y ttl 255 ip link set tun0 up ip addr add 10.10.1.2 dev tun0 peer 10.10.1.1 ip route add Y1/32 via 10.10.1.1 dev tun0 

您也可以考虑在ServerY上使用单个GRE隧道和静态NAT进行替代设置,以使ServerY上的IP地址可用于ServerX上的服务。

UPD:

我刚刚检查过 它似乎在工作。

相关的iptablesconfiguration允许stream量:

的servery:

 -A FORWARD -d Y1 -o tun0 -j ACCEPT -A FORWARD -s Y1 -i tun0 -j ACCEPT -A INPUT -p gre -j ACCEPT 

ServerX:

 -A INPUT -p gre -j ACCEPT 

问题可以按以下顺序进行debugging:

  1. 确保X和Y是可达的。
  2. 确保隧道启动并正常工作: ping <tunnel-peer-address>
  3. 如果不是,请检查供应商是否允许GREstream量。
  4. 跟踪如何处理icmp数据包: tcpdump -i tun0 icmptcpdump -i eth0 icmp

好书是“Linux高级路由和stream量控制HOWTO”。

为什么不从服务器Y中删除IP地址的configuration,并将它们添加到服务器X的configuration中(因此,只有一台服务器具有特定的IP地址)?