Centos – swapping IP addresses with another server in Linux quickly

centosip

I have a way of doing this, but not sure if its the best.

I have two servers, we'll call Server-old, and Server-new. both are running different versions of CentOS. (5.0, and 5.7) Both are also on different IP's in the same subnet, but other wise are running the same software, firewall rules, and configs. I am switching from Xen to VMWare for this host, and its easier to just build a new server..

Server-old gets lots and lots of traffic, both via static NAT routes, and direct to its ip (via other servers connected to the vpn)

To make things smoothly move over (since not everyone uses the DNS name) I need to swap the IP Addresses as quickly as possible, in the middle of the night when traffic is slower.

I am planning on editing both servers /etc/sysconfig/network-scripts/ifcfg-eth0 files and put their 'new' addresses in, opening up two ssh sessions:

  • Server-Old type in ifdown eth0; sleep 10; ifup eth0
  • Server-new type in ifdown eth0;ifup eth0

and then hit enter on the Server-old, then as fast as I can, hit enter on Server-new

I'm thinking this is about the fastest I can switch, without causing any IP address conflicts. Or is there a better way to swap them?

Best Answer

This is the fastest way if nothing comes in between. So my favorite would be to do it from a real console. It's bad when the network is down and you can't connect via ssh.