In this quick tutorial i’m gonna explain how to setup a static IP address on ubuntu 16 LTS, the file which we need to make some changes is /etc/network/interfaces.
For this tutorial, we’re going to assign to my server these entries:
– IP address : 192.168.1.10
– NetMask 255.255.255.0
– Gateway 192.168.1.1
– Domain Name Servers : 192.168.1.2 192.168.1.3
First let’s open the file:
[root@server ~]# vim /etc/network/interfaces
# 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
Here we need to remove or comment iface enp0s3 inet dhcp or change it to static then add the static ip address, netmask, gateway and the dns servers like below :
# The primary network interface auto enp0s3 #iface enp0s3 inet dhcp iface enp0s3 inet static address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 192.168.1.2 192.168.1.3
Next, save the file and reboot the networking service .
[root@server ~]# systemctl restart networking
or this command
[root@server ~]#/etc/init.d/networking restart
Until the next time.
PS. If you like this post please share it with your friends on the social networks using the buttons below.Thanks.
2 comments
followed the steps … I cannot ping outside.
auto enp2s0
iface enp2s0 inet static
address 10.0.0.2
netmask 255.255.255.0
gateway 10.0.0.1
dns-nameservers 10.0.0.1
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.0.0.1 0.0.0.0 UG 0 0 0 enp2s0
10.0.0.0 * 255.255.255.0 U 0 0 0 enp2s0
link-local * 255.255.0.0 U 1000 0 0 enp2s0
ping: unknown host google.com
check your dns-name server, add the google dns server 8.8.8.8 or 4.4.4.4