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=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.30.139  netmask 255.255.255.0  broadcast 192.168.30.255
        inet6 fe80::3711:f55c:b51d:9cc7  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:f3:da:5a  txqueuelen 1000  (Ethernet)
        RX packets 163813  bytes 21019361 (20.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 197627  bytes 24532180 (23.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 63821  bytes 9132036 (8.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 63821  bytes 9132036 (8.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[root@node04 test]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 ens33
192.168.30.0    0.0.0.0         255.255.255.0   U     100    0        0 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

 

posted @ 2019-04-26 21:17  梦醒江南·Infinite  阅读(3897)  评论(0编辑  收藏  举报