Adding static ip address in Ubuntu

image source:Pixabay

In today’s tutorial we are going to configure static ip in ubuntu. The steps are as follows:

Install vim editor if have not previously:

sudo apt-get install vim

Now open interfaces file in networks using the following command:

sudo vim /etc/network/interfaces

Add the following code:

uto lo eth0
iface lo inet loopback
iface eth0 inet static

The address,netmask and gateway value will change according to each os. The address and netmask has to be added from parameters in ifconfig command:

root@HOMEPC:# ifconfig
eth0 Link encap:Ethernet HWaddr a4:17:31:9c:11:4d
inet addr: Bcast: Mask:
inet6 addr: fe80::e49a:8a31:3c56:f9d0/64 Scope:Link
RX packets:292071 errors:0 dropped:0 overruns:0 frame:0
TX packets:179742 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:386351683 (386.3 MB) TX bytes:21029080 (21.0 MB)

Add inet addr as address and Mask value as netmask in interfaces file.

For gateway we need to run the following command:

root@HOMEPC:/var/lib/docker# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface UG 600 0 0 eth0

Copy the gateway value from above to interfaces file.

Once you are done with editing save and close the interfaces file.

Next run the following commands to start using static ip address:

ifdown eth0
ifup eth0


sudo service networking restart

Thats all for today’s tutorial.

Bonus tip:

If you are trying to assign static ip to a docker container make sure you add following tag in the run command:

docker run --cap-add=NET_ADMIN

Connect deeper:

You can find my previous article here and like our facebook page to get notified about similar posts in the future here: Technoetics

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.