How to set static IP Address in Ubuntu Server 16.04
It is really important to know how to configure static IP Address on Ubuntu Server, Because it is almost impossible to run a server without a static IP Address.
During the installation, Ubuntu Server by default configured to use dynamic IP Address. In this Tutorial we are going to learn how to set static IP Address in Ubuntu Server 16.04.
Following are the steps we are going to follow
- Check Available network interfaces on Ubuntu Server 16.04
- Add static IP Configuration to the network configuration file.
- Restart Ubuntu Networking Service.
Check Available Network Interfaces on Ubuntu Server
First of all you need to get the list of available network interfaces on your Ubuntu Server 16.04. We can use ip link show command to find available network interfaces on Ubuntu Linux.
ip link show
You should get the similar output as below screenshot shows.
As above image shows, Our Ubuntu Server has Ethernet interfaces called enp0s3. Next we'll set static IP address to the enp0s3 interface.
Set static IP Address to the network interface
For this example I am going configure enp0s3 Ethernet interfaces with following ip configuration
IP Address = 192.168.1.10
Network mask = 255.255.255.0
Default gateway = 192.168.1.1
DNS Server = 8.8.8.8 and 8.8.4.4
On Ubuntu server, in order to set static IP address we need to add IP configuration to the /etc/network/interfaces file. So open the /etc/network/interfaces file using a command line text editor (You can use vim or nano on Ubuntu Server).
vim /etc/network/interfaces
Then set static IP address as follows.
First line of configuration should be the word "auto" followed by the interface name (This brought up the network interface automatically when system boot or when networking restart).
auto enp0s3
The next line should specify whether to use static IP address or dhcp ip on the enp0s3 network interface. In our case it should be static.
auto enp0s3
iface enp0s3 inet static
Then add the static IP configuration as follows.
auto enp0s3
iface enp0s3 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
Restart Networking Service
After setting up IP Configuration, we need to restart Ubuntu networking service.
sudo ip addr flush enp0s3 && sudo systemctl restart networking.service
Verify the static IP configuration.
After restarting network, use ip add command to make sure that static ip address has been assigned to the network interface.
ip add
Then send ICMP request to a remote host to check the connectivity.
ping -c 4 google.com
Configure Multiple Network Interfaces
Same Way you can configure multiple network interface on ubuntu server using /etc/network/interfaces file.
Example
In the following example, I have set static IP Address on two network interfaces (enp0s3 and enp0s8).
auto enp0s3
iface enp0s3 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
auto enp0s8
iface enp0s8 inet static
address 192.168.0.100
netmask 255.255.255.0
*** Most important thing when configuring multiple interface is you cannot set multiple default gateways. Only one interface should configure with the default gateway. For other interfaces you should add default gateway using static routes.
Summary : Set Static IP Ubuntu Server 16.04
In this tutorial we learned how to set static ip address in Ubuntu server 16.04.
- Using ip link show command we identified the available network interface in our ubuntu server 16.04.
- Then we add static IP address configuration to the /etc/network/interfaces file and restart the ubuntu networking service.