vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens160 #設置自動啟動ens160接口
#iface ens160 inet dhcp
iface ens160 inet static #配置靜態IP
address 10.1.18.200 #IP地址
netmask 255.255.255.0 #子網掩碼
gateway 10.1.18.254 #默認網關
dns-nameserver 210.32.32.10
dns-nameserver 210.32.32.10 這句一定需要有,
因為以前是DHCP解析,所以會自動分配DNS 服務器地址。
而一旦設置為靜態IP后就沒有自動獲取到DNS服務器了
設置完重啟電腦
/etc/resolv.conf
文件中會自動添加
nameserver 210.32.32.10
(或者nameserver 8.8.8.8)可以根據訪問速度,選擇合適的公共DNS