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://www.west.cn/faq/list.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

收藏 】 【 打印 】   
您可对文档进行评分哟~

勾选遇到的问题提交给我们,收到反馈后保证及时修正更新!

提交反馈需要先登陆会员帐号

上一篇:西部数码账号注销说明
下一篇:企业云邮附件大小
若文档内容对您没有帮助,不能解决问题? 您还可以 咨询在线客服提交工单搜索常见问题 ,我们将竭诚为您服务。
  >> 相关文章
 
分享至:
Top

24小时客服热线

400-028-5800

028-62778877

您好,非正常上班时间若有紧急技术问题,请拨总机后按7号键, 其他问题请提交工单或在上班时间联系,谢谢支持!