Configure Static IPv4 Addresses for More Reliable Networking on Ubuntu 14.04 LTS
Using static IPv4 addresses with server administration is helpful in a multitude of situations. It allows for configurations and services to know exactly what to expect and where to reliably send traffic. From defining security measures to configuring a server to use multiple IPv4 addresses to configuring for a high availability solution, static IP setups frequently come in handy. It’s also pretty cool to have a hand in your server’s inner workings.
A server typically comes with its own IPv4 address but does not come configured statically. IP configuration usually defaults to using the Dynamic Host Configuration Protocol (DHCP), which easily lets you switch IPv4 addresses and allows a server to assign new addresses without manual setup.
DHCP would set up your network interface, filling all necessary network information with the relevant IP assigned to your server. Most servers acquired from a hosting service will be set with it.
When it comes to multiple IP addresses on a single server, however, DHCP will not consistently recognize and reliably use all IP addresses allocated to it. To do this, you’ll need to configure static IP addresses, which takes a bit more work, requiring the manual entry of the IP address and gateway, and — depending on the distro running — the netmask. This gives the administrator the ability to setup and use some more powerful options, such as hosting an SSL enabled site (or multiple!) or setting up their own network cluster.
Luckily, static IPv4 address setup is quite simple. Here is an example for Ubuntu 14.04 LTS that you can follow by merely replacing your own IP addresses for those already given within the ‘/etc/network/interfaces’ file:
# Your primary public IP address.
iface eth0 inet static
address 198.51.100.5/24
gateway 198.51.100.1
# To add a second public IP address:
iface eth0 inet static
address 198.51.100.10/24
# To add a private IP address:
iface eth0 inet static
address 192.0.2.6/17
Once these new IP addresses are set up, rebooting the server should bring up the interface statically, as you’ve configured.
You can restart the networking with a ‘sudo ifdown -a && sudo ifup -a’’ command as well, but with all the services starting at the same time, this will not show if a reboot will provide the same results. Consequently, it may become an issue later when a reboot is made.
You can also find Linode’s tutorial on static IP configuration here. This guide will provide templates for other distros as well.
As a last aside, if you are on a Linode, you can use the Linode Network Helper to automatically configure this for you. You can find our blog on static IPv4 configuration here.