centos8之网卡配置
前言
centos8的网卡服务与centos7有所不同,无法通过systemctl或者service命令重启网卡。centos8网卡服务由nmcli进行管理。
网卡配置
1.进入网卡配置目录
[root@k146 rke2]# cd /etc/sysconfig/network-scripts/
[root@k146 network-scripts]# ls -l
总用量 4
-rw-r--r-- 1 root root 395 5月 22 09:16 ifcfg-ens33
2.编辑网卡配置文件
[root@k146 rke2]# cd /etc/sysconfig/network-scripts/
[root@k146 network-scripts]# ls -l
总用量 4
-rw-r--r-- 1 root root 395 5月 22 09:16 ifcfg-ens33
[root@k146 network-scripts]#
[root@k146 network-scripts]# cat ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=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
NAME=ens33
UUID=ba56f6bf-192e-4b80-a55b-6064d580ae64
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.111.146
PREFIX=24
GATEWAY=192.168.111.254
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=114.114.114.114
3.重载网卡配置
nmcli c reload ens33
4.重启网卡/下线网卡
nmcli c up ens33
nmcli c down ens33
nmcli命令管理网卡
查看网卡信息
[root@s2hdBXU91 ~]# nmcli connection
NAME UUID TYPE DEVICE
enp1s0 c0ab6b8c-0eac-a1b4-1c47-efe4b2d1191f ethernet enp1s0
docker0 ee0a82b5-d7eb-4eb5-b90d-d033a4f315c6 bridge docker0
显示具体的网络接口信息
[root@k146 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
ens33 ba56f6bf-192e-4b80-a55b-6064d580ae64 ethernet ens33
[root@k146 network-scripts]#
[root@k146 network-scripts]#
[root@k146 network-scripts]# nmcli connection show ens33
connection.id: ens33
connection.uuid: ba56f6bf-192e-4b80-a55b-6064d580ae64
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: ens33
connection.autoconnect: 是
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0(default)
....
显示所有活动连接
[root@k146 network-scripts]# nmcli connection show --active
NAME UUID TYPE DEVICE
ens33 ba56f6bf-192e-4b80-a55b-6064d580ae64 ethernet ens33
添加一个网卡
nmcli connection add type ethernet con-name eth0
Connection ‘eth0’ (28f1b3d6-4f13-41a3-a809-1c82fd2f470f) successfully added.
删除一个网卡连接
nmcli connection delete virbr0
Connection ‘virbr0’ (9902a052-4775-434a-9531-62712a3be9c3) successfully deleted.