1、修改文件,添加IP地址
sudo vim /etc/network/interfaces
修改如下:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.160 //IP地址
netmask 255.255.255.0 //子网掩码
gateway 192.168.1.1 //网关
保存退出。
2、修改dns解析
sudo vim /etc/resolv.conf
修改如下:
# 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 192.168.1.1 //DNS地址
保存退出。
注意:重启Ubuntu后发现又不能上网了,问题出在/etc/resolv.conf。重启后,此文件配置的dns又被自动修改为默认值。所以需要永久性修改DNS。
方法如下:
vim /etc/resolvconf/resolv.conf.d/base
nameserver 192.168.1.1
3、重启networking服务使其生效:
/etc/init.d/networking restart