How to configure Static IP Address on Ubuntu

There are two ways in which a system can get its IP address first is  DHCP server second if you configure it statically. By default when Ubuntu is installed it takes IP from the DHCP server. But we need static IP to connect to server for SSH or to access any other services that will be running on it.

Configuring static IP on Ubuntu is very easy. This article will guide you through how you can configure it.

This post to configure static IP will help you till Ubuntu release 17, if you are running  Ubuntu release 18 then you can check out my post on configuring static IP address on Ubuntu 18 because on Ubuntu 18 there is a big change on how you configure static IP addresses.

Configuration File /etc/network/interfaces

The network configuration are stored in /etc/network/interfaces file and following is its default configuration with DHCP.
The network interface name here is enp0s3 it may be different for you.

network-interfaces-file
network-interfaces-file

Update The Primary Network Interface to Static

Edit the /etc/network/interfaces file.

# vim  /etc/network/interfaces

Then  change the dhcp to static and add the following lines to primary network interface.

iface enp0s3 inet static
address 192.168.1.133
netmask 255.255.255.0
broadcast 192.168.1.255
gateway  192.168.1.1
dns-nameservers 8.8.8.8

 I prefer to use the IP address that is already assigned to  machine you can find that out with simple ip r command as follow. If you don’t want to use this IP you can use any other available IP in your network.

show-ip-address-with-ip-r
show-ip-address-with-ip-r
change-dhcp-ip-address-to-static
change-dhcp-ip-address-to-static

Restart the Network Service

Save the /etc/network/interfaces file changes and restart the network service.

# service  networking  restart

That’s it you have successfully changed the IP address from DHCP to Static.
Happy Networking.