CentOS8 Stream 网卡配置操作

CentOS8  已废弃network.service,网卡操作需要使用nmcli ,当前整理配置文件操作及相关命令

命令:nmcli

配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0

配置单个ipv4地址

  • IP:60.247.159.221    掩码:255.255.255.0     网关:60.247.159.1

[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# 申明网卡eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=60.247.159.221
NETMASK=255.255.255.0
GATEWAY=60.247.159.1
TYPE=Ethernet
ONBOOT=yes

配置多个ipv4地址

  • IP1:60.247.159.221  掩码1:255.255.255.0  网关1:60.247.159.152

  • IP2:60.247.159.221  掩码2:255.255.255.0

    多ip配置一般只需要配置一个GATEWAY0 网关即可

[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# 申明网卡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

几个依此添加即可,如果ip较多,一个IP段添加。

先通过http://tool.520101.com/wangluo/ipjisuan/ 计算ip地址

image.png


获取到第一个和最后一个可用ip尾数为193和254,以及掩码255.255.255.192,并注意服务器上网络连接名称,加入

for I in $(seq 193 254); do nmcli con mod eth0 +ipv4.addresses 192.168.1.${I}/26; done


单个ipv6配置

  • ipv4:60.247.159.221     掩码:255.255.255.0    网关:60.247.159.1

  • ipv6:240E:D9:C200:160:9404::1A80   掩码位数:64   网关:240e:d9:c200:160::1

[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# 申明网卡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

多个ipv6配置

  • ipv4:60.247.159.221     掩码:255.255.255.0    网关:60.247.159.1

  • ipv6:240E:D9:C200:160:9404::1A80-240E:D9:C200:160:9404::1a9f   掩码位数:64   网关:240e:d9:c200:160::1

[root@ebs-113436 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

# 申明网卡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配置
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6ADDR=240E:D9:C200:160:9404::1A80/64
IPV6_DEFAULTGW=240e:d9:c200:160::1
# 多IPV6配置  用空格分开
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 批量配置教程https://faq.myhostadmin.net/faq/listagent.asp?unid=2276


以上配置后需要重启网卡生效;


网卡服务重启

# 查看网卡名称
[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  
# 重启网卡服务
[root@ebs-113436 ~]# nmcli c reload "System eth0"
[root@ebs-113436 ~]# nmcli c up "System eth0"

# 如果不生效
[root@ebs-113436 ~]# nmcli device reapply eth0
[root@ebs-113436 ~]# nmcli device connect eth0




日期:2022-02-22

打印 】