;

How to Bind Multiple IP Addresses on a CentOS 7 Linux Server

Try it in our public cloud & Get $5 Credit
CLAIM NOW

How to Bind Multiple IP Addresses on a CentOS 7 Linux Server

Many complex network setups require that multiple IP addresses be bound to a single server. This might happen if you have presences on both public and private networks, or need to support multiple servers that expect to bind the same port. It is also useful to secure services by binding them on private IPs, or by creating firewall rules that keep traffic quarantined. Here is how you would go about assigning multiple IP addresses to your CentOS 7 server.

Getting Started

To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Server) with CentOS 7.

Tutorial

In this guide, we’ll be working with a network with this configuration:
• Network CIDR:: 192.168.0.1/29
• First usable IP: 192.168.0.3
• Last usable IP: 192.168.0.7
• Gateway: 192.168.0.2
• Netmask: 255.255.255.248

With those basic specifications established, let’s set up your server to respond accordingly.

We start by configuring the eth0 interface. This is done by editing the interface script.

nano /etc/sysconfig/network-scripts/ifcfg-eth0

Insert this block of text:

DEVICE="eth0"
BOOTPROTO="static"
DNS1="8.8.8.8"
DNS2="8.8.4.4"
GATEWAY="192.168.0.2"
IPADDR="192.168.0.3"
IPV6INIT="no"
NETMASK="255.255.255.248"
ONBOOT="yes"
TYPE="Ethernet"

We’ll now need another configuration file for the other IP.

nano /etc/sysconfig/network-scripts/ifcfg-eth0-range0

IPADDR_START=192.168.0.4
IPADDR_END=192.168.0.7
CLONENUM_START=0
NETMASK=255.255.255.248

service network restart

With the above configuration in place, your server should now respond to all of the IPs specified in this example. Traffic will route out through the configured gateway. You can now set up arbitrary servers bound to the IPs on your newly-created network.

Because each server is on its own IP, they can also bind the same ports. You could, for instance, have two separate Apache instances configured distinctly, each answering port 80 on any of the IPs you’ve just created.

Conclusion

While this example was quite simplistic, the basic principles are the same regardless of complexity. If you can understand the above, it is simple to scale the configuration up to arbitrarily complex networks, each with separate gateways, and to allocate ranges of IP addresses separately to programs and services on the same CentOS server. If this guide was helpful to you, kindly share it with others who may also be interested.