Skip to content

Ubuntu Network Configuration Guide

Network setup for Ubuntu can range from easy to hard, depending on what you’re trying to do. Canonical prides itself on making their Ubuntu Linux operating system very simple to use, even if you do not have a lot of technical knowledge. Despite its simplicity, Ubuntu has a lot going on under the hood to make things work, including networking configuration that allows you to connect to local devices or servers across the world.

Although Ubuntu and its networking settings should normally, and ideally, work without a hitch, there may come a time where you need to roll up your sleeves and do some tinkering to get things sorted out. Or, maybe you’re just curious about various network configuration on the system. The best place to start is by finding out your Ubuntu system’s local IP address, public IP address, default gateway, and DNS information.

In this tutorial, we will show you how to get started with network configuration on Ubuntu. This can include simple tasks like viewing your system’s IP address, to more complex things like restarting your networking service, which may come in handy when troubleshooting network issues. Read on to start learning about network configuration on Ubuntu.

In this tutorial you will learn:

  • How to get local and public IP addresses
  • How to get DNS IP address and default gateway
  • How to set static IP address from GUI and command line
  • More Netplan configuration settings
Ubuntu Network Configuration Guide
Ubuntu Network Configuration Guide
CategoryRequirements, Conventions or Software Version Used
SystemUbuntu 18.04, 20.04, 22.04, 24.04
SoftwareNetplan (installed by default)
OtherPrivileged access to your Linux system as root or via the sudo command.
Conventions# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Ubuntu network setup – local and public IP addresses



If your system is connected to the internet, you are most likely using at least two IP addresses on your system. One IP address is your system’s local address, which is used to communicate with other devices on your home network. This includes your router and any devices you have connected to it.

Your public IP address is the one that devices over the internet will see you connecting from. This is an IP address that is routable on the world wide web, and will grant you connectivity to other servers and routers around the world. Typically, a home network has one public IP address, which is shared by every device that is connected to your router. Of course, other types of networking scenarios exist, but this is the most common.

  1. To see your local IP address, you can run the following command in terminal:$ ip a Locate the requested network interface and check for the assigned IP address. Additionally, the above command also reveals the network interface hardware address (also known as the MAC address).Retrieving local IP address with ip a command on UbuntuRetrieving local IP address with ip a command on UbuntuOn our test system, the local IP address is 192.168.122.112.
  2. There are also various ways to get your public IP address. You can go to a website like ip chicken or execute one of the following commands in terminal:$ echo $(wget -qO – https://api.ipify.org) OR $ echo $(curl -s https://api.ipify.org)
  3. To check for currently used DNS server IP address, execute this command:$ systemd-resolve –status | grep Current
  4. To display default gateway IP address, run this command:$ ip r
  5. You can also check for this information from your Ubuntu desktop GUI. To check for the internal IP address, default gateway, MAC address and DNS server settings on Ubuntu desktop first open Settings and click on Network menu and hit the gear wheel of the desired network interface.How to find my IP address, default gateway and DNS server on Ubuntu desktopHow to find my IP address, default gateway and DNS server on Ubuntu desktop

How to set static IP address

You can configure a static IP address on Ubuntu either from command or GUI. First, we will cover the instructions to configure one from Ubuntu GNOME GUI.


https://996ac42ce5096ad017794d85b3206303.safeframe.googlesyndication.com/safeframe/1-0-40/html/container.html

  1. Start by opening Settings and click on Network menu and hit the gear wheel of the desired network interface.
  2. Next, click the IPv4 tab, and then the manual configuration option.
  3. Fill out your desired IP address, subnet mask, and default gateway. Do not forget to also specify a custom DNS server if you wish. When you are done, click Apply to finalize the changes.
Configuring a static IP in GNOME GUI on Ubuntu
Configuring a static IP in GNOME GUI on Ubuntu

Configure a static IP address from command line

It is also possible to configure a static IP address from command line, which will be essential if you are running a server and do not have access to a Ubuntu GUI desktop.

  1. Locate and edit with administrative privileges the /etc/netplan/50-cloud-init.yaml file with the following configuration. Update your network interface name, desired static IP address, DNS server and gateway where appropriate. Save and exit the file after you have applied your changes.network: version: 2 renderer: networkd ethernets: enp1s0: dhcp4: false dhcp6: false addresses: – 192.168.122.150/24 routes: – to: default via: 192.168.122.1 nameservers: addresses: [208.67.222.222,192.168.122.1] NOTE: In recent updates to network configuration practices, the error message “gateway4 has been deprecated, use default routes instead” indicates that users need to replace the deprecated gateway4 option with the routes configuration. By specifying default and specific routes directly within the network interface settings, as demonstrated in the above example, users can achieve more flexible and clear network path definitions. This change is part of ongoing efforts to standardize and simplify network configurations.
  2. If you need to permanently disable cloud-init’s network management on systems that reset configurations at reboot, create a file in the `/etc/cloud/cloud.cfg.d/` directory. To do this, execute the command:$ sudo bash -c ‘echo “network: {config: disabled}” > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg’This command directly inputs the required settings into the file. By performing this action, you ensure that network configurations remain unchanged across reboots, thus removing cloud-init’s ability to manage network settings automatically. This file tells cloud-init to maintain network configurations as manually specified, bypassing automatic updates from the instance’s data source. This step is essential in environments that demand stable, manual network configuration.
  3. To apply the new Netplan changes execute:$ sudo netplan apply Alternatively, if you run into some issues run:$ sudo netplan –debug apply
  4. Confirm your new static IP address by using the ip a command:$ ip a

More Netplan configuration settings

Ubuntu uses Netplan to manage many network configuration settings. This is a frontend made by Canonical, and is meant to make the configuration process more simple.

To learn more about Netplan configuration on Ubuntu, it is recommended that you check our guide on Netplan network configuration tutorial for beginners.

Note that one of the most essential Netplan commands you are likely to need in the case of troubleshooting is how to restart the networking service. That can be done with following command:

$ sudo netplan apply

DID YOU KNOW? – NETWORK MANAGERS
There are many other ways to manage your network setup through graphical front ends. See our other tutorial on Linux GUI network managers if you would like to try out a different network manager than what Ubuntu includes by default.


https://996ac42ce5096ad017794d85b3206303.safeframe.googlesyndication.com/safeframe/1-0-40/html/container.html

Closing Thoughts

In this tutorial, we learned about basic network setup on Ubuntu Linux. We saw this through various processes such as how to view or set a static IP address, MAC address, default gateway, DNS server, etc. We also saw how to manage the network configuration from both command line and GUI.

Leave a Reply