买了老外服务器,给了五个IP,因为一直都是用一个,而且跑了大量的站,不能轻易断网,所以一直没用加,按照网上的文档操作了一下,执行 /etc/init.d/networking restart 或者 service networking restart
报错信息:Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces … (warning).
没办法,直接TK联系老外了,老外把配置文件恢复了一下,可以连接上去了,可是甘心,又配置了一下,重新,我操,又是报错,没办法,厚着脸皮和老外说 can you help me do again? 外国人还是很厚道的,很快又给我解决了。
我用的是DEBIAN 7 ,去网上苦找文档,终于发现问题所在了。
etc/network/interfaces文件中一般用auto或者allow-hotplug来定义接口的启动行为。
看来要修改allow-hotplug 为auto ,如果不修改的话重新系统估计根据文档说明是可行的,但是不好意思麻烦老外了,我是修改了以后重启的系统。
把我的配置文件粘一下,有需要的自己对照吧。
# 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 iface lo inet loopback # The primary network interface auto eth0 eth0:0 eth0:1 eth0:2 eth0:3 iface eth0 inet static address 170.245.12.132 netmask 255.255.255.248 gateway 170.245.12.131 dns-nameservers 8.8.8.8 4.4.4.4 iface eth0:0 inet static address 170.245.12.133 netmask 255.255.255.248 iface eth0:1 inet static address 170.245.12.134 netmask 255.255.255.248 iface eth0:2 inet static address 170.245.12.135 netmask 255.255.255.248 iface eth0:3 inet static address 170.245.12.136 netmask 255.255.255.248
auto
语法:
auto <interface_name>
含义:
在系统启动的时候启动网络接口,无论网络接口有无连接(插入网线),如果该接口配置了DHCP,则无论有无网线,系统都会去执行DHCP,如果没有插入网线,则等该接口超时后才会继续。
allow-hotplug
语法:
allow-hotplug <interface_name>
含义:
只有当内核从该接口检测到热插拔事件后才启动该接口。如果系统开机时该接口没有插入网线,则系统不会启动该接口,系统启动后,如果插入网线,系统会自动启动该接口。也就是将网络接口设置为热插拔模式。
手动重新启动网络
一般修改了网络配置文件后,会用以下命令重新启动网络
# /etc/init.d/networking restart
但从squeeze开始,此命令会有如下提示:
Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces … (warning).
Reconfiguring network interfaces…done.
如果设置接口为auto,虽然会有如此提示,但接口仍然会正确的启动。
如果接口设置为allow-hotplug则没有这么走运了,网络接口不会正确启动。这种情况下必须使用如下命令启动网络接口:
#ifup <interface_name>
而命令
#ifconfig <interface_name> up
也无法正确启动接口
所以allow-hotplug设置的接口最好如下方式重新启动网络接口,当然auto方式的接口也没问题:
#ifdown <interface_name> && ifup <interface_name>
特别是在ssh登录远程主机的情况下,一定要像上面这样在一条命令里执行ifdown和ifup,否则,如果先执行ifdown,则再也没有机会执行ifup了。