Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Distributions»Ubuntu»How to Configure Static IP Address on Ubuntu 22.04

    How to Configure Static IP Address on Ubuntu 22.04

    By RahulJanuary 19, 20234 Mins Read

    After installing Ubuntu 22.04 the default network interface assigns an IP address using the DHCP server. Also, the wireless network will be active and enable networking over the wifi network.

    Advertisement

    You can also configure the network interface with static IPv4 addresses. Ubuntu 22.04 uses the Netplan as a network manager.

    This tutorial helps you to configure network interfaces on Ubuntu 22.04 Desktop and Ubuntu 22.04 Server editions. The desktop users can use any one of the below methods but the server users that have CLI only access use the second method to edit network interface configuration files.

    Method 1: Configuring Static IPv4 Address on Ubuntu 22.04 Desktop

    The Ubuntu Desktop editions have a graphical interface for configuring the network interfaces. Follow the below steps to configure a static IP address on Ubuntu 22.04 Desktop system.

      • Click the network icon in the upper-right corner.
      • Then expand the Wired Connected dropdown.
      • Now, click on Wired Setting as shown below image.

      Configuring Static IP on Ubuntu 22.04
      Edit Wired Interface Settings
      • A network settings dialog box will appear.
      • Now, click “Network” in left sidebar.
      • Under the Wired section, click the Gear icon as showing in below image

      Configuring Static IP on Ubuntu 22.04
      Edit Network Interface
      • A new Wired dialog box will appear.
      • Now, click on “IPv4” tab.
      • Set IPv4 Method to Manual
      • Input a valid IP address, Netmark and Gateway address
      • Set the DNS server (optional)
      • Click Apply button to save changes

      Configuring Static IP on Ubuntu 22.04
      Configuring Static IP on Ubuntu
    1. Finally disable and then again enable networking to apply changes.

      Configure Static IP Address on Ubuntu 22.04
      Disable and Enable Networking
    2. All done. Ubuntu Desktop system IP address is now changed.

    Method 2: Configuring Static IPv4 Address on Ubuntu 22.04 Server with CLI

    Server editions are installed without any graphical interface. In that case, you need to configure the IP address using the command line.

    Ubuntu uses the Netplan as a network manager that is responsible for configuring the network interfaces. Follow the below steps:

    1. First, find out the network interface name in your system. The interface name can differ based on the installation type and system hardware. To find the interface name type:
      sudo ip a 
      
      Configure Static IPv4 Address using Netplan on Ubuntu
      Checking the network interface name

      The above output shows that the system is configured with the network interface name eth0. This can be different on your system.

    2. Now, create or edit the network configuration file under the /etc/netplan directory. Create a configuration file and edit it in an editor:
      sudo vi /etc/netplan/01-netcfg.yaml 
      

      Add the network configuration in YAML format as below:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      network:
          version: 2
          renderer: networkd
          ethernets:
              eth0:
                  addresses:
                      - 192.168.1.212/24
                  nameservers:
                      addresses: [8.8.8.8, 8.8.4.4]
                  routes:
                      - to: default
                        via: 192.168.1.2

      In the above configuration:

      • eth0 – is the network interface name
      • addresses – is used to configure IPv4 address on an interface. Make sure to define CIDR. You can add multiple addresses here
      • nameservers – Set the name servers here. 8.8.8.8 and 8.8.4.4 are Google’s name servers
      • routes – This is used to set gateway on your system.

      Make sure the IPv4 address belongs to the system network and has the correct gateway Ip address. Once confirmed, save file content and close it.

    3. Apply the changes by running the following commands.Now, execute the following command to apply the changes:
      sudo netplan apply 
      

      That’s it. The static IP address is configured on your Ubuntu system.

    Conclusion

    In this tutorial, you have learned 2 methods of configuring network interface on Ubuntu 22.04 systems. The first method uses the GUI interface to set up a static IP address. The second method provides you with the instructions to configure the network interface via the command line using Netplan.

    You can also configure multiple IP addresses on a single network interface.

    Netplan networking static ip
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Setup DKIM (DomainKeys) with Postfix

    A Step-by-Step Guide to Installing OpenDKIM with Postfix on Ubuntu – Unleash the Power of DKIM!

    How to Install Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    How to Install Apache Kafka on Ubuntu 22.04

    How to Install Apache Kafka on Ubuntu 22.04

    View 10 Comments

    10 Comments

    1. Luuk on September 23, 2022 10:14 am

      **networkctl list**
      IDX LINK TYPE OPERATIONAL SETUP
      1 Io loopback carrier unmanaged
      2 eth0 ether routable configured

      **route**
      Destination Gateway Genmask ….. iface
      default 192.168.178.1 0.0.0.0 …… eth0
      192.168.178.0 0.0.0.0 255.255.255.0 …… eth0

      **/etc/netplan/000-installer-config.yaml**
      network:
      version: 2
      renderer: networkd
      ethernets:
      eth0:
      addresses:
      – 192.168.178.43/24
      nameservers:
      addresses: [8.8.8.8]
      routes:
      – to: default
      via: 192.168.178.1

      After this `ip-a` confirms i have ip address 192.168.178.43, but `ping -4 192.168.178.1` says: Destination Host Unreachable

      Any ideas on how to change? I only have CLI, no GUI running

      Reply
    2. Brad on September 5, 2022 9:03 am

      Oh man bring back /etc/network/interfaces

      Reply
    3. Robert on August 23, 2022 11:48 pm

      If you use the GUI, you need to disable and then enable the connection. Just clicking on ‘Apply’ doesn’t change anything.

      Reply
    4. ZarxAarox on June 29, 2022 5:13 pm

      I am getting an error:
      Error in network definition expected mapping (check indentation) network:

      Any help would be great!

      Reply
    5. ELM on June 15, 2022 1:38 pm

      When I set
      – to: default
      via: 192.168.1.1
      I get an error : could not find expected ‘-‘ before via
      and when I add this ‘-‘ before via, then I get : error in network definition: global unicst route must include both ‘to’ and ‘via’ IP.

      That’s a nightmarre to configure a simple eth0 using CLI.

      Reply
      • Rahul on June 16, 2022 6:05 am

        Hi ELM,

        I have again verified the configuration file and it works fine for me. Make sure that JSON is properly formatted and any extra or less space may cause syntax issues.

        Reply
    6. Ken on May 2, 2022 7:11 pm

      It is warning that gateway4 is depracated and default routes should be used instead.

      Reply
      • Rahul on May 4, 2022 5:20 am

        Thanks, Ken, article is updated accordingly.

        Reply
    7. Passerby on May 2, 2022 4:20 pm

      gateway4: is no longer allowed as an option in Ubuntu 22.04

      Now requires

      routes:
      – to: default
      via: 192.168.1.1

      Reply
      • Rahul on May 4, 2022 5:20 am

        Thanks, Passerby, gateway4 works but as its deprecated, I have updated the article to routes.

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.