打开虚拟机编辑/etc/network/interfaces文件
root@swift:/home/swift# 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).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33#16.04的命名为ens33不是eth0
iface ens33 inet static#static表示静态
address 192.168.110.111 #IP地址
netmask 255.255.255.0 #子网掩码
gateway 192.168.110.2 #网关
dns-nameservers 61.139.2.69 #DNS
root@swift:/home/swift# /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.
root@swift:/home/swift#ping -c 4 www.baidu.com
PING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.
64 bytes from 180.97.33.108: icmp_seq=1 ttl=128 time=51.1 ms
64 bytes from 180.97.33.108: icmp_seq=2 ttl=128 time=48.9 ms
64 bytes from 180.97.33.108: icmp_seq=3 ttl=128 time=49.4 ms
64 bytes from 180.97.33.108: icmp_seq=4 ttl=128 time=51.3 ms
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 48.966/50.215/51.304/1.041 ms
root@swift:/home/swift#
到此配置完成可以连接网络进行安装和更新了。
如果重启服务后还是不能连接网络
编辑/etc/resolvconf/resolv.conf.d/目录下的base head两个文件
在末尾追加DNS
例如:
nameserver 61.139.2.69#使用当地网络服务商提供的DNS
修改后重启网络服务或重启虚拟机(reboot、init 6、shutdown -r now等多种方法)。