CentOS8 Stream network card configuration operation
Published: 2022-02-22
CentOS8 has deprecated network.service. Network interface operations require nmcli. This article organizes configuration file operations and related commands.
Command:nmcli
Configuration file: /etc/sysconfig/network-scripts/ifcfg-eth0
Configuring a single IPv4 address
[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Declare NIC eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=60.247.159.221
NETMASK=255.255.255.0
GATEWAY=60.247.159.1
TYPE=Ethernet
ONBOOT=yes
Configuring multiple IPv4 addresses
IP1:60.247.159.221 Netmask1: 255.255.255.0 Gateway1: 60.247.159.152
IP2:60.247.159.221 Netmask2: 255.255.255.0
For multiple IP configuration, generally only one GATEWAY0 gateway needs to be configured.
[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Declare NIC eth0
DEVICE=eth0
BOOTPROTO=static
TYPE=Ethernet
ONBOOT=yes
IPADDR0=60.247.159.221
IPADDR1=60.247.159.152
NETMASK0=255.255.255.0
NETMASK1=255.255.255.0
.
.
.
.
.
.
GATEWAY0=60.247.159.1
Add the rest in sequence; if there are many IPs, add them as an IP range.
First usehttp://tool.520101.com/wangluo/ipjisuan/ to calculate the IP addresses

The first and last usable IP suffix numbers are 193 and 254, and the netmask is 255.255.255.192. Also note the network connection name on the server, then add:
for I in $(seq 193 254); do nmcli con mod eth0 +ipv4.addresses 192.168.1.${I}/26; doneSingle IPv6 configuration
IPv4: 60.247.159.221 Netmask: 255.255.255.0 Gateway: 60.247.159.1
IPv6: 240E:D9:C200:160:9404::1A80 Prefix length: 64 Gateway: 240e:d9:c200:160::1
[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Declare NIC eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=60.247.159.221
NETMASK=255.255.255.0
GATEWAY=60.247.159.1
TYPE=Ethernet
ONBOOT=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6ADDR=240E:D9:C200:160:9404::1A80/64
IPV6_DEFAULTGW=240e:d9:c200:160::1
Multiple IPv6 configuration
IPv4: 60.247.159.221 Netmask: 255.255.255.0 Gateway: 60.247.159.1
IPv6: 240E:D9:C200:160:9404::1A80-240E:D9:C200:160:9404::1a9f Prefix length: 64 Gateway: 240e:d9:c200:160::1
[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Declare NIC eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=60.247.159.221
NETMASK=255.255.255.0
GATEWAY=60.247.159.1
TYPE=Ethernet
ONBOOT=yes
# IPv6 configuration
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6ADDR=240E:D9:C200:160:9404::1A80/64
IPV6_DEFAULTGW=240e:d9:c200:160::1
# Multiple IPv6 configuration, separated by spaces
IPV6ADDR_SECONDARIES="240E:D9:C200:160:9404::1a80/64 240E:D9:C200:160:9404::1a81/64 240E:D9:C200:160:9404::1a82/64 240E:D9:C200:160:9404::1a83/64 240E:D9:C200:160:9404::1a84/64 240E:D9:C200:160:9404::1a85/64 240E:D9:C200:160:9404::1a86/64 240E:D9:C200:160:9404::1a87/64 240E:D9:C200:160:9404::1a88/64 240E:D9:C200:160:9404::1a89/64 240E:D9:C200:160:9404::1a8a/64 240E:D9:C200:160:9404::1a8b/64 240E:D9:C200:160:9404::1a8c/64 240E:D9:C200:160:9404::1a8d/64 240E:D9:C200:160:9404::1a8e/64 240E:D9:C200:160:9404::1a8f/64 240E:D9:C200:160:9404::1a90/64 240E:D9:C200:160:9404::1a91/64 240E:D9:C200:160:9404::1a92/64 240E:D9:C200:160:9404::1a93/64 240E:D9:C200:160:9404::1a94/64 240E:D9:C200:160:9404::1a95/64 240E:D9:C200:160:9404::1a96/64 240E:D9:C200:160:9404::1a97/64 240E:D9:C200:160:9404::1a98/64 240E:D9:C200:160:9404::1a99/64 240E:D9:C200:160:9404::1a9a/64 240E:D9:C200:160:9404::1a9b/64 240E:D9:C200:160:9404::1a9c/64 240E:D9:C200:160:9404::1a9d/64 240E:D9:C200:160:9404::1a9e/64 240E:D9:C200:160:9404::1a9f/64"
IPv6 batch configuration tutorialhttps://www.west.cn/faq/list.asp?unid=2276
After the above configuration, you need to restart the network card for it to take effect;
Network service restart
# View network card names
[root@ebs-113436 ~]# nmcli c
NAME UUID TYPE DEVICE
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 ethernet eth0
System eth1 9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04 ethernet eth1
# Restart network service
[root@ebs-113436 ~]# nmcli c reload "System eth0"
[root@ebs-113436 ~]# nmcli c up "System eth0"
# If it does not take effect
[root@ebs-113436 ~]# nmcli device reapply eth0
[root@ebs-113436 ~]# nmcli device connect eth0
