I have a script running that will start up an interface with a new IP.

If the script comes up with an IP that is already in use i am in trouble.

Is it possible that the script set up the new Ip, detects that this IP is already in use and then check the next one, until it finds an ip that works ?

while [ "$I" != "256" ]
ifconfig eth0:1 $B.$I
# check here that IP is Ok !
let "I=I+1"

I cannot use DHCP.

  • 3
    Try a for loop: for I in {1..255} then you won't have to increment the variable yourself. – Dennis Williamson Apr 20 '10 at 12:15
  • Perhaps if you fully explained why you can't use DHCP for this, we could better advise you. – mfinni Apr 20 '10 at 14:07

You can use arping like this:

arping -D -I interface -c 2 ip_address > /dev/null

And check the return value ($?):

  • 0: no conflict
  • 1: conflict

You can execute it before the ifconfig as it does not need an IP address (being ARP). So no 'unpredictable' behaviour expected.

  • 1
    Be aware that there is no persistence here, if a server is rebooting or otherwise temporarily off the network, it will come back to find its static IP taken. – kmarsh Apr 20 '10 at 17:29

No, if you use an IP that's already in use, unpredictable behaviour will follow. Either your network or the other machine's network will cease to work, or will work randomly, etc. The right thing to do is use DHCP.


Make a mapping of all your new server MAC addresses and what IP you will assign them. Have the script find the MAC and look up its IP. You need only update the mapping table for each new server. You have to copy the script to each new server anyway, so copying the table also and updating it is no big deal.

If this sounds like a lot of work, congratulations, you have re-implimented DHCP, very poorly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.