我在这里和其他地方读了很多答案,但找不到合适的答案。我尝试了几种解决方案,但都不起作用。我有一台只有一个接口 eth0 的服务器。我有多个 IP,但我无法让它们工作。也许你可以帮助我。
etc/network/interfaces(我在网上找到了这个解决方案,和许多其他解决方案一样):
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo eth0
iface lo inet loopback
# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 31.133.CCC.47
netmask 255.255.255.0
broadcast 31.133.CCC.255
network 31.133.CCC.0
post-up route add default gw 31.133.CCC.1 metric 1
pre-down route del default gw 31.133.CCC.1
auto eth0:0
allow-hotplug eth0
iface eth0 inet static
address 31.133.XXX.254
netmask 255.255.255.128
post-up route add default gw 31.133.XXX.129 metric 2
pre-down route del default gw 31.133.XXX.129
auto eth0:1
allow-hotplug eth0
iface eth0 inet static
address 31.133.YYY.254
netmask 255.255.255.128
post-up route add default gw 31.133.YYY.129 metric 3
pre-down route del default gw 31.133.YYY.129
auto eth0:2
allow-hotplug eth0
iface eth0 inet static
address 31.133.ZZZ.229
netmask 255.255.255.0
post-up route add default gw 31.133.ZZZ.1 metric 4
pre-down route del default gw 31.133.ZZZ.1
此配置不起作用。没有 post-up 和 pre-down,但有网关 - 也不起作用。我该怎么办?启动时,bind 和其他服务无法启动,因为它们找不到可用的接口。使用单个 IP 配置(第一个),服务器可以正常工作。
非常感谢您的建议。
答案1
我解决了这个问题。
/etc/init.d/接口:
auto lo eth0
iface lo inet loopback
auto eth0:0 eth0:1 eth0:2
allow-hotplug eth0
iface eth0 inet static
address 31.133.MMM.47
netmask 255.255.255.0
broadcast 31.133.MMM.255
network 31.133.MMM.0
post-up route add default gw 31.133.MMM.1 metric 1
pre-down route del default gw 31.133.MMM.1
iface eth0:0 inet static
address 31.133.NNN.254
netmask 255.255.255.128
broadcast 31.133.NNN.255
network 31.133.NNN.0
post-up route add default gw 31.133.NNN.129 metric 2
pre-down route del default gw 31.133.NNN.129
iface eth0:1 inet static
address 31.133.KKK.254
netmask 255.255.255.128
broadcast 31.133.KKK.255
network 31.133.KKK.0
post-up route add default gw 31.133.KKK.129 metric 3
pre-down route del default gw 31.133.KKK.129
iface eth0:2 inet static
address 31.133.LLL.229
netmask 255.255.255.0
broadcast 31.133.LLL.255
network 31.133.LLL.0
post-up route add default gw 31.133.LLL.1 metric 4
pre-down route del default gw 31.133.LLL.1
并且它有效!
感谢大家的帮助!