Re: Reconfiguring network on the fly
On Sat, 18 Feb 2006 07:20 am, Nigel Ridley wrote:
> To Switch Network Setups On The Fly (on reboot original setup is used):
> With the laptop already running (and configured using static ip) as root:
> # dhcpcd eth0 (this configures the nic to dhcp)
> # dhcpcd -k eth0 (to disconnect)
> # ifdown eth0
> # ifup eth0 (to get the static ip config working again).
>
> Hope this is of some use to others.
> If you know a better way then do share it :-)
>
Not better; but different: I wrote a small bash script which does this using
alternative interfaces files (same as those in /etc/network/interfaces); you
write one for each different networking situation, and place it in a folder
called ~/.profiles. I call the script in konsole using sudo (any root shell
would work I guess), and it asks me to pick which profile to use, then brings
up the appropriate interface. You can add new profiles as they are needed.
Here it is:
<begin>
#!/bin/bash
ethernet=(`mii-tool | gawk -F: '/link/ {print $1}'`)
wireless=(`iwpriv | gawk '/Available/ {print $1}'`)
profiles=~/.profiles
test=(`mii-tool $ethernet | grep "link ok"`)
echo "Enter a profile from the list below" ; echo
select profile in $( ls $profiles ) ; do
if [ ! -f $profiles/$profile ] ; then
echo
echo Huh? ; echo
else echo
echo $profile chosen ; echo
if [ "$test" ] ; then
echo Cable connected, using $ethernet ; echo
ifdown $ethernet $wireless
ifup $ethernet -i $profiles/$profile
elif [ "$wireless" ] ; then
echo Bringing up wireless interface $wireless ; echo
ifdown $ethernet $wireless
ifup $wireless -i $profiles/$profile
else echo "No networks available"
sleep 3
exit
fi
echo
echo Done
sleep 3
exit
fi
done
<end>
If anyone is interested, I've also written a much more elaborate (too long to
post) script that uses kdialog to present a GUI for managing networking
profiles like these and also wireless connections and other network stuff,
which I'd be glad to share.
John
Reply to: