1. CentOS7
编辑配置文件:/etc/sysconfig/network-scripts/ifcfg-ens33(ens33 为网卡名)
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" # 1
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="c85c107e-c186-4c5f-bfab-431e8a3ffd32"
DEVICE="ens33"
ONBOOT="yes" # 2
IPADDR="192.168.1.152" # 3
NETMASK="255.255.255.0" # 4
GATEWAY="192.168.1.2" # 5
DNS1="222.201.130.30" # 6
DNS2="222.201.130.33" # 7
$ sudo service network restart
2. CentOS8
网络接口配置文件同 CentOS7,但重启接口配置需使用如下方式:
$ sudo nmcli c reload
$ sudo nmcli c up ens33
3. Ubuntu16
编辑配置文件:/etc/network/interfaces
auto lo
iface lo inet loopback
auto ens33
iface ens33 inet static
address 192.168.1.153
netmask 255.255.255.0
gateway 192.168.1.2
dns-nameservers 222.201.130.30 222.201.130.33
$ sudo ip addr flush dev ens33
$ sudo /etc/init.d/networking restart
4. Ubuntu18
编辑配置文件:/etc/netplan/01-network-manager-all.yaml
network:
version: 2
renderer: NetworkManager
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses: [192.168.1.200/24]
gateway4: 192.168.1.2
nameservers:
addresses: [222.201.130.30, 222.201.130.33]
$ sudo netplan apply
5. Ubuntu20
同 Ubuntu18.