Ubuntu Static IP

Linux is a varied operating system with myriad ways of accomplishing a single task. Here is the cleanest, quickest, way I use to set a static IP for Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-96-generic x86_64).

sudo nano /etc/network/interfaces

After entering your password you will be presented with a nano session showing the current configuration of your interfaces. If this is a fresh install you’ll see something like this.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp

Note! My interface is enp0s3 but yours may have a different name.

Comment out the current configuration for the interface you want to set to a static IP and edit in the new information.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto enp0s3
#iface enp0s3 inet dhcp
auto enp0s3
iface enp0s3 inet static
 address 10.10.10.20
 netmask 255.255.255.0
 gateway 10.10.10.3
 network 10.10.10.0
 dns-nameservers 10.10.10.3

In this example I have set it to:

auto enp0s3 Automatically bring the interface online
iface enp0s3 inet static Told the interface it will use a static IP
address 10.10.10.20 Set the static IP I want this VM to use
netmask 255.255.255.0 Set the subnet mask
gateway 10.10.10.3 Set the IP of the gateway to other networks
network 10.10.10.0 Set the network address
dns-nameservers 10.10.10.3 Set the DNS server to the router’s IP

The simplest way to test the configuration is to reboot the machine but you can turn the interface off and back on again if you know the commands for your specific version of Linux.

Leave a Reply

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d bloggers like this: