Ubuntu 18.04设置静态IP

原创
2018/08/06 20:25
阅读数 6.7W

Ubuntu 18.04设置静态IP

Ubuntu 18.04的网络管理程序改为netplan了,因此配置方式也需要改喽!

查看IP:

ifconfig -a

查看当前的配置文件:

cat /etc/netplan/50-cloud-init.yaml

如果要使用静态IP的话,需要修改为下面的样子:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: [192.168.199.101/24, ]
            dhcp4: no
            dhcp6: no
            gateway4:  192.168.199.1
            nameservers:
                addresses: [8.8.8.8, 9.9.9.9]
    version: 2

其中,把dhcp4/dhcp6都设为no予以关闭,设上自己的ip地址、网关和域名服务器。

然后,运行 netplan apply,可以立即生效的哦!如果是通过ssh远程访问的,需要使用新的IP重新连接。

Ubuntu 16.04的设置

16.04的设置,是这样的:

ubuntu 16.04下静态IP地址的设置

找到文件并作如下修改:
sudo vim /etc/network/interfaces

#虚拟机的网络界面一般是enpxxx,要改成自己的。

auto lo
iface lo inet loopback
auto enp2s0
iface enp2s0 inet static
address 192.168.20.1
netmask 255.255.255.0
gateway 192.168.20.254

dns-nameserver 8.8.8.8


sudo /etc/init.d/networking restart

#直接插网线的网络界面一般是eth0,要改成自己的。
auto eth0                  #设置自动启动eth0接口
iface eth0 inet static     #配置静态IP
address 192.168.11.88      #IP地址
netmask 255.255.255.0      #子网掩码
gateway 192.168.11.1        #默认网关

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部