Network Configuration with netplan - GitMasterNikanjam/C_WiKi GitHub Wiki

Netplan is a simple and modern network configuration tool for Linux systems that use YAML to define network configurations. It is commonly used in Ubuntu and other Debian-based distributions. Netplan works by converting the YAML configurations into backend-specific configurations for tools like systemd-networkd or NetworkManager.

Basic Concepts of Netplan

  1. YAML Configuration Files: Netplan uses YAML files stored in the /etc/netplan/ directory. Files typically have names like 01-netcfg.yaml or 50-cloud-init.yaml.

  2. Backends:

    • systemd-networkd: Lightweight and suitable for servers.
    • NetworkManager: More feature-rich, ideal for desktops and laptops.
  3. Key Parameters:

    • network: Root section.
    • version: Netplan configuration file version (e.g., 2).
    • renderer: Specifies the backend (e.g., NetworkManager or networkd).
    • ethernets, wifis, bridges, bonds, vlans: Define specific types of interfaces.

Common Configuration Examples

1. Static IP Address

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: false
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

2. Dynamic IP Address (DHCP)

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: true

3. Bridged Interface

network:
  version: 2
  renderer: networkd
  bridges:
    br0:
      dhcp4: true
      interfaces:
        - enp0s3

4. VLAN Configuration

network:
  version: 2
  vlans:
    vlan100:
      id: 100
      link: enp0s3
      addresses:
        - 192.168.100.1/24

Applying Netplan Configurations

  1. Save the configuration in /etc/netplan/ (e.g., 01-netcfg.yaml).

  2. Apply the configuration:

    sudo netplan apply
    
  3. Debug configurations:

    sudo netplan try
    

Troubleshooting

  1. View logs:

    journalctl -u systemd-networkd
    

    or

    journalctl -u NetworkManager
    
  2. Test and validate YAML syntax:

    sudo netplan generate
    
  3. Reverting changes: If you break the configuration, boot into recovery mode, or use the netplan try command to test configurations before applying them.

Key Features

  • Declarative YAML-based configuration.
  • Integration with both systemd-networkd and NetworkManager.
  • Support for modern networking features like VLANs, bridges, and bonds.
  • Suitable for cloud-init and container environments.