CentOS 7 配置静态IP后不生效 & Job for network.service failed

参考:http://tieba.baidu.com/p/3233996339#57290767555l

在CentOS中配置静态IP后不生效。

解决办法:/etc/sysconfig/network-scripts/ifcfg-eth0文件中的DEVICE=eth0注释掉

解决过程:

一开始,配置文件/etc/sysconfig/network-scripts/ifcfg-eth0内容如下:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
NM_CONTROLLED="no"
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.30.140
NETMASK=255.255.255.0
GETWAY=192.168.1.1
DNS1=114.114.114.114

试了网上其他人说的方法,比如

方法1. 禁用NetworkManager

  systemctl stop NetworkManager

  systemctl disable NetworkManager

方法2. 在/etc/sysconfig/network-scripts/ifcfg-eth0文件中设置

  NM_CONTROLLED="no"

还试了其他一些方法,都没用。而且发现使用 systemctl restart network报错:

[root@node05 ~]# systemctl restart network
Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
[root@node05 ~]# systemctl status network
● network.service - LSB: Bring up/down networking
Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2019-04-26 09:03:05 EDT; 8s ago
Docs: man:systemd-sysv-generator(8)
Process: 9950 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)

Apr 26 09:03:05 node05 network[9950]: RTNETLINK answers: File exists
Apr 26 09:03:05 node05 network[9950]: RTNETLINK answers: File exists
Apr 26 09:03:05 node05 network[9950]: RTNETLINK answers: File exists
Apr 26 09:03:05 node05 network[9950]: RTNETLINK answers: File exists
Apr 26 09:03:05 node05 network[9950]: RTNETLINK answers: File exists
Apr 26 09:03:05 node05 network[9950]: RTNETLINK answers: File exists
Apr 26 09:03:05 node05 systemd[1]: network.service: control process exited, code=exited status=1
Apr 26 09:03:05 node05 systemd[1]: Failed to start LSB: Bring up/down networking.
Apr 26 09:03:05 node05 systemd[1]: Unit network.service entered failed state.
Apr 26 09:03:05 node05 systemd[1]: network.service failed.

最终在贴吧里看到将DEVICE=eth0注释掉的方法,试了一下,静态IP生效了,但是systemctl restart network仍然报错。原因未知。。。。反正静态IP配置好了,但是浪费了好多时间。。。


2019/4/27  把DEVICE注释掉后不能联网了,why....


2019/5/17  将路由地址默认网关DNS配置好可解决大部分配置静态地址后不能上网的问题。

eg.

[root@node04 test]# ifconfig
ens33: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
inet 192.168.30.139 netmask 255.255.255.0 broadcast 192.168.30.255
inet6 fe80:::f55c:b51d:9cc7 prefixlen scopeid 0x20<link>
ether :0c::f3:da:5a txqueuelen (Ethernet)
RX packets bytes (20.0 MiB)
RX errors dropped overruns frame
TX packets bytes (23.3 MiB)
TX errors dropped overruns carrier collisions lo: flags=<UP,LOOPBACK,RUNNING> mtu
inet 127.0.0.1 netmask 255.0.0.0
inet6 :: prefixlen scopeid 0x10<host>
loop txqueuelen (Local Loopback)
RX packets bytes (8.7 MiB)
RX errors dropped overruns frame
TX packets bytes (8.7 MiB)
TX errors dropped overruns carrier collisions
[root@node04 test]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG ens33
192.168.30.0 0.0.0.0 255.255.255.0 U ens33
[root@node04 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@node04 network-scripts]# cat ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.30.138
NETMASK=255.255.255.0
GETWAY=192.168.1.1
DNS1=114.114.114.114
上一篇:百度搜索引擎关键字URL采集爬虫优化行业定投方案高效获得行业流量-代码篇


下一篇:SystemML大规模机器学习,优化算子融合方案的研究