Ubuntu 18.04设置静态IP

Ubuntu 18.04设置静态IP

Ubuntu 18.04的网络管理程序改成netplan了,所以配置方式也须要改喽!ubuntu

查看IP:vim

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地址、网关和域名服务器。app

而后,运行 netplan apply,能够当即生效的哦!若是是经过ssh远程访问的,须要使用新的IP从新链接。ssh

Ubuntu 16.04的设置

16.04的设置,是这样的:ide

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        #默认网关
相关文章
相关标签/搜索