本文内容源于netplan,并展示一个作者用到的配置。

1. Introduction

Netplan is a utility for easily configuring networking on a linux system. You simply create a YAML description of the required network interfaces and what each should be configured to do. From this description Netplan will generate all the necessary configuration for your chosen renderer tool.

2. How does it work?

Netplan reads network configuration from /etc/netplan/*.yaml which are written by administrators, installers, cloud image instantiations, or other OS deployments. During early boot, Netplan generates backend specific configuration files in /run to hand off control of devices to a particular networking daemon.

Netplan currently works with these supported renderers

3. How do I use it?

3.1 Configuration

Obviously, without configuration, netplan will not do anything. The most useful configuration snippet (to bring up things via dhcp) is as follows:

1
2
3
network:
version: 2
renderer: NetworkManager

This will make NetworkManager manage all devices (and by default, any ethernet device will come up with DHCP once carrier is detected).

Using networkd as a renderer does not let devices automatically come up using DHCP; each interface needs to be specified in a file in /etc/netplan for its configuration to be written and for it to be used in networkd.

3.1.1 One example

个人使用的一个配置: Configuring network bridges
https://github.com/liujunming/qemu_usage/tree/master/0002-set-net-on-kvm

1
2
3
4
5
6
7
8
9
10
network:
version: 2
renderer: networkd
ethernets:
eno1:
dhcp4: no
bridges:
br0:
dhcp4: yes
interfaces: [eno1]

eno1 should be you network interface name

netplan reference

如果想了解更多的配置,请参考https://netplan.io/examples/

3.2 Commands

Netplan uses a set of subcommands to drive its behavior:

  • 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.

参考资料:

  1. https://netplan.io/
  2. https://netplan.io/examples/