前言:Centos 7服務器出現網絡異常的問題
排查步驟:
1.確認是否有IP地址
2.重啓網卡是否成功
3.是否有衝突的網絡管理工具(network&NetworkManger)
4.檢查網卡的配置文件是否正常
Warning:主要看日誌,默認Log存放位置(/var/log/messages)
(1)檢測是否有IP地址
(這裏就不上圖了,可以看到網卡信息,但是沒有IP地址)
我們看一下日誌
Apr 8 10:35:20 localhost network: Bringing up interface eth0: ERROR : [/etc/sysconfig/network-scripts/ifup-eth] Device has different MAC address than expected, ignoring.
Apr 8 10:35:20 localhost /etc/sysconfig/network-scripts/ifup-eth: Device has different MAC address than expected, ignoring.
Apr 8 10:35:20 localhost network: [FAILED]
Apr 8 10:35:20 localhost systemd: network.service: control process exited, code=exited status=1
Apr 8 10:35:20 localhost systemd: Failed to start LSB: Bring up/down networking.
Apr 8 10:35:20 localhost systemd: Unit network.service entered failed state.
Apr 8 10:35:20 localhost systemd: network.service failed.
這裏明顯說明MAC地址問題我們就看一下MAC地址是否正確
[root@localhost ~]# grep HAW /etc/sysconfig/network-scripts/ifcfg-eth0
HAWDDR="打碼不給你看"
然後確認一下eth0網卡的MAC地址是否正確
[root@localhost ~]# cat /sys/class/net/eth0/address
打碼打碼
現在確認MAC地址不一致,我們修改網卡配置文件
[root@localhost ~]sed -i 's'/原配置文件的MAC/現在配置文件的MAC/g' /etc/sysconfig/network-scripts/ifcfg-eth0
再次重啓網卡
[root@localhost ~]# systemctl restart network
不出意外又報錯了,我們再看一下日誌信息
Apr 8 10:43:47 localhost /etc/sysconfig/network-scripts/ifup-eth: Device does not seem to be present, delaying initialization.
Apr 8 10:43:47 localhost network: [FAILED]
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
Apr 8 10:43:47 localhost network: RTNETLINK answers: File exists
這次的報錯不一樣了,告訴我們找不到文件(這種類型的報錯範圍廣,不容易排查,我們從一下幾點排查)
1.首先排查配置文件是否指定網卡名稱
對象:文件名
網卡配置:NAME、DEVICE
2.檢查70-persistent-net.rules自定義網卡信息配置文件
3.網卡信息是否刷新
(1)檢查配置文件名稱
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
NAME="eth0"
HWADDR="打碼"
ONBOOT=yes
NETBOOT=yes
UUID="打碼"
IPV6INIT=yes
BOOTPROTO=dhcp
TYPE=Ethernet
這裏缺少DEVICE名稱我們加上
[root@localhost ~]# sed -i '3a/DEVICE=eth0' /etc/sysconfig/network-scripts/ifcfg-eth0
重啓服務嘗試
[root@localhost ~]# systemctl restart network
服務正常了
(2)檢查70-persistent-net.rules自定義網卡信息配置文件
[root@localhost ~]# cat /etc/udev/rules.d/70-persistent-net.rules
如果沒有這個文件這一步可以跳過,有的話比對信息
(3)刷新網卡
[root@localhost ~]# ip addr flush dev eth0
一般這些做完就可以排除網卡配置問題
如果還有問題請檢查route、dns、到DHCP服務器是否正常、如果是虛擬機的話查看虛擬機網卡配置是否正常等