Centos7网卡启动失败解决

日常我们做练习的时候,linux服务器都是跑在VM里面的,有时断网或者其他原因就会遇到服务器突然不读取ip地址了,导致客户端远程不能连接,如下图

网上也有说去windows系统的任务管理器把VMnetDHCP与VMware NAT Service这个两个开启可是我的服务一直在运行中,我于是就重启了服务结果发现ip突然有了?

但是systemctl status network.service还是报错呢?

而且重启还是失败的

[root@centos7 ~]#service network restart
Restarting network (via systemctl):  Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
                                                           [失败]

使用ifconfig看一下发现网卡名不一样啊?这个叫eth0啥时换的?我的叫ens33吧。

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:9c:9e:4f brd ff:ff:ff:ff:ff:ff
    inet 192.168.111.190/24 brd 192.168.111.255 scope global noprefixroute dynamic eth0
       valid_lft 2699sec preferred_lft 2699sec
    inet6 2408:8409:7820:7ed0:4adb:ec9b:72d9:91a1/64 scope global noprefixroute dynamic 
       valid_lft 3600sec preferred_lft 3600sec
    inet6 fe80::b312:e24:168f:10ab/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

之后在cd /etc/sysconfig/network-scripts/ 修改里面的ifcfg-ens33修改网卡名把原来ens33修改为eth0之后在加入HWADDR=XXX,eth0的mac地址

之后我在看一下网卡状态,没问题了。

[root@centos7 /]#systemctl status network.service
● network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
   Active: active (running) since 二 2023-05-16 18:58:37 CST; 25min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 25268 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
  Process: 25441 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)
    Tasks: 1
   CGroup: /system.slice/network.service
           └─25648 /sbin/dhclient -1 -q -lf /var/lib/dhclient/dhclient-74a5ce3b-eeda-4022-ac03...

5月 16 18:58:35 centos7.magedu.com network[25441]: 正在打开环回接口: [  确定  ]
5月 16 18:58:35 centos7.magedu.com network[25441]: 正在打开接口 ens33:
5月 16 18:58:35 centos7.magedu.com dhclient[25581]: DHCPDISCOVER on eth0 to 255.255.255.255...8)
5月 16 18:58:35 centos7.magedu.com dhclient[25581]: DHCPREQUEST on eth0 to 255.255.255.255 ...8)
5月 16 18:58:35 centos7.magedu.com dhclient[25581]: DHCPOFFER from 192.168.111.145
5月 16 18:58:35 centos7.magedu.com dhclient[25581]: DHCPACK from 192.168.111.145 (xid=0x30c...8)
5月 16 18:58:37 centos7.magedu.com dhclient[25581]: bound to 192.168.111.190 -- renewal in ...s.
5月 16 18:58:37 centos7.magedu.com network[25441]: 正在确定 eth0 的 IP 信息... 完成。
5月 16 18:58:37 centos7.magedu.com network[25441]: [  确定  ]
5月 16 18:58:37 centos7.magedu.com systemd[1]: Started LSB: Bring up/down networking.
Hint: Some lines were ellipsized, use -l to show in full.

重启网卡也没有问题,这回好了

[root@centos7 network-scripts]#service network restart
Restarting network (via systemctl):                        [  确定  ]

附加:

关闭NetworkManager服务,重启机器后会失效

systemctl stop NetworkManager

永久关闭NetworkManager服务,重启机器后不会失效

systemctl disable NetworkManager

 

版权声明:
作者:微笑蝈蝈
链接:https://www.weixiaoguo.cn/?p=498
来源:微笑蝈蝈
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>