Please replace 11.22.33 with your own common part of IP address range. This is just raw string comparsion so no subnet checking etc.
There is one problem I did not solve yet. The ARP cache. If you move VPS to another hardware node, you must wait about 10 minutes until ARP cache on the gateway is cleared. The gateway is not under my control so I can't clear the cache manually
File: /etc/vz/conf/vps.mount
#!/bin/bash
# This script source VPS configuration files in the same
# order as vzctl does
# if one of these files does not exist then something is
# really broken
[ -f /etc/vz/vz.conf ] || exit 1
[ -f $VE_CONFFILE ] || exit 1
# source both files. Note the order, it is important
. /etc/vz/vz.conf
. $VE_CONFFILE
if [ -z "$IP_ADDRESS" ]
then
# no IP for this container
echo "No IP address for this container"
exit 0
fi
for IP in $IP_ADDRESS
do
if `echo $IP | grep "11.22.33" 1>/dev/null 2>&1`
then
# this container uses our IP address range. Check ARP
if `arp -n | grep $IP 1>/dev/null 2>&1`
then
# command above return 1 if item is not found
echo "$IP is already in ARP table. Weird."
else
# IP is not in local ARP table. Add. it
echo "Adding $IP to ARP table"
arp -i eth0 -Ds $IP eth0 pub
fi
fi
done
exit 0
File: /etc/vz/conf/vps.umount
#!/bin/bash
# This script source VPS configuration files in the same
# order as vzctl does
# if one of these files does not exist then something is
# really broken
[ -f /etc/vz/vz.conf ] || exit 1
[ -f $VE_CONFFILE ] || exit 1
# source both files. Note the order, it is important
. /etc/vz/vz.conf
. $VE_CONFFILE
if [ -z "$IP_ADDRESS" ]
then
# no IP for this container
echo "No IP address for this container"
exit 0
fi
for IP in $IP_ADDRESS
do
if `echo $IP | grep "11.22.33" 1>/dev/null 2>&1`
then
# this container uses our IP address. Check ARP
if `arp -n | grep $IP 1>/dev/null 2>&1`
then
# IP is in local ARP table. Remove it
echo "Removing $IP from ARP table"
arp -i eth0 -d $IP
else
echo "$IP is not in ARP table. Weird."
fi
fi
done
exit 0