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        #默認網關
相關文章
相關標籤/搜索