Static IP Configuration in Ubuntu using Netplan

Netplan is a network setup tool released in Ubuntu 17.10 that allows users to customize network settings such as IP addresses, gateways, and DNS servers in a YAML-based configuration file. Users may quickly set up and maintain their network connections with Netplan, including the assignment of static IP addresses. This can be especially helpful when a device needs a constant IP address to connect to other networked devices or to offer services like file sharing or web hosting. In this situation, setting up a static IP address in Ubuntu using Netplan can offer a dependable and effective network connection.

To configure IP address in Ubuntu using netplan, follow below simple steps:

NOTE: This steps were tested on Ubuntu 20.04 and Ubuntu 22.04, they can also work on Ubuntu 18.04

  1. Open the terminal
  2. Navigate to the Netplan configuration directory by entering the command below:
     cd /etc/netplan
  3. Check the current configuration file by entering the command below:
    ls
  4. Create a new configuration file or edit the available configuration file by entering the command below:
    sudo nano 01-netcfg.yaml
  5. Within the configuration file, add/edit the following lines:
  6.         
              network:
                version: 2
                renderer: networkd
                ethernets:
                  eth0:
                    dhcp4: no
                    addresses: [STATIC_IP/24]
                    routes:
                        - to: default
                         via: GATEWAY_IP
                    nameservers:
                      addresses: [DNS_SERVER_1, DNS_SERVER_2]
            
          
  7. Replace STATIC_IP with the static IP address you want to use, GATEWAY_IP with the IP address of your network gateway, and DNS_SERVER_1 and DNS_SERVER_2 with the IP addresses of your DNS servers. Note that you should replace eth0 with the name of the network interface you want to configure (you can find the name by using the ip a command).
    Below is a an example of a fully configured interface:
            
    network:
      version: 2
      renderer: networkd
      ethernets:
        enp3s0:
          addresses:
            - 192.168.0.201/24
          routes:
            - to: default
              via: 192.168.0.1
          nameservers:
              addresses: [192.168.0.1, 8.8.8.8]
    

  8. Save the changes to the configuration file by pressing Ctrl + X, then Y, then Enter.
  9. Apply the changes by entering the command below:
    sudo netplan apply

    .

Static IP Configuration in Ubuntu by editing /etc/network/interfaces

Prior to Ubuntu 17.10, the usual approach for managing network interfaces was to configure a static IP address by modifying the /etc/network/interfaces file. Hence, modifying the /etc/network/interfaces file is still the suggested method for creating a static IP address if you are using Ubuntu 16 or a previous version. With the help of this technique, you may easily and successfully set up a dependable network connection with a constant IP address, gateway, and DNS settings.

Follow below simple steps to achieve this:

  1. Open the terminal and enter the command below to open the network interfaces file.
  2. $ sudo nano /etc/network/interfaces
  3. Find the section for the network interface you want to set a static IP for (usually "eth0" or "wlan0"). It should look something like this:
    iface eth0 inet dhcp
  4. Change "dhcp" to "static" and add the following lines below it:
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1

    NOTE:Change the IP addresses to the desired static IP, subnet mask, and default gateway for your network.

  5. Save and exit the file.
  6. Restart the network interface with the command below.
  7. $ sudo ifdown eth0
    $ sudo ifup eth0

You should now be able to access the network with the static IP you set.

Enjoy!!

0 Comments

Leave a reply

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

*

©2025 ZMATECH: Innovative solutions for your IT challenges.

Log in with your credentials

Forgot your details?