Linux: Configuring a Server for Static IP

This mini HOWTO explains the required configuration for a static IP.

Before proceed we must know the following configuration of our network:

  1. The IP Address to be used for our server;
  2. Netmask of our network;
  3. Broadcast IP address; and
  4. The gateway IP address.

First, we must open for edit the file /etc/network/interfaces:

$ sudo vim /etc/network/interfaces

Once there, we must find the network interface to be configured from a dynamic IP address to a static one. In this case it will be eth0:

auto eth0
iface eth0 inet dhcp

In the above example we can see that the interface eth0 is configured for dhcp (dynamic address). To change to static IP address configuration we must set the following:

auto eth0
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
nerwork 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254

Finally, we restart networking services:

$ sudo /etc/init.d/networking restart

And that’s it, we’ve now our server configured for static IP address.

Happy Hacking!

Linux: Configuring a Server for Static IP