centos8之网卡配置修改及管理

前言

自己搞了一台服务器在家里自己玩玩,E5-2683 v4 32核64线程,DDR4 128G内存,3块1T硬盘做的RAID5阵列,4个NIC接口
遇到一点网络配置的问题,这篇文档感觉靠谱,帮我解决了实际问题,转载收藏下了

一、情况说明

  centos8的网卡服务与centos7有所不同,无法通过systemctl或者service命令重启网卡。centos8网卡服务由nmcli进行管理。

[root@centos8 network-scripts]# systemctl restart network
Failed to restart network.service: Unit network.service not found.
[root@centos8 network-scripts]# service network restart
Redirecting to /bin/systemctl restart network.service
Failed to restart network.service: Unit network.service not found.

二、网卡配置

1、进入网卡配置目录

[root@centos8 ~]# cd /etc/sysconfig/network-scripts/
[root@centos8 network-scripts]# ll
total 4
-rw-r–r--. 1 root root 366 Mar 4 22:35 ifcfg-ens33

2、编辑网卡配置文件

[root@centos8 network-scripts]# vim ifcfg-ens33
将BOOTPROTO参数由dhcp改为static,根据需要配置IP地址、掩码、网关、DNS等信息
BOOTPROTO=static
IPADDR=192.168.0.127
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=114.114.114.114

3、重载网卡配置

[root@centos8 network-scripts]# nmcli c reload ens33

4、重启网卡

[root@centos8 network-scripts]# nmcli c up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)

5、验证网络

[root@centos8 network-scripts]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from localhost (183.232.231.174): icmp_seq=1 ttl=52 time=18.8 ms
64 bytes from localhost (183.232.231.174): icmp_seq=2 ttl=52 time=18.2 ms
^C
— www.a.shifen.com ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 4ms
rtt min/avg/max/mdev = 18.228/18.503/18.779/0.307 ms

三、nmcli命令管理网卡

1、查看网卡信息

[root@centos8 network-scripts]# nmcli connection
NAME UUID TYPE DEVICE
ens33 2cf75158-1e14-46c8-be85-b3d9cd0e8352 ethernet ens33
virbr0 9902a052-4775-434a-9531-62712a3be9c3 bridge virbr0

2、显示具体的网络接口信息

[root@centos8 network-scripts]# nmcli connection show ens33
connection.id: ens33
connection.uuid: 2cf75158-1e14-46c8-be85-b3d9cd0e8352
connection.stable-id: –
connection.type: 802-3-ethernet
connection.interface-name: ens33
connection.autoconnect: yes

3、显示所有活动连接

[root@centos8 network-scripts]# nmcli connection show --active
NAME UUID TYPE DEVICE
ens33 2cf75158-1e14-46c8-be85-b3d9cd0e8352 ethernet ens33
virbr0 9902a052-4775-434a-9531-62712a3be9c3 bridge virbr0

4、添加一个网卡

[root@centos8 network-scripts]# nmcli connection add type ethernet con-name eth0
Connection ‘eth0’ (28f1b3d6-4f13-41a3-a809-1c82fd2f470f) successfully added.

5、删除一个网卡连接

[root@centos8 network-scripts]# nmcli connection delete virbr0
Connection ‘virbr0’ (9902a052-4775-434a-9531-62712a3be9c3) successfully deleted.

6、给添加一个IP(IPADDR)

[root@centos8 network-scripts]# nmcli connection modify eth0 ipv4.addresses 192.168.10.100

7、给xxx添加一个子网掩码(NETMASK)

[root@centos8 network-scripts]# nmcli connection modify eth0 ipv4.addresses 192.168.10.100/24

8、添加一个ipv4

此处参数为+ipv4.addresses,即在此原来的配置上添加一个地址配置,无+则是在原来的基础上修改IP地址。
[root@centos8 network-scripts]# nmcli connection modify eth0 +ipv4.addresses 192.168.30.100/24

9、删除一个ipv4

[root@centos8 network-scripts]# nmcli connection modify eth0 -ipv4.addresses 192.168.20.100/24

10、添加DNS

[root@centos8 network-scripts]# nmcli connection modify eth0 +ipv4.dns 211.142.211.124

11、删除DNS

[root@centos8 network-scripts]# nmcli connection modify eth0 -ipv4.dns 114.114.114.114

12、添加一个网关(GATEWAY)

[root@centos8 network-scripts]# nmcli connection modify eth0 ipv4.gateway 192.168.0.1

13、使用nmcli重新回载网络配置

[root@centos8 network-scripts]# nmcli c reload
如果之前没有xxx的connection,则上一步reload后就已经自动生效了

14、重启网卡

[root@centos8 network-scripts]# nmcli c up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)

15、下线网卡

[root@centos8 network-scripts]# nmcli c down ens33在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值