step1:设定IP
vi /etc/network/interfaces
文件内容修改为:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.2
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
然后重启networking
/etc/init.d/networking restart
step2:设置DNS
vi /etc/resolv.conf
文件内容修改为:
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 8.8.8.8
不需要重启操作,这是修改后马上生效的
输入任意网址进行测试,如果连接成功则表示设置静态IP成功