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?
Make sure that that time on both servers is the same, set up a cron job to fire off at 2:00am (or whatever 'middle of the night' time you choose), and have it run:
then delete the cron job the next morning, or after it runs.
...more important than doing the OS-level IP plumbing quickly, you must also update the ARP protocol caches on all the devices on the LAN. If these two servers get most of their trafffic from, say, one outer-edge router, you can just blow the arp cache right after you re-plumb the IPs addrs. Packets (I'm presuming ethernet lan) flow around your LAN via ethernet addresses (which target the physical NICs on the wires), if you just replumb the IP addrs, your router and other devices will continue addressing packets to the wrong NICs for some period of time. (How long depends on how their ARP cache works.)
Also, some IP stacks won't let you plumb an IP address that already successfully RARP's (reverse ARP) on the LAN. So the cron automagic "network restart" suggestion is (in my opinion) likely to fail. When one box does the 'add' it may see the other box respond to the RARP. Meanwhile, the other box's cron job gets around to taking the IP out... train wreck.
Do it all by hand, from the consoles (bonus if you have a remotely accessible console server) it won't take but a few minutes.
If you're totally swapping the boxes, I'd also play ethernet plug shuffle... preconfigure the new one cabled into a switch (so the link is up) with nothing else on that tiny LAN. Then yank the ethernet plug from the old server, move the new server to the real LAN fabric, then blow ARP caches.
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.