centos8已经发布了,下载了一个体验一下,新安装好的centos8默认网卡是没有启动的,安装好后需要先配置网络。在/etc/sysconfig/network-scripts目录下存放着网卡的配置文件,文件名称是ifcfg- 网卡名称。
一 修改配置文件
设置网络时首先打开配置文件,配置文件默认如下所示,如果使用dhcp自动获取ip,只需将ONBOOT=no修改为ONBOOT=no即可。
网卡配置文件按默认配置
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=stable-privacy
NAME=ens33
UUID=e4987998-a4ce-4cef-96f5-a3106a97f5bf
DEVICE=ens33
ONBOOT=no #如果使用dhcp分配ip的话,只需要将这里no改为yes,然后重启网络服务就行
如果需要配置静态ip,则按照以下修改方法修改
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #将dhcp修改为stati表示使用静态ip
DEFROUTE=yes
IPADDR=192.168.128.129 #设置IP地址
NETMASK=255.255.255.0 #设置子网掩码
GATEWAY=192.168.128.1 #设置网关
DNS1=114.114.114.114 #设置dns
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=e4987998-a4ce-4cef-96f5-a3106a97f5bf
DEVICE=ens33
ONBOOT=yes #将no改为yes
二 重启网络服务
使用nmcli c reload命令重启网络服务,nmcli命令的参数如下所示:
[hk@localhost network-scripts]$ nmcli -h
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }
OPTIONS
-o[verview] overview mode (hide default values)
-t[erse] terse output
-p[retty] pretty output
-m[ode] tabular|multiline output mode
-c[olors] auto|yes|no whether to use colors in output
-f[ields] |all|common specify fields to output
-g[et-values] |all|common shortcut for -m tabular -t -f
-e[scape] yes|no escape columns separators in values
-a[sk] ask for missing parameters
-s[how-secrets] allow displaying passwords
-w[ait] set timeout waiting for finishing operations
-v[ersion] show program version
-h[elp] print this help
OBJECT
g[eneral] NetworkManager’s general status and operations
n[etworking] overall networking control
r[adio] NetworkManager radio switches
c[onnection] NetworkManager’s connections # 网络管理一般使用 nmcli c
d[evice] devices managed by NetworkManager
a[gent] NetworkManager secret agent or polkit agent
m[onitor] monitor NetworkManager changes
[hk@localhost network-scripts]$
网络管理一般使用 nmclli c,用法如下:
[hk@localhost network-scripts]$ nmcli c -h
Usage: nmcli connection { COMMAND | help }
COMMAND := { show | up | down | add | modify | clone | edit | delete | monitor | reload | load | import | export }
show [–active] [–order ]
show [–active] [id | uuid | path | apath] …
up [[id | uuid | path] ] [ifname ] [ap ] [passwd-file ]
down [id | uuid | path | apath] …
add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [– ([+|-]. )+]
modify [–temporary] [id | uuid | path] ([+|-]. )+
clone [–temporary] [id | uuid | path ]
edit [id | uuid | path]
edit [type ] [con-name ]
delete [id | uuid | path]
monitor [id | uuid | path] …
reload
load [ … ]
import [–temporary] type file
export [id | uuid | path] []
[hk@localhost network-scripts]$