Linux版本:Ubuntu 12.04
配置網口后重啟網絡,提示/etc/init.d/networking restart is deprecated。
$ sudo /etc/init.d/networking restart * Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces * Reconfiguring network interfaces... [ OK ]
在網上搜了半天,找到幾種方法試了下。
一種說法是/etc/init.d/networking restart已被廢棄,只保留/etc/init.d/networking start|stop,但測試結果表明stop|start可用性更差。
執行sudo /etc/init.d/networking stop后,除了loopback其它網卡都被停掉(有時會直接死機……),而且無法通過sudo /etc/init.d/networking start再啟動,只能重啟系統。
一種方法是先更新iptables再重啟網卡
$ sudo iptables-save $ sudo /etc/init.d/networking restart
但結果依然報錯,跟直接執行/etc/init.d/networking restart一樣。
還有一種方法是用命令service networking restart替代/etc/init.d/networking restart。
zlf@zlf:/etc/init.d$ service networking restart stop: Unknown instance: start: Rejected send message, 1 matched rules; type="method_call", sender=":1.94" (uid=1000 pid=3847 comm="start networking ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
zlf@zlf:/etc/init.d$ sudo service networking restart stop: Unknown instance: networking stop/waiting
區別是報錯信息不同了,但目測也不起作用。
只好擼起袖子自己干了,打開/etc/init.d/networking看了看,這是個shell腳本,對restart的處理實際用的命令是ifdown -a和ifup -a。
case "$1" in
start)
/lib/init/upstart-job networking start
;;
stop)
check_network_file_systems
-------略過-------
force-reload|restart) process_options log_warning_msg "Running $0 $1 is deprecated because it may not enable again some interfaces" log_action_begin_msg "Reconfiguring network interfaces"
ifdown -a --exclude=lo || true if ifup -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi ;;
man一下ifdown和ifup,ifdown可以停止正在運行的網口,而ifup可以啟動在/etc/network/interfaces文件中配置並標有auto的網口,auto表示開機自動啟動。
ifdown -a Bring down all interfaces that are currently up. ifup -a Bring up all the interfaces defined with auto in /etc/network/interfaces
於是試了試sudo ifdown -a,sudo ifup -a,網卡重啟成功。
所以,對需要重啟的網口,先確認/etc/network/interfaces配置中有auto標識,然后用ifdown -a | ifup -a實現重啟。
比如eth0的配置
auto eth0
iface eth0 inet dhcp
----下略----
嚴重吐槽:一個小小的網卡重啟功能,被Ubuntu改得雞飛狗跳!
參考資料
http://www.jscto.net/html/109.html
http://comments.gmane.org/gmane.linux.debian.user/390797