Ubuntu 18.04设置静态IP

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

查看IP:

ifconfig -a

查看当前的配置文件:

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

如果要使用静态IP的话,需要使用 vi /etc/netplan/50-cloud-init.yaml ,将该配置文件修改为下面的样子:

# 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.85.154/24, ]
            dhcp4: no
            dhcp6: no
            gateway4:  192.168.85.1
            nameservers:
                addresses: [8.8.8.8, 9.9.9.9]
    version: 2

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

此处静态IP为ifconfig 获取的内网地址,而不是自己物理机电脑的IP地址(不能自己随便写)。

然后,运行 netplan apply,即可立即生效!

如果是通过ssh远程访问的,需要使用新的IP重新连接!

发布了79 篇原创文章 · 获赞 55 · 访问量 32万+

猜你喜欢

转载自blog.csdn.net/qq_33833327/article/details/103459232