Ubuntu通過Netplan配置網(wǎng)絡(luò)教程
Ubuntu 通過 Netplan 配置網(wǎng)絡(luò)教程
Ubuntu through Netplan configuration network tutorial
一、Netplan 配置流程
1. Netplan configuration process
1、Netplan默認(rèn)配置文件在/etc/netplan目錄下。您可以使用以下命令找到:
1. The default configuration file of Netplan is in the /etc/netplan directory. You can find it with the following command:
ls /etc/netplan/
就可以看到配置文件名稱。
You can see the configuration file name.
2、查看Netplan網(wǎng)絡(luò)配置文件的內(nèi)容,執(zhí)行以下命令:
2. View the contents of the Netplan network configuration file and execute the following command:
cat /etc/netplan/*.yaml
3、現(xiàn)在你需要在任何編輯器中打開配置文件: 由于我使用 vim 編輯器來編輯配置文件,所以我將運(yùn)行:
3. Now you need to open the configuration file in any editor: Since I use the vim editor to edit the configuration file, I will run:
vim /etc/netplan/*.yaml
根據(jù)您的網(wǎng)絡(luò)需要更新配置文件。對于靜態(tài) IP 尋址,添加 IP 地址、網(wǎng)關(guān)、DNS 信息,而對于動(dòng)態(tài) IP 尋址,無需添加此信息,因?yàn)樗鼘?DHCP 服務(wù)器獲取此信息。使用以下語法編輯配置文件。
Update the configuration file according to your network needs. For static IP addressing, add IP address, gateway, DNS information, and for dynamic IP addressing, there is no need to add this information because it will get this information from the DHCP server. Use the following syntax to edit the configuration file.
4、在應(yīng)用任何更改之前,我們將測試配置文件。
4. We will test the configuration file before applying any changes.
sudo netplan try
如果沒有問題,它將返回配置接受消息。如果配置文件未通過測試,它將恢復(fù)為以前的工作配置。
If there is no problem, it will return a configuration acceptance message. If the configuration file fails the test, it will revert to the previous working configuration.
5、運(yùn)行以下命令來應(yīng)用新配置:
5. Run the following command to apply the new configuration:
sudo netplan apply
6、成功應(yīng)用所有配置后,通過運(yùn)行以下命令重新啟動(dòng) Network-Manager 服務(wù):
6. After successfully applying all the configurations, restart the Network-Manager service by running the following command:
如果是桌面版:
If it is the desktop version:
sudo systemctl restart system-networkd
如果您使用的是 Ubuntu 服務(wù)器,請改用以下命令:
If you are using an Ubuntu server, use the following command instead:
sudo systemctl restart network-manager
7、驗(yàn)證 IP 地址
7. Verify the IP address
ip a
二、Netplan 配置文件詳解
Detailed explanation of Netplan configuration file
1、使用 DHCP:
1. Use DHCP:
network: version: 2 renderer: networkd ethernets: enp3s0: dhcp4: true
2、使用靜態(tài) IP:
2. Use static IP:
network: version: 2 renderer: networkd ethernets: enp3s0: addresses: - 10.0.0.10/8 gateway4: 10.0.0.1 nameservers: search: [mydomain, otherdomain] addresses: [10.0.0.5, 1.1.1.1]
3、多個(gè)網(wǎng)口 DHCP:
3. Multiple network ports DHCP:
network: version: 2 ethernets: enred: dhcp4: yes dhcp4-overrides: route-metric: 100 engreen: dhcp4: yes dhcp4-overrides: route-metric: 200
4、連接開放的 WiFi(無密碼):
4. Connect to open WiFi (without password):
network: version: 2 wifis: wl0: access-points: opennetwork: {} dhcp4: yes
5、連接 WPA 加密的 WiFi:
5. Connect to WPA encrypted WiFi:
network: version: 2 renderer: networkd wifis: wlp2s0b1: dhcp4: no dhcp6: no addresses: [10.0.0.10/8] gateway4: 10.0.0.1 nameservers: addresses: [10.0.0.5, 8.8.8.8] access-points: "network_ssid_name": password: "**********"
6、在單網(wǎng)卡上使用多個(gè) IP 地址(同一網(wǎng)段):
6. Use multiple IP addresses on a single network card (same network segment):
network: version: 2 renderer: networkd ethernets: enp3s0: addresses: - 10.0.0.10/8 - 10.0.0.10/8 gateway4: 10.0.0.1
7、在單網(wǎng)卡使用多個(gè)不同網(wǎng)段的 IP 地址:
7. Use multiple IP addresses of different network segments on a single network card:
network: version: 2 renderer: networkd ethernets: enp3s0: addresses: - 9.0.0.9/24 - 10.0.0.10/24 - 11.0.0.11/24 #gateway4: # unset, since we configure routes below routes: - to: 0.0.0.0/0 via: 9.0.0.1 metric: 100 - to: 0.0.0.0/0 via: 10.0.0.1 metric: 100 - to: 0.0.0.0/0 via: 11.0.0.1 metric: 100
以上就是Ubuntu通過Netplan配置網(wǎng)絡(luò)教程的詳細(xì)內(nèi)容,更多關(guān)于Ubuntu Netplan配置網(wǎng)絡(luò)的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
win10下VSCode+CMake+Clang+GCC環(huán)境搭建教程圖解
這篇文章主要介紹了win10下VSCode+CMake+Clang+GCC環(huán)境搭建,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10360提示服務(wù)器開啟了WebDAV的關(guān)閉方法
WebDAV (Web-based Distributed Authoring and Versioning) 一種基于 HTTP 1.1協(xié)議的通信協(xié)議.它擴(kuò)展了HTTP 1.1,在GET、POST、HEAD等幾個(gè)HTTP標(biāo)準(zhǔn)方法以外添加了一些新的方法2012-07-07基于postman實(shí)現(xiàn)http接口測試過程解析
這篇文章主要介紹了基于postman實(shí)現(xiàn)http接口測試過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11搭建hMailServer服務(wù)實(shí)現(xiàn)遠(yuǎn)程發(fā)送郵件的圖文教程
hMailServer是一個(gè)郵件服務(wù)器,通過它我們可以搭建自己的郵件服務(wù),本文主要介紹了搭建hMailServer服務(wù)實(shí)現(xiàn)遠(yuǎn)程發(fā)送郵件的圖文教程,具有一定的參考價(jià)值,感興趣的可以了解一下2023-08-08Windows Server 2016 上配置 APACHE+SSL+PHP+perl的教程詳解
這篇文章主要介紹了Windows Server 2016 上配置 APACHE+SSL+PHP+perl的教程詳解,需要的朋友可以參考下2017-01-01詳解如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件
這篇文章主要介紹了詳解如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11