[....] Restarting networking (via systemctl): networking....process exited with error code....

起因:

虚拟机两台ubuntu_server_16.04,准备测试搭建网关服务器,实现DNAT/SNAT功能。在作为内网服务器上的网卡配置里,添加了一条网络不可达的路由(因为测试的功能是准备在生产环境上应用,所以尽量避免重启机器)。配置如下:

auto ens33

iface ens33 inet static

address 192.168.241.6

netmask 255.255.255.0

up route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.25.7.247 dev ens33

然后重启网络服务

root@test:~# /etc/init.d/networking restart
[....] Restarting networking (via systemctl): networking.serviceJob for networking.service failed because the control process exited with error code. See "systemctl status networking.service" and "journalctl -xe" for details.
 failed!

崩了!!!

按照提示查看:

root@test:~# systemctl status networking.service
● networking.service - Raise network interfaces
   Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
  Drop-In: /run/systemd/generator/networking.service.d
           └─50-insserv.conf-$network.conf
   Active: failed (Result: exit-code) since Tue 2018-09-11 16:51:08 CST; 3min 7s ago
     Docs: man:interfaces(5)
  Process: 4814 ExecStop=/sbin/ifdown -a --read-environment --exclude=lo (code=exited, status=0/SUCCESS)
  Process: 5705 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
  Process: 5699 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle (code=exited, status=0/SUCCESS)
 Main PID: 5705 (code=exited, status=1/FAILURE)

Sep 11 16:51:08 ubuntu1 systemd[1]: Stopped Raise network interfaces.
Sep 11 16:51:08 ubuntu1 systemd[1]: Starting Raise network interfaces...
Sep 11 16:51:08 ubuntu1 ifup[5705]: RTNETLINK answers: File exists
Sep 11 16:51:08 ubuntu1 ifup[5705]: Failed to bring up ens33.
Sep 11 16:51:08 ubuntu1 systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Sep 11 16:51:08 ubuntu1 systemd[1]: Failed to start Raise network interfaces.
Sep 11 16:51:08 ubuntu1 systemd[1]: networking.service: Unit entered failed state.
Sep 11 16:51:08 ubuntu1 systemd[1]: networking.service: Failed with result 'exit-code'.

出问题找百度:

root@test:~# ifdown ens33 && ifup ens33
ifdown: interface ens33 not configured
RTNETLINK answers: File exists
Failed to bring up ens33.


再来:

root@test:~# ifdown --exclude=lo -a && ifup --exclude=lo -a
RTNETLINK answers: File exists
Failed to bring up ens33.

还有个NetworkManager的解决方法,后来才知道server版没有这个玩意。

再后来在一个陈年老贴里,发现了一个解决centos问题的语句。

root@test:~# ip addr flush dev ens33

重点来了,这个命令会让你断开远程连接,所以,生产环境需要的同志往下看。

因为我是准备用在生产环境的,所以不会大老远跑过去,何况本身我就是在虚拟机测试的。

下面,惯例。

root@test:~# ip addr flush dev ens33 && /etc/init.d/networking start
Socket error Event: 32 Error: 10053.
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(192.168.241.6) at 17:15:37.

Type `help' to learn how to use Xshell prompt.
[c:\~]$ 
竟然断了。

反复搞了好几次。

最终命令:

root@test:~# ip addr flush dev ens33 && /etc/init.d/networking restart

先把网卡配置文件改正确了,再执行命令,不然你还是要跑过去的。嘿嘿。

ens33是网卡名,根据需要自行更改。restart!!!很关键!

声明:本人是在测试环境下使用,各位需要的最好自己测试一下再用,网卡配置文件添加一个不可达路由就会出现这个报错。

 

 

 

 

你可能感兴趣的:(运维)