Configure static IP for Linux
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
iface eth1 inet static
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.
- Login as root or a user with sudo privilege
- Run sudo ifdown eth1 to bring down the desired network interface
- Run sudo ifup eth1 to bring up the desired network interface
Now check the whether the configuration takes effect using ifconfig -a command.
Loves coding too much. Don't forget about code even when catching a cold indeed.