Does your provider provides you with a connection to the internet via a static IP address? Are you an Ubuntu or Debian user like me? Are you looking for a way to configure your eth0 Linux network card with the static ISP provided IP address? That was the scenario with me and in this article I will explain, how you can configure your Home internet access with your Ubuntu/Debian based Linux.
Both Ubuntu and Debian does have a graphic tools, which also can be used to set a static IP address to your network interface, however I find it easier to do it straight from the command line.
To configure your internet static IP via a command line, what you will need to modify is the file:
In order to configure a static IP address, your provider should have equipped you with few IP addresses like let’s say the example values below:
Host IP Address: 192.168.0.5
Netmask Address: 255.255.255.0
Primary DNS Server: 192.168.0.1
Secondary DNS Server: 192.168.0.2
Now edit with vim, nano or mcedit /etc/network/interfaces e.g.:
root@ubuntu:~# mcedit /etc/network/interfaces
A plain /etc/network/interfaces file should contain something similar to:
iface lo inet loopback
In order to be able to set your static IP address, Netmask, Gateway and DNS servers you will have to append in the interfaces file, the settings:
iface eth0 inet static
The eth0 sets the lan card on which the values will be assigned, address variable is the IP address assigned by your ISP, netmask is logically the netmask, network should always be configured same as the value set for address but the last ip block should be always .0 , gateway as you already know is the gateway (the ISP router).
One more thing you need to do is to configure your DNS servers by including the DNS ip addresses to /etc/resolv.conf , just issue something like:
root@ubuntu:~# echo 'nameserver 192.168.0.1' >> /etc/resolv.conf
root@ubuntu:~# echo 'nameserver 192.168.0.2' >> /etc/resolv.conf
To test that your new Linux static ip configuration is correct exec:
root@ubuntu:~# /etc/init.d/networking restart
Next use ping or (if ping is disabled by ISP), use matt’s traceroute (mtr) or a browser to test if the Linux is connected to the net.
ubuntu:~# ping google.com
ubuntu:~# mtr google.com
If none of the two are not able to show either ping requests flowing around, or routes to google, then something is either wrong with your internet configuration or you forgot to pay your internet bill 😉