CentOS 8 常用操作
网络配置
nmcli命令
1、显示当前网卡信息
1 2 3 4
| [root@centos8-1 network-scripts]# nmcli connection NAME UUID TYPE DEVICE Wired connection 1 d05ff1cb-7c01-3651-9cfd-01ee4b118bc8 ethernet eth1 eth0 10edd6e5-1de5-4dc3-8058-1ece613acc56 ethernet eth0
|
2、创建两个不同网络环境的配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| # 这种方法虽然说指定了IP地址 但是实际是不生效的 [root@centos8-1 network-scripts]# nmcli connection add con-name eth0-09 ifname eth0 type ethernet ipv4.addresses 172.20.7.80/24 Connection 'eth0-09' (7f8b7a58-5ba1-4774-9b69-143707792d30) successfully added. [root@centos8-1 network-scripts]# nmcli connection NAME UUID TYPE DEVICE eth0 10edd6e5-1de5-4dc3-8058-1ece613acc56 ethernet eth0 eth0-09 7f8b7a58-5ba1-4774-9b69-143707792d30 ethernet -- # 查看网卡配置文件,其中看到BOOTPROTO=dhcp [root@centos8-1 network-scripts]# cat ifcfg-eth0-09 BOOTPROTO=dhcp # 修改网卡配置不让它自动获取IP [root@centos8-1 network-scripts]# nmcli connection modify eth0-09 ipv4.method manual [root@centos8-1 network-scripts]# cat ifcfg-eth0-09 BOOTPROTO=none
|
3、网卡创建好之后查看详细信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [root@centos8-1 network-scripts]# nmcli connection show eth0-office connection.id: eth0-office connection.uuid: 08589320-088c-45b3-9f63-878285a1d24f connection.stable-id: -- connection.type: 802-3-ethernet connection.interface-name: eth0 connection.autoconnect: yes connection.autoconnect-priority: 0 connection.autoconnect-retries: -1 (default) connection.multi-connect: 0 (default) connection.auth-retries: -1 connection.timestamp: 0 connection.read-only: no connection.permissions: --
|
4、新创建好的网卡是没有被启用的需要手动启用
1
| [root@centos8-1 network-scripts]# nmcli connection up eth0-09
|
然后生效后当前终端是断了,通过虚拟机的控制端通过ip a 可以看到IP已经变了,然后再使用nmcli connection 可以看到新创建的eth0-09已经挂在到eth0上了
5、修改已经创建好的网卡名称
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| [root@centos8-1 ~]# nmcli connection modify eth0-office con-name eth0-test [root@centos8-1 ~]# nmcli connection NAME UUID TYPE DEVICE Wired connection 1 d05ff1cb-7c01-3651-9cfd-01ee4b118bc8 ethernet eth1 eth0 10edd6e5-1de5-4dc3-8058-1ece613acc56 ethernet eth0 eth0-09 7f8b7a58-5ba1-4774-9b69-143707792d30 ethernet -- eth0-test 08589320-088c-45b3-9f63-878285a1d24f ethernet -- # 这里要注意,修改的是eth0-office里面的NAME名称,/etc/sysconfig/network-scripts/ # 目录下的名称不变 [root@centos8-1 network-scripts]# ls ifcfg-eth0 ifcfg-eth0-09 ifcfg-eth0-office [root@centos8-1 network-scripts]# cat ifcfg-eth0-office TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp 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=eth0-test UUID=08589320-088c-45b3-9f63-878285a1d24f DEVICE=eth0 ONBOOT=yes # 修改网卡配置文件中的ONBOOT为no [root@centos8-1 ~]#nmcli connection modify eth0-09 connection.autoconnect no [root@centos8-1 ~]#nmcli connection reload
|