CentOS8 network management and previous methods vary widely, no conventional network.service (the default is discarded, installable) generally used NetworkManager
(referred to NM
) command set. For the next series of Red Hat a large version of the system will only support NetworkManager
, it is recommended to master. NetworkManager
More important is a command: nmcli
.
1. nmcli
understanding
nmcli
There are two important concepts: nmcli connection
and nmcli device
.
nmcli connection
And that a connection can be understood as the configuration file, it can be abbreviated as follows: nmcli c
it has two states: active and inactive.
nmcli device
Indicates that the device can be understood as our card, the card needs to be NM
satisfied that the tube before you can configure one or more devices that are connected, the same time, a device can have a corresponding connection.
1.1 nmcli connection
View a list of all connections
nmcli c
# 或者
nmcli connection
# 或者
nmcli connection show
# 或者
nmcli c show
The results have four, namely: the name of the connection (connection ID), UUID connection, connection type, device name (name card)
1.2 View a list of all devices
nmcli device
nmcli d
Results There are four, namely: the device name (name of the NIC), connection type, the connection status, the name of the connection (connection identifier)
1.3 create a connection
nmcli c add type ethernet con-name 连接名称 ifname 网卡名称 [各种参数……]
After you create the connection will /etc/sysconfig/network-scripts/
automatically create a directory ifcfg-连接名
of files
Description:
- type: Required, indicates that the network type, there are many types, you can
nmcli c add type -h
see, designated hereethernet
- con-name: Required, indicates that the connection name can be arbitrarily defined
- ifname: Required to indicate the name of the card, not free to fill in must be
nmcli d
able to see inside
Other common parameters (IPV4):
nmcli parameters | Corresponding ifcfg- * file | Description result |
---|---|---|
ipv4.method manual |
BOOTPROTO=none |
Set a static IPV4 address |
ipv4.method auto |
BOOTPROTO=dhcp |
Set to automatically obtain IPV4 address |
ipv4.address "192.168.0.10/24" |
IPADDR=192.168.0.10 PREFIX=24 |
Set IPV4 address, the network prefix |
ipv4.gateway 192.168.0.1 |
GATEWAY=192.168.0.1 |
Set the gateway address |
ipv4.dns 8.8.8.8 |
DNS1=8.8.8.8 (Google domain name system open to the public) |
Set DNS (Domain Name System) address |
connection.autoconnect yes |
ONBOOT=yes |
This connection is provided automatically activated to start |
Creating examples
nmcli c add type ethernet con-name ss ifname ens33 ipv4.address '192.168.101.201/24' ipv4.gateway 192.168.101.1 ipv4.dns '8.8.8.8,4.4.4.4' ipv4.method manual
注
: Ipv4.dns 8.8.8.8
Google publicly Domain Name System
Executing the command, we can see the use of the command nmcli c
to view the list of connections the machine have. For example, like this:
NAME UUID TYPE DEVICE
ens33 6f8161e2-be5b-453a-a721-1a03dc01db48 ethernet ens33
ss f4946c30-0b13-4f31-baf5-2b7ebac6675d ethernet --
Meanwhile, /etc/sysconfig/network-scripts/
automatically creates a directory ifcfg-ss
of files, similar to this:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.101.201
PREFIX=24
GATEWAY=192.168.101.1
DNS1=8.8.8.8
DNS2=4.4.4.4
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=ss
UUID=f4946c30-0b13-4f31-baf5-2b7ebac6675d
DEVICE=enp0s3
ONBOOT=yes
1.4 stop and activate the connection
# 停止connection
nmcli c down 连接名称
# 激活连接
nmcli c up 连接名称
Once the connection is activated, the network configuration will take effect.
1.5 To delete a connection
nmcli c delete 连接名称
2. Configure a static IP
2.1 Method 1: Use the modified TUI
Enter the command at the command line: nmtui
you will see a graphical interface, use the keyboard arrow keys and the enter key, select Edit a connection
, and then select the card you want to modify the name, and then select Edit
, enter the new page, configure the corresponding IP address according to their own circumstances, then choose the bottom OK
, and then select Back
, TUI back to the first page, select Activate a connection
, enter the continuous press the enter key twice, to restart the activation of the connection represents, in front of the card have a name *
indicates is active, then choose Back
to return back after the first screen choose Quit
to.
2.2 Method 2: Use the conventional configuration script to modify (in some cases may not be installed in the system)
# enp0s3 表示连接的名称
vi /etc/sysconfig/network-scripts/ifcfg-ens33
Then modify the few (if not on these items added):
# 不再是static了
BOOTPROTO=none
# 这是设置IP地址
IPADDR=192.168.101.205
# 这是子网掩码
NETMASK=255.255.255.0
# 这是网关地址
GATEWAY=192.168.101.1
# 这是dns服务器的配置
DNS1=192.168.101.1
Save and exit the command:
# 连接重载配置文件
nmcli c reload
# 重启NetworkManager
nmcli networking off
nmcli networking on
2.3 Method 3: Referring 1.3, 1.4 of the front portion
mtui graphical interface to set the network
View the machine IP command
# 下面两个命令都可以在CentOS8上查看本机IP
ip addr
nmcli