Ubuntu下配置固定IP地址,只需修改三个文件,以保障服务器重启后都能生效:
leekwen@leekwen:~$ cat /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 static
address 192.168.10.121
netmask 255.255.255.0
gateway 192.168.10.1
leekwen@leekwen:~$ cat /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 202.101.172.46
nameserver 202.101.172.35
leekwen@leekwen:~$ cat /etc/resolvconf/resolv.conf.d/base
nameserver 202.101.172.46
nameserver 202.101.172.35
将/etc/resolv.conf里的内容与/etc/resolvconf/resolv.conf.d/base保持一致。