How to prevent duplicate IP addresses

I know an openvz just try to ping IP address before start the container, and if it is pings (already exists somewhere in the network), the container will not start. I can’t see the same function in LXC, so i think to write some simple script and use it with lxc.hook.pre-start - how do you think, is it good idea?

Yeah, that would work fine.

In general we tend to prefer DHCP for IP configuration, partly because it deals with that for you (both by tracking leases AND by pinging any address it wants to hand out).

1 Like

Hey, @stgraber ! Glad to see you again! :slight_smile:

Yeah, think so too. Wrote a small script:


for ip in "$@"; do
    ip=`echo $ip | cut -f1 -d'/'`
    ping -c1 $ip > /dev/null;

    if [ $? -eq 0 ]; then
        echo "/!\ $ip exists. Aborting container start." | tee >(logger -t 'LXC');
        exit 1;

Looks like it works! :slight_smile:

1 Like