Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ [1] 2 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Set network settings on boot, With a remastered DSL< Next Oldest | Next Newest >
friedgold Offline





Group: Members
Posts: 122
Joined: Mar. 2005
Posted: May 05 2005,13:14 QUOTE

I thought it would be handy to set your network settings at boot via a cheatcode. This is mainly for people with no dhcp server. To do this I edited /etc/init.d/knoppix-autoconifg as follows

find the section starting

Code Sample
if checkbootparam "nodhcp"; then
...


and change it to

Code Sample
if checkbootparam "nodhcp"; then
echo " ${BLUE}Skipping DHCP broadcast/network detection as requested on boot commandline.${NORMAL}"
else
NETDEVICES="$(awk -F: '/eth.:|tr.:/{print $1}' /proc/net/dev 2>/dev/null)"
for DEVICE in $NETDEVICES
do
echo " ${GREEN}Network device ${MAGENTA}$DEVICE${GREEN} detected${NORMAL}"
NETSETTINGS="$(getbootparam $DEVICE 2>/dev/null)"
if [ -n "$NETSETTINGS" ]; then
IP="$(echo "$NETSETTINGS" | cut -d , -f 1)"
NM="$(echo "$NETSETTINGS" | cut -d , -f 2)"
DG="$(echo "$NETSETTINGS" | cut -d , -f 3)"
NS="$(echo "$NETSETTINGS" | cut -d , -f 4)"
NETSETTINGS_ERR=""
for i in $IP $NM $DG $NS; do
[ -n "$i" ] && [ -z "$(echo "$i" | awk '/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/')" ] && NETSETTINGS_ERR="yes"
done
if [ -n "$NETSETTINGS_ERR" ]; then
echo " ${BLUE}Invalid network settings, skipping network configuration.${NORMAL}"
else
ifconfig $DEVICE $IP netmask ${NM:-255.255.255.0}  >/dev/null 2>&1
sleep 1
[ -n "$DG" ] && route add default gw $DG >/dev/null 2>&1
[ -n "$NS" ] && echo "nameserver $NS">/etc/resolv.conf
echo " ${GREEN}Using Static IP:${YELLOW} $IP${NORMAL}"
fi
else
trap 2 3 11
pump -i $DEVICE >/dev/null 2>&1 &
trap "" 2 3 11
sleep 1
echo " ${BLUE}(Backgrounding)${NORMAL}"
fi
done
fi


I then remastered as normal

You can then use the cheatcode eth0=ip,nm,dg,dns where ip is your IP address, nm your netmask, dg your default gateway and dns your dns server. Only the ip address is required, the rest is optional (i.e. you can use eth0=192.168.1.100 to get you network up, although without a gateway/dns server you won't be able to get on the internet). In theory if you have more than one network card you can use eth0=... eth1=... etc to set each one up.
Back to top
Profile PM 
cbagger01 Offline





Group: Members
Posts: 4264
Joined: Oct. 2003
Posted: May 05 2005,21:19 QUOTE

This is a good idea.

I assume that it works as designed.
Back to top
Profile PM 
friedgold Offline





Group: Members
Posts: 122
Joined: Mar. 2005
Posted: May 06 2005,20:12 QUOTE

Quote (cbagger01 @ May 05 2005,17:19)
This is a good idea.

I assume that it works as designed.

Well it works fine for me. Im sure it could be improved/tidied up though.

Does any one know how the best way to check if a string is a valid ip address?

[ -z "$(echo "$i" | awk '/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/')" ]

should check the string is in the form ###.###.###.### where the #'s are nos, but it doesn't rule out stuff like 999.999.999.999.
Back to top
Profile PM 
cbagger01 Offline





Group: Members
Posts: 4264
Joined: Oct. 2003
Posted: May 07 2005,03:18 QUOTE

In my world (rough, minimally functional script creator), if you don't follow directions and you type in stuff incorrectly, then you deserve to get the unpredictable results that are a consequence of your actions.

I guess this is what separates me from real programmers who take into account the moron factor.

I think that the new feature is good enough as-is, even if you don't do any idiot-proof error checking.

But error checking is cool too, if you know how to do it.
Back to top
Profile PM 
Fallen Kell Offline





Group: Members
Posts: 21
Joined: May 2005
Posted: May 27 2005,18:57 QUOTE

hmmm... trying to figure out what I did wrong. It didn't detect my network device and as such didn't do any of the setup by reading the info from the line.
Back to top
Profile PM 
6 replies since May 05 2005,13:14 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ [1] 2 >/
reply to topic new topic new poll
Quick Reply: Set network settings on boot

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code