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.
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.
Insert this block of text:
We’ll now need another configuration file for the other IP.
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.
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.