辅助 IP (eth0:0) 就像主服务器 IP

Geo*_*lis 5 networking linux xen vps

我有一个 CentOS 服务器,配置了 4 个连续的 IP:
eth0 5.xx251
eth0:0 5.xx252
eth0:1 5.xx253
eth0:2 5.xx254

问题是所有流量都以 eth0:0 (5.xx252) 作为源 IP 而不是 eth0 传到互联网。
# curl ifconfig.me
5.x.x.252

我该如何解决这个问题,以便所有流量都通过 eth0(即我的主 IP)流出?

PS:我的服务器是在 Xen dom0 上运行的 VPS,后者配置为路由模式网络。

提前致谢!

服务器配置

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:x:x:x:x:AE  
          inet addr:5.x.x.251  Bcast:5.x.x.255  Mask:255.255.255.255
          inet6 addr: fe80::x:x:x:x/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:14675569 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9463227 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4122016502 (3.8 GiB)  TX bytes:25959110751 (24.1 GiB)
          Interrupt:23 

eth0:0    Link encap:Ethernet  HWaddr 00:x:x:x:x:AE   
          inet addr:5.x.x.252  Bcast:5.x.x.255  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:23 

eth0:1    Link encap:Ethernet  HWaddr 00:x:x:x:x:AE  
          inet addr:5.x.x.253  Bcast:5.x.x.255  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:23 

eth0:2    Link encap:Ethernet  HWaddr 00:x:x:x:x:AE  
          inet addr:5.x.x.254  Bcast:5.x.x.255  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:23  
Run Code Online (Sandbox Code Playgroud)
# cat /etc/hosts
127.0.0.1       localhost.localdomain localhost
5.x.x.251       [fqdn] [hostname]
Run Code Online (Sandbox Code Playgroud)
# cat ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=5.x.x.251
NETMASK=255.255.255.224
SCOPE="peer 5.x.y.82"
Run Code Online (Sandbox Code Playgroud)
# cat ifcfg-eth0:0
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=5.x.x.252
NETMASK=255.255.255.224
Run Code Online (Sandbox Code Playgroud)
# cat route-eth0 
ADDRESS0=0.0.0.0
NETMASK0=0.0.0.0
GATEWAY0=5.x.y.82
Run Code Online (Sandbox Code Playgroud)
# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
5.x.y.82        0.0.0.0         255.255.255.255 UH        0 0          0 eth0
5.x.x.224       0.0.0.0         255.255.255.224 U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         5.x.y.82        0.0.0.0         UG        0 0          0 eth0
Run Code Online (Sandbox Code Playgroud)

更新29 2012年8月
当我跑/etc/init.d/network restart我得到一个RTNETLINK answers: File exists错误,我相信这线索,有使用默认网关另一个网络的另一个途径,如看到这里

# /etc/init.d/network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  RTNETLINK answers: File exists
                                                           [  OK  ]
Run Code Online (Sandbox Code Playgroud)

可以肯定的是,当我第一次删除ip route del default via 5.x.y.82 dev eth0然后使用 .251 IP 再次添加它时,一切都按预期工作。
有没有办法向文件或文件添加route del命令?我可以看到这可以在 Debian上完成(更多信息),但是 CentOS 呢?ifcfg-eth0route-eth0pre-up ip addr del ...

Zor*_*che 6

本文档看来,至少在 CentOS 5 上,我怀疑您可以通过简单地提供正确的 iproute2 命令参数来指定您的路由。(请参阅 上的部分IP Command Arguments Format

所以不要写这样的东西:

# route-eth0 
ADDRESS0=0.0.0.0
NETMASK0=0.0.0.0
GATEWAY0=5.x.y.82
Run Code Online (Sandbox Code Playgroud)

你可以有一个这样的文件:

default via 5.x.y.82 dev eth0  src 5.x.x.251
Run Code Online (Sandbox Code Playgroud)

不过,我没有方便测试的 Redhat/Redhat 派生框。