Recently I leased a server with 2 IPs, x.x.x.x and y.y.y.y from a VPS company. Their first IP is the primary one and is connected to my VM, the secondary IP y.y.y.y is there for me to use, but have not connected yet.
Given the following status quo:
The primary x.x.x.x is a great IP and has good connectivity all over the world, however their y.y.y.y secondary IP has a premium networking route to certain places in the world in addition. I’d like to have both IP working in the mean time make y.y.y.y the default IP. My operating system is CentOS 7.
I would like to achieve the goal of:
1. Add y.y.y.y to the system
2. Make y.y.y.y the default IP, if seen from outside world.
3. Keep the primary x.x.x.x IP available and connected just in case for failover.
So here is how I did it:
- Copy from ifcfg-eth0 to ifcfg-eth0:1 and change ifcfg-eth0:1 file in /etc/sysconfig/network-scripts
- Modify ifcfg-eth0 file with DEFROUTE=no
- Add a static route to make sure. Create a file route-eth0 in /etc/sysconfig/network-scripts
- Restart network service
- Confirm your IP and route
BOOTPROTO=none DEFROUTE=yes DEVICE=eth0:1 GATEWAY=y.y.y.1 HWADDR=be:ef:be:ef:be:ef IPADDR=y.y.y.y IPV6INIT=no NETMASK=255.255.255.0 ONBOOT=yes TYPE=Ethernet USERCTL=no
Here BOOTPROTO must be none, make sure you keep the MAC address the same as ifcfg-eth0 and replace the values I obfuscated.
default via y.y.y.1 dev eth0:1
systemctl restart network
# confirm IP: ip a # confirm route: ip ro
And your VM’s default IP to the outside world should be y.y.y.y now.