Detailed Explanation of Ubuntu Netplan
1. Overview
Netplan is a new network configuration tool introduced in Ubuntu starting from version 17.10, designed to simplify and unify the network configuration process. It defines network interface settings through YAML configuration files and supports <span>NetworkManager</span>
and <span>systemd-networkd</span>
as backends.
Advantages
-
Readable and writable YAML format.
-
Unified configuration method.
-
Supports wired, wireless networks, as well as advanced features like VLAN and Bonding.
-
Applicable to both server and desktop systems.
Related Tools
-
<span>netplan apply</span>
: Apply configuration. -
<span>netplan generate</span>
: Generate configuration files. -
<span>netplan try</span>
: Test configuration with a 120-second rollback mechanism. -
<span>netplan ip</span>
: Display IP address (similar to<span>ip a</span>
).
2. Netplan Configuration File Location and Format
Configuration File Location
Netplan configuration files are usually stored in:
/etc/netplan/
with a suffix of <span>.yaml</span>
, typically named <span>01-netcfg.yaml</span>
or other custom names.
Configuration File Structure
An example of a simple Netplan configuration file:
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: true
Key Points of Configuration File
-
<span>version</span>
: The current version is<span>2</span>
. -
<span>renderer</span>
: Defines the backend used, usually<span>networkd</span>
or<span>NetworkManager</span>
. -
<span>ethernets</span>
: Defines Ethernet interfaces. -
<span>dhcp4</span>
: Whether to enable IPv4 DHCP.
3. Common Configuration Examples
3.1 Static IP Configuration
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: false addresses: [192.168.1.10/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4]
3.2 DHCP Configuration
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: true
3.3 VLAN Configuration
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: false vlans: vlan10: id: 10 link: enp0s3 addresses: [192.168.10.1/24]
4. Common Commands
-
<span>sudo netplan apply</span>
: Apply configuration. -
<span>sudo netplan generate</span>
: Generate configuration. -
<span>sudo netplan try</span>
: Test configuration, allows rollback. -
<span>sudo netplan ip</span>
: Display IP address. -
<span>sudo netplan --debug</span>
: Debug mode, shows detailed information.
5. Comparison with Other Tools
Tool | Configuration File Format | Supported Backends | Applicable Scenarios |
---|---|---|---|
Netplan | YAML | <span>networkd</span> , <span>NetworkManager</span> |
Ubuntu server and desktop systems |
NetworkManager | Configuration file or nmcli | <span>NetworkManager</span> |
Desktop systems, Wi-Fi network management |
ifupdown | <span>/etc/network/interfaces</span> |
Kernel Network Stack | Traditional Linux servers |
6. Conclusion
Netplan provides a unified network configuration method suitable for network management in modern Linux systems. For desktop systems, it can be used in conjunction with <span>NetworkManager</span>
; for servers, it typically uses <span>systemd-networkd</span>
. Understanding the configuration method of Netplan is crucial for network management in modern Ubuntu systems.