Configure static IP for Linux

  sonic0002        2017-07-08 08:39:58       2,882        0    

When a Linux server is running, it has to have an IP so that other machines can talk to it. It is often desired that the server would own a static IP so that every time other machines want to connect to it, the same IP address would be used. This is extremely useful when there are virtual machines installed on a host machine where the virtual machine would start and stop now and then. 

To configure static IP address for a Linux server, the /etc/network/interfaces needs to be updated. Assuming there is a host only network is created for a network interface named eth1. The configuration would look like

auto eth1
iface eth1 inet static
address 192.168.56.150
netmask 255.255.255.0
gateway 192.168.56.1
broadcast 192.168.56.255

Here the interface for eth1 needs to be defined with static specified. This means this will be a static IP. Other options are available as well such as dhcp and loopback

Next, need to specify the IP address to be configured. This will be the IP address other machines would connect to. Thereafter, some standard configuration should be defined such as netmask, gateway, dns-nameservers etc. But the address is the most important one.

After saving this configuration, the changes could be applied by running below commands.

  1. Login as root or a user with sudo privilege
  2. Run sudo ifdown eth1 to bring down the desired network interface
  3. Run sudo ifup eth1 to bring up the desired network interface

Now check the whether the configuration takes effect using ifconfig -a command.

Sometimes if you found that you cannot ping public domains after restarting the server, please check whether you have the correct DNS servers configured. You may also want to add your own DNS servers in /etc/network/interfaces with below line:

dns-nameservers 8.8.8.8 8.8.4.4

LINUX  NETWORK  DNS  STATIC IP 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

The future world