Centos7 配置静态ip及问题处理

进入对应的网卡配置目录

首先进入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 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!