1.设置ip地址
vi /etc/network/interface # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto ens32 iface ens32 inet static address 192.168.159.130 netmask 255.255.255.0 gateway 192.168.2.1
2.设置dns
vi /etc/resolvconf/resolv.conf.d/base nameserver 8.8.8.8 nameserver 8.8.4.4
3.刷新配置文件
resolvconf -u
4.重启网络服务
/etc/init.d/networking restart
如果上述命令重启网卡失败,可以手动关闭网卡,再打开网卡,这是ip已经改过来了,变成你设置的固定的ip了