Ubuntu server 设置静态IP

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/descreekert/article/details/50723768

需求:在VirtualBox里装了Ubuntu server 14的镜像做本地服务器,对外提供ssh访问,在内网访问时需要使用IP,但是默认的IP都是dhcp模式自动获取的,每次重启虚拟机,IP都会变化,如何设置为静态IP?

方法:具体步骤如下
1.编辑 /etc/network/interfaces 文件, 在其中设置

# The primary network interface
auto eth0 #希望设置静态ip的网卡,默认是eth0
#iface eth0 inet dhcp --将此句注释掉,添加下面的配置
iface eth0 inet static #静态ip
address 192.168.1.101 #希望设置的ip地址
netmask 255.255.255.0 #子网掩码
gateway 192.168.1.1 #网关
dns-nameservers 8.8.8.8 8.8.4.4 #这句是用来设置dns的,可选

2.重启网络服务,使配置生效

sudo /etc/init.d/networking restart

猜你喜欢

转载自blog.csdn.net/descreekert/article/details/50723768