linuxvirtual-ip-address

Virtual IP failover on 2 Linux box


I have 2 Linux VM Box.

VM1 ip is 192.168.0.4 VM2 ip is 192.168.0.5

GW: 192.168.0.1, net mask: 255.255.255.0

1)I have added a virtual ip on VM1

ifconfig eth0:1 192.168.0.10 netmask 255.255.255.0 up

Then I can ping it successfully from my client

2)removed the virtual ip on VM1

ifconfig eth0:1 192.168.0.10 netmask 255.255.255.0 down

Then I can NOT ping it successfully from my client

3)Add the same virtual ip on VM2

ifconfig eth0:1 192.168.0.10 netmask 255.255.255.0 up

!!I failed to ping this ip!!

however 1-2 hours later, I can ping it successfully.


Solution

  • 3)Add the same virtual ip on VM2

    however 1-2 hours later, I can ping it successfully.

    Try flushing the ARP table on the client:

    ip neigh flush all dev eth0
    

    Also, I believe having the second VM send gratuitous ARPs after getting the new IP will solve the problem.