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 #設(shè)置自動(dòng)啟動(dòng)ens160接口
#iface ens160 inet dhcp
iface ens160 inet static #配置靜態(tài)IP
address 10.1.18.200 #IP地址
netmask 255.255.255.0 #子網(wǎng)掩碼
gateway 10.1.18.254 #默認(rèn)網(wǎng)關(guān)
dns-nameserver 210.32.32.10
dns-nameserver 210.32.32.10 這句一定需要有,
因?yàn)橐郧笆荄HCP解析,所以會(huì)自動(dòng)分配DNS 服務(wù)器地址。
而一旦設(shè)置為靜態(tài)IP后就沒有自動(dòng)獲取到DNS服務(wù)器了
設(shè)置完重啟電腦
/etc/resolv.conf
文件中會(huì)自動(dòng)添加
nameserver 210.32.32.10
(或者nameserver 8.8.8.8)可以根據(jù)訪問速度,選擇合適的公共DNS