Home // How to Configure Static IP Address on Ubuntu 16.04 to 22.04

How to Configure Static IP Address on Ubuntu 16.04 to 22.04

0 6 mins read
| Published on: July 22, 2022 | Last updated on: July 31, 2023

How to Configure Static IP Address on Ubuntu 16.04 to 22.04

This article will walk you through the process of configuring Ubuntu 20.04 to use a static IP address.

The DHCP server on the router is often responsible for dynamically assigning IP addresses in the majority of network setups. The assignment of a static IP address may be necessary in a variety of contexts, including the configuration of port forwarding and the operation of a media server, for example.

Implementing Static IP Address Configuration Using DHCP

Configuring a Static DHCP server on your router is the simplest and most recommended method for assigning a static IP address to a device on your local area network (LAN). Static DHCP, also known as DHCP reservation, is a feature that can be found on most routers. This feature instructs the DHCP server to always issue the same IP address to a particular network device whenever that device makes a request for an address from the DHCP server. A static IP is given to the device so that it may be identified by its unique MAC address.

Different routers have different procedures that must be followed in order to configure a DHCP reservation. For further information, please refer to the documentation provided by the vendor.

Netplan

Starting with version 17.10, the network administration utility that comes pre-installed with Ubuntu is Netplan. When configuring the network, earlier versions of Ubuntu relied on the ifconfig utility and the /etc/network/interfaces configuration file that came with it.

The configuration files for Netplan are saved with a .yaml file extension and are authored using YAML syntax. In order to use Netplan to setup a network interface, you will first need to write a YAML description of the interface. After this has been completed, Netplan will build the necessary configuration files for the renderer tool that you select.

Both NetworkManager and Systemd-networkd are supported renderers for use with Netplan. Systemd-networkd is often utilized on servers that do not have a graphical user interface (GUI), while NetworkManager is typically utilized on desktop computers.

Setting up a Fixed IP Address on the Ubuntu Server

Quick way:

Change the config which is located over at  sudo nano /etc/netplan/01-netcfg.yaml from:

/etc/netplan/01-netcfg.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes

To:

/etc/netplan/01-netcfg.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - x.x.x.x/24
      gateway4: x.x.x.x
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

Fill in Xs with your own IP

American tour bus way:

“Predictable network interface names” are the method by which the system in Ubuntu 20.04 recognizes the various network interfaces.

The first thing you need to do in order to set up a static IP address is to determine the name of the ethernet interface that will be used for the configuration. To do this, use the ip connect command, as illustrated in the following example:

ip link

This command will produce a list of all of the network interfaces that are currently accessible. The name of the interface is ens3 in this particular illustration:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff

The /etc/netplan directory is where all of the configuration files for Netplan are kept. This directory most likely contains one or more YAML files for you to look over. There is a possibility that the name of the file will change depending on the setting. The name of the file is typically 01-netcfg.yaml, but it may also be interfaceName.yaml or 50-cloud-init.yaml. However, the name of the file on your system could be different.

You will need to deactivate cloud-init if it was used to provision the Ubuntu cloud instance you are working with. In order to accomplish this, please produce the following file:

sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}

Open up the YAML configuration file using your preferred text editor in order to assign a static IP address to the network interface:

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

/etc/netplan/01-netcfg.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes

First, let’s go through a brief explanation of the code before we make any changes to the settings.

Every Netplan YAML file begins with the network key, which must have a minimum of two mandatory items. The kind of the device is the second needed component after the version of the network configuration format, which is the first essential element. It is possible for the device type to be an ethernet, bond, bridge, or vlan.

A line that displays the kind of renderer is also included in the setup that was just shown. If you installed Ubuntu in server mode, then the renderer will automatically be set up to utilize networkd as the back end. This is the default configuration.

You have the ability to select one or more network interfaces under the ethernets heading of the device’s type. In this particular illustration, we only have one interface, designated as ens3, that is set up to receive IP addressing information from a DHCP server (dhcp4: yes).

Make the following edits to the file in order to provide a static IP address to the ens3 interface:

  • Set DHCP to dhcp4: no.
  • Specify the static IP address. Under addresses: you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.
  • Specify the gateway.
  • Under nameservers, set the IP addresses of the nameservers.

/etc/netplan/01-netcfg.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      addresses:
        - 10.0.0.25/24
      gateway4: 10.0.0.1
      nameservers:
          addresses: [8.8.8.8, 1.1.1.1]

When modifying Yaml files, you must ensure that the code indentation rules for YAML are followed. The modifications will not be implemented if the syntax cannot be rectified beforehand.

After you have finished, be sure to save the file and apply the modifications by executing the following command:

sudo netplan apply

Verify the changes by typing:

ip addr show dev ens3
 2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.25/24 brd 10.0.0.255 scope global dynamic ens3
       valid_lft 3575sec preferred_lft 3575sec
    inet6 fe80::5054:ff:feb0:f500/64 scope link 
       valid_lft forever preferred_lft forever

You have provided your Ubuntu server with a fixed Ip.

Creating a Static IP Address Configuration on Your Ubuntu Desktop

There is no need for technical skills to configure Ubuntu Desktop machines to use a static IP address.

Search for “settings” in the Activities screen’s search bar, then click on the icon that appears. The GNOME settings window will pop up when you do this. To make changes to the interface, select either the Network or Wi-Fi tab and then click the appropriate button. To access the settings for the interface, choose the cog icon that is located to the right of the interface’s name.

Choose “Manual” from the drop-down menu under “IPV4” Method, then input your static IP address, Netmask, and Gateway. After you are finished, click the “Apply” button.

To verify the changes, open your terminal either by using the Ctrl+Alt+T keyboard shortcut or by clicking on the terminal icon and run:

ip addr

The output will show the interface IP address:

...
2: wlp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000link/ether 50:5b:c2:d8:59:7d brd ff:ff:ff:ff:ff:ffinet 10.0.0.25/24 brd 10.0.0.255 scope global dynamic noprefixroute wlp1s0
valid_lft 38963sec preferred_lft 38963sec
inet6 fe80::45e3:7bc:a029:664/64 scope link noprefixroute
 

Conclusion

We’ve shown you how to configure a static IP address on Ubuntu 20.04.

If you have any questions, please leave a comment below.

IF YOU ARE HAVING PROBLEMS WITH THIS GUIDE, EMAIL US AT:

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Copyright @2022-2024 All Right Reserved – PCPlanet

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. You understand and give your consent that your IP address and browser information might be processed by the security plugins installed on this site. By clicking “Accept”, you consent to the use of ALL the cookies.
.
Accept Read More

Privacy & Cookies Policy