Centos7 配置靜態ip及問題處理

HuDu發表於2020-09-18

進入對應的網路卡配置目錄

首先進入root使用者

$sudo su
$cd /etc/sysconfig/network-scripts/

根據具體的網路卡的情況編輯檔案

vim ifcfg-eno1

完整配置示例

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
#BOOTPROTO=dhcp
BOOTPROTO=static    # 修改為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
HWADDR=xx:xx:xx:xx:xx:xx    # mac地址
NAME=eno2
UUID=34cad817-53a4-43e4-8747-c1e911d864f3
DEVICE=eno2
#ONBOOT=no
ONBOOT=yes    # 開機自啟

IPADDR=192.168.33.61    # ip地址
GATEWAY=192.168.33.1    # 閘道器
NETMASK=255.255.255.0    # 子網
DNS1=114.114.114.114    #DNS伺服器地址
#DNS2=8.8.8.8

修改完配置檔案後,記得重啟網路服務

systemctl restart network

虛擬機器可能執行命名可以,但是實體機可能會有問題

解決報錯Failed to start LSB: Bring up/down networking:MAC地址導致

報錯大致如下

[root@ansible-control ~]# systemctl start 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@ansible-control ~]# 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 日 2019-09-29 22:44:34 CST; 1s ago
Docs: man:systemd-sysv-generator(8)
Process: 5042 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)

929 22:44:34 ansible-control network[5042]: RTNETLINK answers: File exists
929 22:44:34 ansible-control network[5042]: RTNETLINK answers: File exists
929 22:44:34 ansible-control network[5042]: RTNETLINK answers: File exists
929 22:44:34 ansible-control network[5042]: RTNETLINK answers: File exists
929 22:44:34 ansible-control network[5042]: RTNETLINK answers: File exists
929 22:44:34 ansible-control network[5042]: RTNETLINK answers: File exists
929 22:44:34 ansible-control systemd[1]: network.service: control process exited, code=exited...s=1
929 22:44:34 ansible-control systemd[1]: Failed to start LSB: Bring up/down networking.
929 22:44:34 ansible-control systemd[1]: Unit network.service entered failed state.
929 22:44:34 ansible-control systemd[1]: network.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

解決方法

關閉NetworkManager,罪魁禍首就是這個服務!

  • 一、檢視NetworkManager服務狀態:

Centos7 配置靜態ip及問題處理

  • 二、關閉NetworkManager,並設定開啟預設不啟動該服務:

    [root@ansible-control ~]# systemctl stop NetworkManager
    [root@ansible-control ~]# systemctl disable NetworkManager
    Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
    Removed symlink /etc/systemd/system/dbus-org.freedesktop.NetworkManager.service.
    Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
  • 三、重啟network服務

[root@ansible-control ~]# systemctl status network.service
● 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 日 2019-09-29 22:53:32 CST; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3620 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)

發現還是報錯,此時,我又百度了其它方法嘗試,發現是MAC地址的問題

  • 四、查詢主機的硬體地址

Centos7 配置靜態ip及問題處理

  • 五、修改/etc/sysconfig/network-scripts/ifcfg-配置_1檔案

Centos7 配置靜態ip及問題處理

  • 六、再次重啟網路
[root@ansible-control ~]# systemctl restart network
[root@ansible-control ~]# systemctl status network

或者重啟電腦,發現可以連線網路

本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章