Skip to content

How to Set Static IP on Ubuntu

To set the static IP address on Ubuntu, we want to first determine what network interfaces we currently have. These network interfaces represent the Infiniband or Ethernet ports on your computer. You will typically have an interface called eth0 or eth1 that allows you to connect to the Internet.

Note, setting the static IP will allow you to connect to the Internet as long as the IP address is valid according to your DHCP server. If you set any static IP address randomly and refresh the interface, you will not be able to connect to the Internet. However, the static IP address should still work on the internal network. I would recommend doing the following steps directly on the computer instead of through SSH.


To find out what interfaces you have, you can first check for interfaces that contain eth.

ifconfig -a | grep eth

You can also use the following command to see all your interfaces:

cat /proc/net/dev

Here, we have an eth0 interface that we can set a static IP. If we don’t see any interfaces after running the above commands, then we will have to check the interfaces configuration file.

sudo vim /etc/network/interfaces

You will see something like this:

auth lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto lo refers to the loopback for connections to oneself. We want to change the eth0 interface or whatever named interface you have. Note, the interface may have a different name.

We want to give the eth0 interface a static IP address.

auto eth0
iface eth0 inet static

Now, we save the file, and we can restart the network.

sudo ifdown eth0 && sudo ifup eth0

We can check if eth0 has the new static IP address.

ifconfig | grep eth0

You should see the new eth0 interface information after running the above command.