Configuring network settings in Ubuntu 24.04 requires a good understanding of Netplan, the default network configuration tool used in modern Ubuntu distributions. Whether you’re setting up a home server, configuring a production environment, or simply wanting to customize your desktop’s network settings, this comprehensive guide will walk you through the entire process.

Table of Contents

    Ubuntu 24.04, the latest Long-Term Support release, continues to rely on Netplan for network configuration management. Netplan simplifies the process of setting up network interfaces by using YAML configuration files, making it more straightforward than traditional methods. Proper network configuration is essential for system administrators and users alike, as it ensures reliable connectivity and accessibility of network services.

    In this guide, we’ll explore everything from basic DHCP setup to advanced configurations like network bonding, static IP addressing, and multi-interface routing. By the end, you’ll have the knowledge to configure your Ubuntu 24.04 system’s network to meet your specific requirements, whether for a desktop workstation or a server environment.

    Understanding Netplan in Ubuntu 24.04

    Netplan was introduced to Ubuntu to unify network configuration across different environments. It acts as an abstraction layer that generates the appropriate configuration for either NetworkManager (primarily used in desktop environments) or systemd-networkd (commonly used in server installations).

    How Netplan Works

    Netplan uses YAML files located in the /etc/netplan/ directory to define network configurations. These configuration files have a .yaml extension and follow a specific naming convention, typically starting with a number (like 01-netcfg.yaml) to indicate the order of processing.

    The basic structure of a Netplan configuration involves:

    • Specifying the network version (typically version 2)
    • Choosing a renderer (networkd or NetworkManager)
    • Defining configuration for various network interface types

    Netplan processes these files and generates the appropriate configuration for the chosen backend. This approach provides several advantages:

    • Consistent configuration across different Ubuntu versions
    • Simplified syntax compared to direct editing of network configuration files
    • Easy rollback of configuration changes
    • Support for complex network setups in a readable format

    The configuration files are typically processed in alphanumeric order, so files with lower numbers are applied first. This allows administrators to override specific settings by creating files with higher numbers.

    Network Interface Identification

    Before configuring your network, you need to identify the network interfaces available on your system. Ubuntu 24.04 uses predictable network interface naming, which provides consistent names regardless of hardware changes or system reboots.

    To list all available network interfaces, use the following command:

    ip a

    Alternatively, if NetworkManager is installed, you can use:

    nmcli d

    The output will display interface names like enp0s3 or wlp2s0 rather than traditional names like eth0 or wlan0. This naming convention follows a specific pattern:

    • en – Ethernet
    • wl – Wireless LAN
    • p0s3 – PCI bus location identifier

    Record the interface name you want to configure, as you’ll need it for the Netplan configuration file.

    Basics of YAML Syntax for Netplan

    YAML (YAML Ain’t Markup Language) is a human-readable data serialization format used by Netplan for configuration files. Understanding YAML syntax is essential for creating valid Netplan configurations.

    Key YAML Concepts for Netplan:

    1. Indentation matters – YAML uses spaces (not tabs) for indentation, typically 2 or 4 spaces per level
    2. Key-value pairs are separated by a colon and space (key: value)
    3. Lists are denoted by a dash and space (- item)
    4. Comments begin with the hash symbol (# comment)

    Here’s a simple example of Netplan YAML syntax:

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

    Common YAML errors in Netplan configurations include:

    • Using tabs instead of spaces for indentation
    • Inconsistent indentation levels
    • Missing spaces after colons
    • Incorrect nesting of configuration items

    Always verify your YAML syntax before applying changes to avoid network configuration issues.

    Configuring DHCP in Ubuntu 24.04

    Dynamic Host Configuration Protocol (DHCP) allows your system to automatically obtain network configuration from a DHCP server. This is the default and simplest configuration method for most environments.

    Step 1: Create or Edit the Netplan Configuration File

    sudo nano /etc/netplan/01-netcfg.yaml

    Step 2: Add DHCP Configuration

    For a basic DHCP setup, add the following configuration:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:  # Replace with your interface name
          dhcp4: true
          dhcp6: true  # Enable if you need IPv6 configuration

    Step 3: Apply the Configuration

    sudo netplan apply

    DHCP Configuration Options

    You can customize your DHCP configuration with additional parameters:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: true
          dhcp4-overrides:
            use-hostname: true
            send-hostname: true
            hostname: myserver
          dhcp6: true
          dhcp6-overrides:
            use-hostname: true

    DHCP configuration is ideal for desktop systems or environments where centralized network management is in place. However, for servers and devices that need to maintain a consistent network presence, static IP configuration is recommended.

    Setting Up a Static IP Address

    Static IP addressing ensures your system maintains the same IP address across reboots, which is crucial for servers and network infrastructure devices.

    Step 1: Gather Network Information

    Before configuring a static IP, collect the following information:

    • IP address you want to assign
    • Subnet mask (CIDR notation)
    • Default gateway IP
    • DNS server addresses

    Step 2: Create or Edit the Netplan Configuration File

    sudo nano /etc/netplan/01-netcfg.yaml

    Step 3: Configure Static IP Settings

    Add the following configuration, replacing the values with your network information:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:  # Replace with your interface name
          dhcp4: no
          addresses:
            - 192.168.1.10/24  # Replace with your desired IP/subnet
          routes:
            - to: default
              via: 192.168.1.1  # Replace with your gateway IP
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]  # Replace with your DNS servers

    Step 4: Apply the Configuration

    sudo netplan apply

    Step 5: Verify the Configuration

    ip a

    This command will show your network interface with the newly assigned static IP address.

    Additional Static IP Options

    For more control, you can add options like:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: no
          addresses:
            - 192.168.1.10/24
          routes:
            - to: default
              via: 192.168.1.1
              metric: 100  # Lower metrics are preferred
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]
            search: [example.com, local.lan]  # Domain search suffixes
          optional: true  # System will boot without this interface

    Static IP configuration provides stability but requires manual updates if network details change. Ensure your static IP doesn’t conflict with other devices on your network.

    Configuring DNS Settings

    Domain Name System (DNS) is essential for resolving hostnames to IP addresses. In Ubuntu 24.04, DNS settings are configured in the Netplan file and managed by systemd-resolved.

    Basic DNS Configuration

    To configure DNS servers, add them to your Netplan configuration:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: true  # or false for static IP
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]  # Google DNS servers

    Advanced DNS Options

    For more detailed DNS configuration:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: true
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]
            search: [example.com, internal.net]  # Search domains

    Verifying DNS Configuration

    After applying your configuration, verify DNS resolution:

    resolvectl status

    Or test DNS resolution with a simple ping:

    ping -c 3 www.google.com

    If you encounter DNS issues, ensure systemd-resolved is running properly:

    sudo systemctl status systemd-resolved

    Proper DNS configuration ensures your system can resolve domain names correctly, which is critical for most network operations.

    Implementing Multiple IP Addresses

    In some scenarios, you may need to assign multiple IP addresses to a single network interface. Netplan makes this straightforward with its list syntax.

    Configuring Multiple IP Addresses

    Edit your Netplan configuration file:

    sudo nano /etc/netplan/01-netcfg.yaml

    Add multiple addresses in the configuration:

    network:
      version: 2
      renderer: networkd
      ethernets:
        ens192:  # Replace with your interface name
          addresses:
            - 192.168.1.10/24
            - 192.168.1.11/24
            - 10.0.0.10/24
          routes:
            - to: default
              via: 192.168.1.1
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]

    Apply the configuration:

    sudo netplan apply

    Verifying Multiple IP Configuration

    To confirm that all IP addresses are correctly assigned:

    ip addr show ens192

    Multiple IP configurations are useful for:

    • Hosting multiple websites or services
    • Creating backup or failover connections
    • Connecting to different network segments
    • Load balancing across different subnets

    This flexibility allows you to adapt your network configuration to complex requirements without additional hardware.

    Advanced Routing Configuration

    Routing determines how network packets travel from source to destination. Ubuntu 24.04 allows for sophisticated routing configurations through Netplan.

    Basic Default Route

    A default route sends all traffic not matching specific routes to a designated gateway:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          addresses: [192.168.1.10/24]
          routes:
            - to: default
              via: 192.168.1.1

    Multiple Default Routes with Metrics

    For failover or load-balancing scenarios, you can define multiple default routes with different metrics:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          addresses: [192.168.1.10/24]
          routes:
            - to: default
              via: 192.168.1.1
              metric: 100  # Primary route (lower metric)
        enp0s8:
          addresses: [10.0.0.10/24]
          routes:
            - to: default
              via: 10.0.0.1
              metric: 200  # Backup route (higher metric)

    Static Routes to Specific Networks

    You can also define routes to specific destinations:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          addresses: [192.168.1.10/24]
          routes:
            - to: default
              via: 192.168.1.1
            - to: 10.0.0.0/24
              via: 192.168.1.254
            - to: 172.16.0.0/16
              via: 192.168.1.253

    Advanced routing configurations allow for traffic engineering and network isolation, which are essential in complex enterprise environments or multi-homed systems.

    Network Bonding and Aggregation

    Network bonding combines multiple network interfaces into a single logical interface for increased bandwidth or redundancy.

    Types of Bonding Modes:

    • Mode 0 (balance-rr): Round-robin load balancing
    • Mode 1 (active-backup): Failover protection
    • Mode 2 (balance-xor): XOR-based load balancing
    • Mode 4 (802.3ad): IEEE 802.3ad dynamic link aggregation
    • Mode 5 (balance-tlb): Adaptive transmit load balancing
    • Mode 6 (balance-alb): Adaptive load balancing

    Configuring Network Bonding

    To create a bond interface with two physical interfaces:

    network:
      version: 2
      renderer: networkd
      bonds:
        bond0:
          interfaces: [enp0s3, enp0s8]
          parameters:
            mode: active-backup
            primary: enp0s3
            mii-monitor-interval: 100
          addresses: [192.168.1.10/24]
          routes:
            - to: default
              via: 192.168.1.1
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]
      ethernets:
        enp0s3: {}
        enp0s8: {}

    After applying this configuration, you’ll have a single logical interface (bond0) that provides either increased bandwidth or redundancy, depending on the bonding mode chosen.

    Network bonding is particularly useful for servers that require high availability or increased network throughput.

    VLAN Configuration

    Virtual LANs (VLANs) allow you to create multiple logical networks on a single physical interface, helping with network segmentation and security.

    Basic VLAN Configuration

    To configure a VLAN interface:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3: {}
      vlans:
        vlan10:
          id: 10
          link: enp0s3
          addresses: [192.168.10.10/24]
        vlan20:
          id: 20
          link: enp0s3
          addresses: [192.168.20.10/24]

    This configuration creates two VLAN interfaces (vlan10 and vlan20) on the physical interface enp0s3.

    VLANs are commonly used in enterprise environments to separate different departments, isolate sensitive systems, or implement quality of service (QoS) policies.

    Applying and Testing Network Changes

    After creating or modifying Netplan configuration files, you need to apply the changes and verify that they work as expected.

    Safely Applying Netplan Changes

    Before applying changes, it’s a good practice to test your configuration:

    sudo netplan try

    This command will apply the configuration temporarily and prompt you to accept or reject the changes within 120 seconds. If you don’t respond or if the configuration causes a loss of connectivity, the system will revert to the previous configuration.

    To apply changes permanently:

    sudo netplan apply

    Creating Backup Configurations

    Always back up your working network configuration before making changes:

    sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.backup

    Verifying Network Changes

    After applying changes, verify your network configuration:

    ip a                  # Check interface status and IP addresses
    ip route              # Verify routing table
    ping -c 3 8.8.8.8     # Test Internet connectivity
    ping -c 3 google.com  # Test DNS resolution

    For more detailed network information:

    networkctl status     # Check network interface status
    resolvectl status     # Verify DNS resolver configuration

    Proper testing and verification ensure that your network changes don’t disrupt connectivity and work as intended.

    Network Configuration via GUI

    While command-line configuration provides the most flexibility, Ubuntu Desktop users can also configure network settings through the graphical interface.

    Ubuntu Desktop Network Settings

    1. Click on the network icon in the top-right corner of the screen
    2. Select “Settings” or “Edit Connections” depending on your desktop environment
    3. Choose the network interface you want to configure
    4. Navigate to the “IPv4” or “IPv6” tab to adjust settings
    5. Apply the changes and enter your password if prompted

    The GUI provides access to common settings like IP address, gateway, DNS servers, and connection methods. However, some advanced options may only be available through Netplan configuration files.

    The main difference between GUI and command-line configuration is that GUI changes typically modify NetworkManager settings, while command-line changes work with Netplan and systemd-networkd.

    Network Troubleshooting

    Even with careful configuration, network issues can arise. Having a systematic approach to troubleshooting can help resolve problems quickly.

    Common Troubleshooting Commands

    ping -c 3 8.8.8.8         # Test basic connectivity
    ip addr show              # Check interface status and IP addresses
    ip route                  # Verify routing table
    nslookup google.com       # Test DNS resolution
    traceroute google.com     # Trace network path
    netstat -tuln             # Show listening ports
    sudo systemctl status NetworkManager    # Check NetworkManager status
    journalctl -u NetworkManager            # View NetworkManager logs

    Common Network Issues and Solutions

    1. No connectivity after configuration changes:
      • Check for syntax errors in your Netplan file
      • Verify interface names are correct
      • Ensure gateway IP is accessible
      • Restore from a backup configuration
    2. DNS resolution issues:
      • Verify nameserver entries in your Netplan configuration
      • Check systemd-resolved status
      • Examine /etc/resolv.conf
      • Test with alternative DNS servers
    3. Intermittent connectivity:
      • Check physical connections and network hardware
      • Examine system logs for errors
      • Monitor network interface with watch -n 1 ip a
      • Test with different connection methods

    Systematic troubleshooting helps identify and resolve issues more efficiently. Start with basic connectivity tests and work up to more complex checks as needed.

    Security Considerations

    Proper network security is essential for protecting your Ubuntu 24.04 system. Here are some important security considerations:

    Secure Netplan Configuration Files

    Restrict access to Netplan configuration files:

    sudo chmod 600 /etc/netplan/01-netcfg.yaml
    sudo chown root:root /etc/netplan/01-netcfg.yaml

    Firewall Configuration

    Ubuntu includes Uncomplicated Firewall (UFW) for basic firewall protection:

    sudo ufw enable                # Enable the firewall
    sudo ufw allow ssh             # Allow SSH connections
    sudo ufw allow 80/tcp          # Allow HTTP traffic
    sudo ufw status                # Check firewall status

    Network Interface Hardening

    Disable unnecessary network services and features:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: no
          addresses: [192.168.1.10/24]
          routes:
            - to: default
              via: 192.168.1.1
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]
          ipv6-privacy: true       # Use privacy extensions for IPv6

    Regular Security Updates

    Keep your system updated with the latest security patches:

    sudo apt update
    sudo apt upgrade

    Implementing these security measures helps protect your system from network-based attacks and unauthorized access.

    Ref. https://idroot.us/ubuntu-24-04-network-configuration/

    Leave a Reply

    AI assistant