Ubuntu 虚拟机设置静态IP地址
第一步,填写IP地址,网关地址,子网掩码找到目录/etc/network/修改其下的interfaces文件sudovi interfaces配置过后的文件内容为(红色标记为更改添加内容):# This file describes the network interfaces available on your system# and how to acti
注:以下是基于桥接模式的配置
第一步,填写IP地址,网关地址,子网掩码
找到目录/etc/network/修改其下的interfaces文件
sudo vi 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 dhcp (把自动获取Ip注释掉)
iface eth0 inet static (静态获取IP)
address 192.168.0.6 (IP地址)
netmask 255.255.255.0 (子网掩码)
gateway 192.168.0.1 (网关地址)
注意对比,配置完成之后,重启网络:
/etc/init.d/networking restart
第二部,配置DNS
打开/etc/resolv.conf文件
sudo vi /etc/resolv.conf
设置如下
nameserver 192.168.xx.xx(宿主机的DNS地址)
保存,重启网络
注:此种方式不行,因为之后重启机器,会把resolv.conf内容擦除,导致设置失败,所以不用进行第二步设置,直接进行第三步设置
第三部,设置DNS
找到目录/etc/resolvconf/resolv.conf.d/下的head文件
打开修改 sudo vi /etc/resolvconf/resolv.conf.d/head
内容如下
nameserver 192.168.xx.xx(宿主机的DNS地址)
配置完成之后,重启网络:
/etc/init.d/networking restart
注:如果重启网络无效,请重启机器
更多推荐
所有评论(0)