在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
实验室其中一台机器的配置:
代码语言:javascript复制# 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