如何給 Ubuntu 18 04 配置靜態IP

2021-10-24 14:54:43 字數 1956 閱讀 7817

總結介紹如何給ubuntu 18.04配置靜態ip

在 ubuntu 18.04 lts 中配置 ip 位址的方法和以往使用的配置方法有很大的不同。和舊版本的不同之處在於,ubuntu 18.04 使用 netplan 來配置 ip 位址,netplan 是乙個新的命令列網路配置工具。其實在 ubuntu 17.10 的時候 ubuntu 開發者就已經介紹過 netplan 了。接下來要介紹的新的 ip 配置方法不會再用到 /etc/network/inte***ces 這個檔案,取而代之的是乙個 yaml 檔案。預設的 netplan 配置檔案一般在 /etc/netplan 目錄下。

在這篇教程中,我們會去學習在 ubuntu 18.04 lts 的最小化伺服器中配置靜態 ip 和動態 ip 。

**如下(示例):

root@server:

/home/usr# cat /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:

network:

ethernets:

enp3s0:

dhcp4: true

version:

2root@server:

/home/usr#

可以看出,預設是dhcp方式

**如下(示例):

root@server:

/home/usr# cat /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:

network:

ethernets:

enp3s0:

addresses:

[192.168

.***.xx/24]

gateway4:

192.168

.***.

1 dhcp4: no

nameservers:

addresses:

[192.168

.***.xx,

8.8.8.8]

optional: true

version:

2root@server:

/home/usr#

注意:編輯裡面的內容時縮排需要用空格,不用用tab鍵,否則修改無效。

**如下(示例):

如果在應用配置的時候有出現問題的話,可以通過如下的命令來檢視剛才配置的內容出了什麼問題。

可以看到具體的錯誤資訊,便於診斷。

以上就是今天要講的內容,本文僅僅簡單介紹了ubuntu 18.04的靜態配置ip的方法,希望對你有幫助。

Ubuntu18 04配置gitlab伺服器筆記

參考 sudo apt get install curl openssh server ca certificates postfix執行完成後,出現郵件配置,選擇internet那一項 不帶smarthost的 curl 2 dev null sudo apt key add dev nullcu...

ubuntu1804修改網路配置

1.使用netplan修改yaml檔案 sudo vim etc netplan 50 cloud init.yaml 1.配置檔案如下network ethernets ens160 addresses 210.72.92.28 24 ip及掩碼 gateway4 210.72.92.254 閘道...

ubuntu18 04配置ssh服務

1.安裝ssh sudo apt get install openssh server sudo chy 的密碼 正在讀取軟體包列表.完成 正在分析軟體包的依賴關係樹 正在讀取狀態資訊.完成 將會同時安裝下列軟體 ncurses term openssh sftp server ssh import...