我在界面上创build了虚拟IP,在centos中使用下面的命令。
ifconfig eth0:0 10.100.0.5/24 broadcast 10.100.0.255
该接口的真实IP为10.100.0.3。 当我ping另一个主机时,我的源IP是10.100.0.3这不是我想要的东西。 我想虚拟IP显示为源。
我尝试添加默认网关接口eth0:0,但是在路由中-n仍然显示我eth0作为默认网关接口。
任何帮助表示赞赏。
我可以使用iproute-package中的'ip'工具来解决这个问题。
使用ip route我可以看到哪个地址被用作源:
root@testbox:~# ip route 10.100.0.0/24 dev eth0 proto kernel scope link src 10.100.0.3/24 metric 1 default via 10.100.0.1 dev eth0 proto static
通过复制和编辑上面的行,我可以改变它:
ip route change 10.100.0.0/24 dev eth0 proto kernel scope link src 10.100.0.5/24 metric 1
route -n仍将显示eth0,因为它看不到虚拟接口。