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        #默認網關
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章