Ubuntu Static IP configuration

This tutorial will deal with Ubuntu static IP address configuration. It will provide the reader with a step by step procedure how to set static IP address on Ubuntu Server via netplan and Ubuntu Desktop using NetworkManager. Static IP address is recommended for servers as the static address does not change as oppose to a dynamic IP address assignment via DHCP server.

DID YOU KNOW?
Did you know that static IP address can also be achieved by DHCP server? DHCP server allows for a manual MAC address binding to a specific IP address, which will result in client receiving same static IP address with each dynamic IP address request.

In this tutorial you will learn how to:

  • Set static IP address on Ubuntu Desktop using a NetworkManager
  • Configure static IP address on Ubuntu server via networkd daemon

 

Ubuntu Static IP configuration
Ubuntu Static IP configuration

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or Ubuntu Server/Desktop
N/A
Other Privileged 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 Static IP configuration step by step

Ubuntu Desktop

The simplest approach on how to configure a static IP address on Ubuntu Desktop is via GNOME graphical user interface:

Open network settings Ubuntu Desktop

Click on the top right network icon and select settings of the network interface you wish to configure to use a static IP address on Ubuntu.


Start network configuration to set static IP address

Click on the settings icon to start IP address configuration.

Static IPv4 IP address Ubuntu Desktop

Select IPv4 tab.

enter your desired static IP address

Select manual and enter your desired IP address, netmask, gateway and DNS settings. Once ready click Apply button.


apply your new network configuration settings

Turn OFF and ON switch to apply your new network static IP configuration settings.

confirm your new IP address settings

Click on the network settings icon once again to confirm your new static IP address settings.

Ubuntu Server

To configure a static IP address on your Ubuntu server you need to modify a relevant netplan network configuration file within /etc/netplan/ directory.

NOTE
Carefully check the renderer stanza in your configuration file. If the renderer configuration is set to NetworkManager then your Ubuntu’s system network configuration is managed by GUI Network Manager. Change the renderer to renderer: networkd if you do not wish to configure your network IP address via Graphical User Interface ( desktop ).

For example, you might find there a default netplan configuration file called 50-cloud-init.yaml or 01-network-manager-all.yaml with a following content using the networkd deamon to configure your network interface via DHCP:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
    version: 2



Default dynamic IP address settings on Ubuntu Server
Default dynamic IP address settings on Ubuntu Server

To set your network interface enp0s3 to static IP address 192.168.1.233 with gateway 192.168.1.1 and DNS server as 8.8.8.8 and 8.8.4.4 replace the above configuration with the one below.

WARNING
Note, you must adhere to a correct code indent for each line of the block. In other words the prefix number of spaces for each line is important. Otherwise you may end up with an error message similar to:
Invalid YAML at //etc/netplan/01-netcfg.yaml line 7 column 6: did not find expected key
.
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
     dhcp4: no
     addresses: [192.168.1.233/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [8.8.8.8,8.8.4.4]
Ubuntu server configured with static IP address.
Ubuntu server configured with static IP address.
Once ready apply changes with:
$ sudo netplan apply

In case you run into some issues execute:

$ sudo netplan --debug apply