1. 先设置IP,网关,掩码
vim /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.123
gateway 192.168.1.1
netmask 255.255.255.0
2. 再设置DNS服务器地址
vim /etc/resolvconf/resolv.conf.d/base (该文件默认是空的)
nameserver 8.8.8.8
3. 执行一下这条命令
resolvconf -u
会更新内容到/etc/resolv.conf
4. 重启网络
/etc/init.d/networking restart
5. 验证
ping www.baidu.com
可以ping通外网