centos8 card use -nmcli

In 2004 Red Hat NetworkManager is the start of the project, designed to allow Linux users to more easily handle the needs of modern networks, especially wireless networks, can automatically discover and configure network adapter ip address.

On rhel8, it must be turned NM, or can not use the network.

Similarly wifi phones simultaneously turned on and the cellular network, and automatically detect the available network connection without manual switching.

nmcli use

nmcli use very similar linux ip command, cisco switch command, and tab-completion, but also in the last command by -h, - help, help View help. There are two most commonly used commands in nmcli in:

nmcli connection

Translated connection , understood as the configuration file , corresponding to ifcfg-eth0. It may be abbreviated as nmcli c

nmcli device

Translation devices , is understood to actually existing card (NIC includes a physical and virtual NIC). It may be abbreviated as nmcli d

In NM, there are two dimensions: the connection (connection) and equipment (Device) , which is related many-to. I want to give a card with ip, first of all to be able nanotube NM NIC. LAN equipment in existence (ie nmcli d can be seen), that is, NM nanotubes. Next, may be configured as a plurality of connection devices (i.e. nmcli c can be seen), each connection can be understood as a ifcfg profile. The same time, a device can have only one active connection. By nmcli c up switch connection.   

connection has two states :

▷ active (colored font): Indicates that the connection into force ▷ inactive (normal font): Indicates that the connection does not take effect

There are four common device status :

▷ connected: NM nanotubes have been, and currently has an active connection ▷ disconnected: NM nanotubes have been, but currently there is no active connection ▷ unmanaged: not NM nanotube ▷ unavailable: unavailable, NM unable nanotubes, generally when the card appears in the link is down (such as ip link set ethX down)


Configuration dynamic IP (equivalent to the configuration ifcfg, wherein BOOTPROTO = dhcp, and start ifup)

nmcli c add type ethernet con-name eth0 ifname ens33 ipv4.method auto

type ethernet: When creating a connection must specify the type, there are many types, can be seen by -h nmcli c add type, designated here as ethernet.

name-CON eth0 ifname ens33 : first eth0 represents the name of the connection (connection), the name can be arbitrarily defined, and network cards do not need to name the same ; the second ens33 express card name, this ens33 must be able to see where in the nmcli d of.

Configuring a static IP (equivalent to the configuration ifcfg, wherein BOOTPROTO = none, and start ifup)

nmcli c add type ethernet con-name eth0 ifname ens33 ipv4.addr 192.168.1.100/24 ipv4.gateway 192.168.1.254 ipv4.dns '8.8.8.8,4.4.4.4' ipv4.method manual

ipv4.method对应ifcfg文件内容的BOOTPROTO,ipv4.method默认为auto,对应为BOOTPROTO=dhcp这种时候如果指定ip,就可能导致网卡同时有dhcp分配的ip和静态ip。设置为manual表示BOOTPROTO=none,即只有静态ip。

# 查看ip(类似于ifconfig、ip addr)

nmcli

# 启用指定网卡配置文件(相当于ifup)

nmcli c up ethX

# 停止指定网卡配置文件(相当于ifdown)

nmcli c down ethX

# 删除指定网卡配置文件(类似于ifdown并删除ifcfg)

nmcli c delete ethX

# 查看connection列表

nmcli c show

# 查看connection详细信息

nmcli c show ethX

# 重载所有网卡配置文件(不会立即生效)

nmcli c reload

# 重载指定ifcfg或route到connection(不会立即生效)

nmcli c load /etc/sysconfig/network-scripts/ifcfg-ethX

nmcli c load /etc/sysconfig/network-scripts/route-ethX

# 立即使网卡配置文件生效,有3种方法

nmcli c up eth0                # 启用指定网卡配置文件

nmcli d reapply eth0        #刷新网卡配置文件,前提是网卡的device处于connected状态,否则会报错。

nmcli d connect eth0       #激活网卡

# 查看网卡列表

nmcli d

# 查看所有网卡的详细信息

nmcli d show

# 查看指定网卡的详细信息

nmcli d show eth0

# 激活网卡(就算之前nmcli c delete eth0删除网卡配置文件,也可以使用此命令激活重新生成配置文件

由NM对指定网卡进行管理,同时刷新该网卡对应的活跃connection(如果之前有修改过connection配置);如果有connection但是都处于非活跃状态,则自动选择一个connection并将其活跃;如果没有connection,则自动生成一个并将其活跃。

nmcli d connect eth0

nmcli d disconnect eth0

让NM暂时不管理指定网卡,此操作不会变更实际网卡的link状态,只会使对应的connection变成非活跃。若重启系统则又会自动connect。另外,如果手工将该网卡的connection全部删掉,该网卡状态也会自动变为disconnected。

# 关闭无线网络(NM默认启用无线网络)

nmcli r all off

# 查看NM启动状态

nmcli n

# 开启NM纳管

nmcli n on

# 关闭NM纳管(谨慎执行)

nmcli n off

# 监听事件

nmcli m

# 查看NM本身状态

nmcli

# 检测NM是否在线可用

nm-online


Guess you like

Origin blog.51cto.com/7072753/2416910
Recommended