经验教程 ·

centos8之网卡配置修改及管理

一、情况说明
centos8的网卡服务与centos7有所不同,无法通过systemctl或者service命令重启网卡。centos8网卡服务由nmcli进行管理。

[[email protected] network-scripts]# systemctl restart network
Failed to restart network.service: Unit network.service not found.
[[email protected] network-scripts]# service network restart
Redirecting to /bin/systemctl restart network.service
Failed to restart network.service: Unit network.service not found.

二、网卡配置
1、进入网卡配置目录

[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# ll
total 4
-rw-r–r--. 1 root root 366 Mar 4 22:35 ifcfg-ens33

2、编辑网卡配置文件

[[email protected] network-scripts]# vim ifcfg-ens33

将BOOTPROTO参数由dhcp改为static,根据需要配置IP地址、掩码、网关、DNS等信息

BOOTPROTO=static
IPADDR=192.168.0.127
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=114.114.114.114

3、重载网卡配置

[[email protected] network-scripts]# nmcli c reload ens33

4、重启网卡

[[email protected] network-scripts]# nmcli c up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)

5、验证网络

[[email protected] network-scripts]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from localhost (183.232.231.174): icmp_seq=1 ttl=52 time=18.8 ms
64 bytes from localhost (183.232.231.174): icmp_seq=2 ttl=52 time=18.2 ms
^C
— www.a.shifen.com ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 4ms
rtt min/avg/max/mdev = 18.228/18.503/18.779/0.307 ms

三、nmcli命令管理网卡
1、查看网卡信息

[[email protected] network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
ens33 2cf75158-1e14-46c8-be85-b3d9cd0e8352 ethernet ens33
virbr0 9902a052-4775-434a-9531-62712a3be9c3 bridge virbr0

2、显示具体的网络接口信息

[[email protected] network-scripts]# nmcli connection show ens33
connection.id: ens33
connection.uuid: 2cf75158-1e14-46c8-be85-b3d9cd0e8352
connection.stable-id: –
connection.type: 802-3-ethernet
connection.interface-name: ens33
connection.autoconnect: yes
…

3、显示所有活动连接

[[email protected] network-scripts]# nmcli connection show --active
NAME UUID TYPE DEVICE
ens33 2cf75158-1e14-46c8-be85-b3d9cd0e8352 ethernet ens33
virbr0 9902a052-4775-434a-9531-62712a3be9c3 bridge virbr0

4、添加一个网卡

[[email protected] network-scripts]# nmcli connection add type ethernet con-name eth0
Connection ‘eth0’ (28f1b3d6-4f13-41a3-a809-1c82fd2f470f) successfully added.

5、删除一个网卡连接

[[email protected] network-scripts]# nmcli connection delete virbr0
Connection ‘virbr0’ (9902a052-4775-434a-9531-62712a3be9c3) successfully deleted.

6、给添加一个IP(IPADDR)

[[email protected] network-scripts]# nmcli connection modify eth0 ipv4.addresses 192.168.10.100

7、给xxx添加一个子网掩码(NETMASK)

[[email protected] network-scripts]# nmcli connection modify eth0 ipv4.addresses 192.168.10.100/24

8、添加一个ipv4
此处参数为+ipv4.addresses,即在此原来的配置上添加一个地址配置,无+则是在原来的基础上修改IP地址。

[[email protected] network-scripts]# nmcli connection modify eth0 +ipv4.addresses 192.168.30.100/24

9、删除一个ipv4

[[email protected] network-scripts]# nmcli connection modify eth0 -ipv4.addresses 192.168.20.100/24

10、添加DNS

[[email protected] network-scripts]# nmcli connection modify eth0 +ipv4.dns 211.142.211.124

11、删除DNS

[[email protected] network-scripts]# nmcli connection modify eth0 -ipv4.dns 114.114.114.114

12、添加一个网关(GATEWAY)

[[email protected] network-scripts]# nmcli connection modify eth0 ipv4.gateway 192.168.0.1

13、使用nmcli重新回载网络配置

[[email protected] network-scripts]# nmcli c reload

如果之前没有xxx的connection,则上一步reload后就已经自动生效了

14、重启网卡

[[email protected] network-scripts]# nmcli c up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)

15、下线网卡

[[email protected] network-scripts]# nmcli c down ens33

————————————————

原文链接:https://blog.csdn.net/carefree2005/article/details/114396600

参与评论