When you have bought a server with a main IP and assigned additional IPs, additional IPs are routed statically on your main IPs, thus no gateway or broadcast addresses are needed when configuring the IPs on your NIC.
However, when using additional IPs, the default route of the server is still via gateway of your primary IP. How to reroute all the traffic via additional IP?
To begin with, in this example we will use Kronos Cloud server with CentOS 7 OS, with main IP 126.96.36.199. For additional IP we will use 188.8.131.52/32 which we have already assigned to our server via Terminal.
Note: after assigning the additional IPs to the server, do not forget to perform stop/start of the server for the routing to be fully finished, or else you might not see the desired results.
Changing the default route is not that hard, it might be done temporarily, or permanently.
Let's check the network configuration:
Inspect the results:
Now, let's add the additional IP:
ip addr add 184.108.40.206/32 dev eth0
Check the network configuration again:
We see the IP address was added successfully.
Checking from some other computer/server, we can see it gives ping replies
Now, let's check the default route:
Let's change the default route for the source IP:
ip r change default via 220.127.116.11 src 18.104.22.168
Inspect the results:
This is it! The traffic is now rerouted to go via additional IP.
Note: after performing network service restart or restarting the server - these changes will be reverted back to defaults.
A permanent solution is as easy as the temporary one:
Let's edit the /etc/sysconfig/networking-scripts/ifcfg-eth0 file (if your network interface name is eth0):
Note: as our examples if for Kronos Cloud server, we need to configure the IP address statically.
Here is how our configuration looks in this example case:
Make sure there are no mistakes in this file, we suggest you firstly configuring static IP, then restarting network service, then configuring second IP in the same file and only the adding the SCRADDR (source address) or else you might lose connection to your server (in this case, use the virtual console via Heficed Terminal to reach your server).
Check the results:
And that is exactly what we were aiming for.