By Manny Fernandez

April 1, 2020

Setting Static IP Address on an Ubuntu Server

In preparation for another article I am writing, I deployed an Ubuntu Server 18.04.  By default, it boots with DHCP.  I usually use CentOS so when I wanted to change from DHCP to static IP, I found it was a bit different than CentOS.  Ubuntu Server uses Netplan.  Here is a blurb from the Netplan site.

2020-04-01_08-40-41

DHCP – [Default]

You will need to use the sudo command to make changes as your user does not have rights to make the changes.  You need to go to /etc/netplan

2020-04-01_08-45-13

run the following command sudo vi /etc/netplan/50-cloud-init.yaml in my case, your mileage may vary.

# 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:
ens160:
dhcp4: yes

Static IP

It is important to keep the spacing/indent correct or you will receive an error.  I made the mistake and added the line with addresses as address (Singular) and it barked at me.

# 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:
ens160:
dhcp4: no
addresses: [10.1.106.61/24]
gateway4: 10.1.106.1
nameservers:
addresses: [10.1.106.43,4.2.2.2]
version: 2

If you are like me and you are using vi and you are editing the file:

i – This will allow you to edit

esc – Once you finish make the edits, you will hit the esc key.

: – Next type the semi-colon  (:)

x – Type x which will save

Recent posts

  • There are many options when troubleshooting in FortiGate firewalls. ... Full Story

  • Have you ever had an IPS signature that continues... Full Story

  • Use case:  Customer has a Split Tunnel Enabled but... Full Story