部分系统(例如7.2)网卡名称比较长。#为演示方便添加,实际文件未显示。

[root@promote ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@promote ~]# cd /etc/sysconfig/network-scripts/
[root@promote network-scripts]# ls
ifcfg-ens33  ifdown-eth   ifdown-post    ifdown-Team      ifup-aliases  ifup-ipv6   ifup-post    ifup-Team      init.ipv6-global
ifcfg-lo     ifdown-ippp  ifdown-ppp     ifdown-TeamPort  ifup-bnep     ifup-isdn   ifup-ppp     ifup-TeamPort  network-functions
ifdown       ifdown-ipv6  ifdown-routes  ifdown-tunnel    ifup-eth      ifup-plip   ifup-routes  ifup-tunnel    network-functions-ipv6
ifdown-bnep  ifdown-isdn  ifdown-sit     ifup             ifup-ippp     ifup-plusb  ifup-sit     ifup-wireless
[root@promote network-scripts]# cat ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
#启动类型,分为dhcp和static,固定IP地址设置为static
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="7c21f428-ed27-407c-accc-2f9bd6b98085"
DEVICE="ens33"
#是否开机启动,不开机启动会导致无法远程连接
ONBOOT="yes"
[root@promote network-scripts]#

执行命令 cat /dev/null > vi /etc/sysconfig/network-scripts/ifcfg-ens33 ,添加内容如下

#注释内容不需要添加

#IP地址
IPADDR="192.168.216.137"
#默认网关
GATEWAY="192.168.216.1"
#DNS服务器,至少一个
DNS="192.168.216.1"
#DNS服务器,可以配置多个
DNS="114.114.114.114"

重启网络服务。需要注意IP地址编号可能会导致远程连接工具退出,一般修改连接IP地址重新连接即可。

[root@promote ~]# systemctl restart network

查看DNS服务器方法如下。

[root@promote ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain cache-dns.local
nameserver 192.168.216.1
nameserver 114.114.114.114
03-31 04:34