Ubuntu 网络配置
1. 网络配置文件:/etc/network/interfaces
如果通过DHCP来获取IP地址的,默认interfaces文件看起来是:
auto lo
iface lo inet loopback
如果要手工指定IP地址,则要把DHCP关键字改为scatic:
auto lo
iface lo inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
配置好后,重启服务:
sudo /etc/init.d/networking restart
2. 域名服务器配置文件:/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 127.0.0.1
如果有要修改DNS服务器地址,则可以把上面的IP地址替换掉
3. /etc/hosts 文件
默认看上去像:
127.0.0.1 localhost
127.0.1.1 jeff-F6Ve
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
默认情况下,进行域名解析时,系统会先查找/etc/hosts文件,再去查询DNS服务器,如果想更改这个顺序,可以修改/etc/nsswitch.conf 文件中 hosts一行的顺序。