Ubuntu 18.04设置静态IP

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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值