Bobcares

How to set up static IP on Ubuntu configuration via Netplan

by | Nov 28, 2024

Learn how to set up static IP on Ubuntu configuration via Netplan. Our Server Management Support team is here to help you with your questions and concerns.

How to set up static IP on Ubuntu configuration via Netplan

How to set up static IP on Ubuntu configuration via NetplanDid you know that Netplan simplifies network configuration using YAML-based syntax?

It makes it easy to set up and modify network settings. Additionally, it lets us manage network interfaces through networkd (primarily for servers) or NetworkManager (for GUI-based systems).

Today, we are going to take a close look at Netplan’s structure and how to configure a static IP address on Ubuntu.

An Overview:

Understanding Netplan Configuration

Netplan’s configuration files are located in /etc/netplan/ and typically include:

  • 01-netcfg.yaml
  • 01-network-manager-all.yaml
  • 50-cloud-init.yaml

The default renderer for Netplan is specified as networkd or NetworkManager, depending on our Ubuntu setup. To confirm or generate a new Netplan configuration file:

sudo netplan generate

How to Choose Between DHCP and Static IP Address

Netplan lets us configure:

  • DHCP: Automatically assigns an IP address from the router.
  • Static IP: Manually assigns a fixed IP address to ensure consistent connectivity.

Benefits of Configuring a Static IP Address

Configuring a static IP address offers several advantages, especially in environments that require consistent network communication:

  • A static IP ensures that the device retains the same IP address, making it easier to locate within the network.
  • Systems with static IPs can be accessed more reliably for remote administration or SSH connections.
  • Static IPs let us set up custom DNS entries, streamlining name resolution in the network.
  • Dynamic IP addresses can lead to reassignment issues; static IPs eliminate this risk, ensuring uninterrupted network services.
  • Servers hosting websites, databases, or other critical applications benefit from a stable IP for consistent client connections.
  • Static IP addressing is particularly useful in enterprise setups, IoT deployments, and when integrating firewalls or VPNs that rely on consistent IPs for authentication.

Configuring a Static IP Address with Netplan

 

  1. First, identify the Netplan configuration file with this command:

    ls /etc/netplan/

  2. Then, open the configurations file:

    sudo nano /etc/netplan/CONFIGFILENAME

  3. Next, update the configuration file to include the following changes:
    • Disable DHCP:

      dhcp4: no

    • Assign a Static IP:

      addresses: [192.168.0.123/24]

      Replace 192.168.0.123 with the desired IP.

    • Set the Gateway:

      gateway4: 192.168.1.1

    • Define DNS Servers:

      nameservers:
      addresses: [1.1.1.1, 8.8.8.8]
      Example configuration:
      network:
      version: 2
      renderer: networkd
      ethernets:
      enp0s3:
      dhcp4: no
      addresses: [192.168.0.123/24]
      gateway4: 192.168.1.1
      nameservers:
      addresses: [1.1.1.1, 8.8.8.8]

After saving the changes, we can apply the new configuration with this command:

sudo netplan apply

In case the changes don’t take effect, reboot the system:

sudo reboot

Troubleshooting Common Issues

 

  • Ensure the router allows the specified static IP.
  • Check for typos or indentation issues in the YAML file.
  • Revert to DHCP by resetting “dhcp4: yes” in the configuration file and reapplying changes.

How to Automate Static IP Configuration for Multiple Systems

Managing static IP addresses across multiple systems can be simplified with automation:

  • Tools like Ansible, Puppet, or Chef can deploy static IP configurations to multiple devices with minimal effort.
  • Create reusable Netplan YAML templates that define static IP settings and apply them to multiple systems.
  • Write scripts to automate file generation and apply configurations using netplan apply on each target machine.
  • Automate both system installation and static IP configuration during the boot process using pre-seeded scripts.
  • Store Netplan configurations in version control systems (e.g., Git) to ensure consistency and rollback options.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Netplan’s YAML-based syntax simplifies static IP configuration on Ubuntu. By following these steps, we can set a static IP address to ensure consistent network connectivity. With its flexibility and integration with modern Ubuntu systems, Netplan is a powerful tool for network management.

In brief, our Support Experts demonstrated how to set up static IP on Ubuntu configuration via Netplan

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.