找到文件并作如下修改
sudo vim /etc/network/interfaces
# The primary network interface
auto eno1
iface eno1 inet static
address 192.168.1.111
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 202.101.172.35 202.101.172.46
修改dns解析
因为以前是dhcp解析,所以会自动分配dns服务器地址
而一旦设置为静态ip后就没有自动获取到的dns服务器了
要自己设置一个
sudo vim /etc/resolv.conf
写上一个公网的DNS,以下为浙江杭州电信DNS
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 202.101.172.35
nameserver 202.101.172.46
(注意:8.8.8.8是谷歌的DNS服务器,但是解析速度慢,还是找到一个国内的dns来用)
重启网卡
sudo /etc/init.d/networking restart