在Ubuntu 18.04 平臺上,其使用Netplan管理系統網路,Netplan 可以通過yaml 格式的組態檔(位于/etc/netplan),生成 NetworkManager 或 systemd-network 所需要的組態檔,用于配置網路,Ubuntu從17.10起,就使用netplan代替了之前的ifupdown的linux系統默認的網路管理工具,之前的網路配置,常編輯 /etc/network/interfaces檔案,并重啟網路服務;netplan的引入,使得網路配置更方便,
之前我曾在ubuntu配置靜態網路的博客中,提到netplan的使用:linux 靜態地址配置選項;Ubuntu 18.04 靜態網路地址配置;netplan命令; 今天我對netplan進行了系統了解,并在此博客上進行簡要記錄,方便我個人的記憶,
Netplan 官網:https://netplan.io/
發行版本對應的組態檔:
| INSTALL TYPE | RENDERER | FILE |
|---|---|---|
| Server ISO | systemd-networkd | /etc/netplan/01-netcfg.yaml |
| Cloud Image | systemd-networkd | /etc/netplan/50-cloud-init.yaml |
| Desktop ISO | NetworkManager | /etc/netplan/01-network-manager-all.yaml |
樣例配置:配置完成后,使用netplan apply 生效:
配置對應網卡,期望達到的狀態:
- enp3s0 setup with IPv4 DHCP
- enp4s0 setup with IPv4 static with custom MTU
- IPv6 static tied to a specific MAC address
- IPv4 and IPv6 DHCP with jumbo frames tied to a specific MAC address
ethernets: enp3s0: dhcp4: true enp4s0: addresses: - 192.168.0.10/24 gateway4: 192.168.0.1 mtu: 1480 nameservers: addresses: - 8.8.8.8 - 9.9.9.9 net1: addresses: - fe80::a00:10a/120 gateway6: fe80::a00:101 match: macaddress: 52:54:00:12:34:06 net2: dhcp4: true dhcp6: true match: macaddress: 52:54:00:12:34:07 mtu: 9000
實驗室其中一臺機器的配置:
# 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: eno1: dhcp4: false dhcp6: true addresses: [10.134.150.79/24] gateway4: 10.134.150.1 nameservers: addresses: [202.112.128.51, 202.112.128.50] #eno2: #addresses: [192.168.5.49/16] #dhcp4 : false #gateway4: 192.168.5.1 version: 2
當然,使用netplan還可以,通過yaml的語法撰寫組態檔,配置網卡的 Bonding、Bridges 和 Vlans;
Netplan的設計思路:具體可以參考netplan設計;

上圖展示了:netplan,netplan組態檔,后端網路渲染器之間的關系,netplan可以按照yaml組態檔,分別生成對應的網路后端渲染器的組態檔;網路渲染器通過netplan生成的檔案,來進行配置內核網路,
Netplan常用命令:
- netplan generate: Use /etc/netplan to generate the required configuration for the renderers.
- netplan apply: Apply all configuration for the renderers, restarting them as necessary.
- netplan try: Apply configuration and wait for user confirmation; will roll back if network is broken or no confirmation is given.
相關閱讀:
Ubuntu Bionic: Netplan
Netplan Source Code
Netplan Design Doc
Netplan Reference
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/244107.html
標籤:其他
