Apr 20, 2011
83 Views
Comments Off on Bash Scirpt to Change ip

Bash Scirpt to Change ip

Written by

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.

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 your vote

0 points
Upvote Downvote

Comments

0 comments

Article Tags:
· ·
Article Categories:
Linux

Log In

Forgot password?

Forgot password?

Enter your account data and we will send you a link to reset your password.

Your password reset link appears to be invalid or expired.

Log in

Privacy Policy

Add to Collection

No Collections

Here you'll find all collections you've created before.