CentOS 8 的网络配置
CentOS 7
/etc/init.d/network restart
CentOS 8 上使用 nmcli
管理网络配置:
# 检查 NetworkManager 服务是否启动
# systemctl status NetworkManager.service
[root@localhost ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens33 ethernet connected ens33
lo loopback unmanaged --
[root@localhost ~]#
网上的配置文件路径不变:
[root@localhost ~]# ll /etc/sysconfig/network-scripts/ifcfg-ens33
-rw-r--r--. 1 root root 271 Apr 7 09:55 /etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost ~]#
查看 ens33
网上的信息:
[root@localhost ~]# nmcli device show ens33
GENERAL.DEVICE: ens33
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:51:B3:FA
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: ens33
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.30.242/22
IP4.GATEWAY: 192.168.30.1
IP4.ROUTE[1]: dst = 192.168.28.0/22, nh = 0.0.0.0, mt = 100
IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 192.168.30.1, mt = 100
IP4.DNS[1]: 192.168.0.7
IP4.DNS[2]: 202.96.209.133
IP6.ADDRESS[1]: fe80::20c:29ff:fe51:b3fa/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 1024
[root@localhost ~]#
修改网卡配置信息后,重新加载并启用或激活网卡配置:
nmcli connection reload
或 nmcli c reload
,
nmcli c up ens33
[root@localhost ~]# nmcli c reload
[root@localhost ~]#
[root@localhost ~]# nmcli c up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@localhost ~]#
使用 DHCP 时的配置:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=eui64
NAME=ens33
UUID=18fb67f5-5aa6-4891-9fec-c94aced0a369
DEVICE=ens33
ONBOOT=yes
改为静态IP后的配置:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
# BOOTPROTO 改为 static
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=eui64
NAME=ens33
UUID=18fb67f5-5aa6-4891-9fec-c94aced0a369
DEVICE=ens33
ONBOOT=yes
# 配置IP信息
IPADDR=192.168.30.242
NETMASK=255.255.255.0
GATEWAY=192.168.30.1
DNS1=192.168.0.7
DNS2=116.228.111.118
[root@localhost ~]# vi !$
vi /etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost ~]#
[root@localhost ~]# nmcli c reload
[root@localhost ~]# nmcli c up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
[root@localhost ~]#
[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.30.242 netmask 255.255.255.0 broadcast 192.168.30.255
inet6 fe80::20c:29ff:fe51:b3fa prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:51:b3:fa txqueuelen 1000 (Ethernet)
RX packets 33893 bytes 3840624 (3.6 MiB)
RX errors 0 dropped 866 overruns 0 frame 0
TX packets 1401 bytes 174662 (170.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]#
标签:nmcli,CentOS,配置,网络,192.168,yes,root,localhost,ens33 From: https://www.cnblogs.com/zhpj/p/18133037/centos-8-de-wang-luo-pei-zhi-zo9fbl