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
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
ifconfig -a | grep eth
You can also use the following command to see all your interfaces:
eth0 Link encap:Ethernet HWaddr 00:04:4b:57:f9:74
inet addr:184.108.40.206 Bcast:220.127.116.11 Mask:255.255.255.0
inet6 addr: fe80::204:4bff:fe57:f974/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1774748 errors:0 dropped:0 overruns:0 frame:0
TX packets:1157834 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:338152978 (338.1 MB) TX bytes:213483020 (213.4 MB)
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 address 18.104.22.168 netmask 255.255.255.0 gateway 22.214.171.124 dns-nameservers 126.96.36.199 188.8.131.52
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.