Bash Scirpt to Change ip

Here in the days of DHCP running on everything from cable modems to knock off cisco switches, what do you do when DHCP fails to assign an address to a large multi-user LAN?

Instead of having a stroke, you implement this script in Ubuntu to auto assign an ip address. As it was designed specifically for fact that the LTSP projects DHCP-3d can not assign multiple networks DHCP leases without physical adapters being present.

 

#!/bin/bash
NETWORK=”192.168.2.”
START=”10″
END=”30″
PAUSE=”2″
MISSED=0
ROUTER=”254″
PATH=/bin/:usr/bin:/sbin:/usr/sbin:/usr/local/sbin

####Start Script

#take the start ip, make sure its less than end ip else add one
for (( ; $START < $END ; START += 1))
do
ping -c 1 -w 1 $NETWORK$START
if ping -c 1 -w 1 “$NETWORK$START” | grep “100% packet loss”
then
/sbin/ifconfig eth0:1 $NETWORK$START
/sbin/route add default gw $NETWORK$ROUTER eth0:1
/sbin/route del default gw 192.168.2.254
break
fi

 

Leave a Comment

Your email address will not be published.

Start typing and press Enter to search