How to configure a Static IP address on Ubuntu 18

This tutorial will show you all the steps required to configure a static IP address on Ubuntu Linux.

This tutorial was tested on Ubuntu 18.04.

1. Detect the Network Interface on Linux

First, you need to verify if the Ubuntu Linux detected the network interface.

# lshw -C network

Take note of the Network interface logical named.

In our example, the system detected a network interface named ENS160.

description: Ethernet interface
product: VMXNET3 Ethernet Controller
vendor: VMware
physical id: 0
bus info: pci@0000:03:00.0
logical name: ens160
version: 01
serial: 00:0c:29:b1:46:b1
size: 10Gbit/s
capacity: 10Gbit/s
width: 32 bits
clock: 33MHz
capabilities: pm pciexpress msi msix bus_master cap_list rom ethernet physical logical tp 1000bt-fd 10000bt-fd
configuration: autonegotiation=off broadcast=yes driver=vmxnet3 driverversion= duplex=full ip= latency=0 link=yes multicast=yes port=twisted pair speed=10Gbit/s
resources: irq:18 memory:fd5fc000-fd5fcfff memory:fd5fd000-fd5fdfff memory:fd5fe000-fd5fffff ioport:4000(size=16) memory:fd500000-fd50ffff

2. Backup the Network Configuration Files

Create a backup of your current network configuration.

# mkdir /backup
# cp /etc/netplan /backup -R

3. Configure the Static IP Address

Access the Netplan directory and list the configuration files available.

# cd /etc/netplan
# ls


Usually, you will find a file named 01-netcfg.yaml or a file named  50-cloud-init.yaml.

In our example, let's assume that you found a file named 50-cloud-init.yaml.

Edit the network configuration file.

# cd /etc/netplan
# vi 50-cloud-init.yaml

Here is the default content of the network configuration file:


Here is the new file with our configuration.


In our example, the network interface ENS160 was configured to use the IP address, the gateway and the DNS server from Google and


The Netplan configuration files use the YAML configuration language

YAML is a human-friendly data serialization standard for all programming languages.
YAML is extremely sensitive to indentation errors.

Enable the new Network configuration.

# netplan generate
# netplan apply

4. Verify the Network Configuration

Use the IFCONFIG command to verify the network interface configuration.

# ifconfig

Here is the current network interface configuration.

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet netmask broadcast
inet6 fe80::20c:29ff:feb1:46b1 prefixlen 64 scopeid 0x20 ether 00:0c:29:b1:46:b1 txqueuelen 1000 (Ethernet)
RX packets 572572 bytes 258895818 (258.8 MB)
RX errors 0 dropped 319 overruns 0 frame 0
TX packets 132383 bytes 11603906 (11.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Verify the DNS configuration.

# systemd-resolve --status

Here is the current DNS configuration.

Link 2 (ens160)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers:

Verify the default route configuration.

# netstat -nr

Here is the current routing table configuration.

Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface UG 0 0 0 ens160 U 0 0 0 ens160