script to set interfaces, enjoy!

#!/bin/bash

if [ $# -lt 1 ] ; then
	echo "usage:"
	echo "${0##*/} subnet [subnet] [subnet]..."
	exit 1
fi

LASTNUM=`ifconfig eth0 | grep -o "inet addr:[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}" | cut -d'.' -f4`
LASTIFACE=`ifconfig | grep eth0 | tail -1 | cut -d' ' -f1 | cut -d':' -f2`

let CURIFACE=$LASTIFACE+1
for i in $*; do
	if [ $i -gt 255 ] ; then
		echo "input error: $*"
		exit 1
	fi
	IFACES["$i"]=$CURIFACE
	echo sudo ifconfig eth0:$CURIFACE 192.168.$i.$LASTNUM
	let CURIFACE++
done

echo -n "accept? (Y/n): "
read -n 1 ANSWER
if [ "$ANSWER" != "" ]; then echo; fi
if [ "$ANSWER" == "" ] || [ "$ANSWER" == "Y" ] || [ "$ANSWER" == "y" ];
then
	for i in $*; do
		CURIFACE=${IFACES[$i]}
		sudo ifconfig eth0:$CURIFACE 192.168.$i.$LASTNUM
		echo added subnet $i
	done
else
	echo nothing changed
fi

#ifconfig

 
howto/setinterface.txt · Last modified: 2008/08/13 10:51 by 192.168.11.59
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki