Ubuntu如果需要使用静态网络地址,需要手工对网络进行配置,包括网络地址配置和DNS配置(上外网需要)
网络地址配置比较简单
输入sudo 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).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
#这是默认的动态获取方式
#iface eth0 inet dhcp
#设置为静态配置方式
iface eth0 inet static
#IP地址
address 192.168.1.222
#掩码
netmask 255.255.255.0
#网关
gateway 192.168.1.1
完成后执行 sudo /etc/init.d/networking restart 重置网络,新IP生效
DNS配置费了比较多的周折,网络上的信息一般是让编辑/etc/resolv.conf文件。编辑了后的确可以用了,但是这个文件是机器启动的时候动态生成的,DHCP的时候能够自动写入正确的值,但是非DHCP模式的时候,这个文件重启后就变空了。最终发现,要让他重启后写入正确的值,则需要编辑/etc/resolvconf/resolv.conf.d/base文件
输入sudo vi /etc/resolvconf/resolv.conf.d/base 输入
nameserver 202.106.0.20
nameserver 202.106.196.115
如果要马上生效则执行命令
resolvconf -u
查看/etc/resolv.conf 发现上述两行写到文件中了,重启后同样有效。