LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-12-2007, 01:31 PM   #1
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 37
switching between interfaces to use to access internet...the slackware way


Ok I've been looking at KNetworkManager, even tried to compile it and gave up on it and decided that I want to to this one the slackware way.
The thing is, I'm accessing 3 different networks with my laptop. Two are Wireless and one is wired.
I connect to the home wireless like this (this one is in rc.local):
Code:
/sbin/modprobe rt2500
ifconfig eht0 down
ifconfig wlan0 192.168.2.20 up
iwpriv wlan0 set AuthMode=WPAPSK
iwpriv wlan0 set EncrypType=TKIP
iwpriv wlan0 set WPAPSK=mypsk
route add default gw 192.168.2.1 wlan0
And then when I go to school I use RutilT to switch between ESSIDs. Not exactly the way I want it. And on another network I connect to a router via eth0.
The other wireless does not use any encryption and no passwords or anything. Don't ask me why, it's not my network and I use it only for highly needed information from the internet.
How would I do this and where do I begin?

Edit: Damn I'm stupid, can't even ask the right way :P

I would like that my laptop would use either one of these networks that are currently available.
I.e. when I'm at home it uses the specified info to connect to the router, and when I'm and school it would connect to the open wireless router at boot. But when I'm on a cable it would use the eth0 interface to connect.

Last edited by Tux-Slack; 11-12-2007 at 01:34 PM.
 
Old 11-12-2007, 02:30 PM   #2
acummings
Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 615

Rep: Reputation: 50
http://www.linuxquestions.org/questi...3/#post2933935

http://www.linuxquestions.org/questi...362/page2.html

--
Alan.
 
Old 11-12-2007, 05:26 PM   #3
Whiffle
LQ Newbie
 
Registered: Nov 2007
Posts: 7

Rep: Reputation: 0
I'd give wicd a shot. I've got it on my laptop and it works very nicely for what you want. In fact, I've disabled the rc.inet1 script entirely and replaced it with the wicd daemon and so far things are going quite smoothly. The wpa_supplicant templates that it comes with may not be suited to your needs, but you can always edit them so they do.
 
Old 11-13-2007, 12:41 PM   #4
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Original Poster
Rep: Reputation: 37
Well not exactly the slackware way, but it will do for some time until I find some time to do it the slackware way. Thank you both.
 
Old 11-13-2007, 02:29 PM   #5
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Rep: Reputation: 63
The Slackware way - here goes:

Code:
#!/bin/bash

#Determine SSID and Gateway IP.

if [ $1 = "home" ]; then
    NAME=******
    GWDSL=******
    RESOLV=resolv.conf.home
elif [ $1 = "work" ]; then
    NAME=******
    GWWORK=******
    RESOLV=resolv.conf.work
elif [ $1 = "down" ]; then
    /bin/echo ""
else
    /bin/echo "Usage: wlan {home|work|down}"
    exit 1
fi

#To bring up or down the interface.

if [ $1 != "down" ]; then
        if /sbin/lspci | grep Marvell > /dev/null; then
            /sbin/modprobe ndiswrapper
            /sbin/iwconfig $IF essid $NAME
        
        elif /sbin/lspci | grep AR5212 > /dev/null; then
            /bin/echo "Setting up Netgear WG511U adapter."
            /sbin/modprobe ath_pci countrycode=840 outdoor=0
            /sbin/iwconfig $IF essid $NAME
                
        elif /sbin/lsusb | grep 07b8:6001 > /dev/null; then
            /bin/echo "Setting up Hawking HWU54G adapter(zd1211 chipset)."
            /sbin/modprobe zd1211rw
            /sbin/iwconfig $IF essid $NAME
                        
        elif /sbin/lsusb | grep MA111 > /dev/null; then 
            /bin/echo "Setting up the Netgear MA111 adapter (prism2 chipset)."
/sbin/iwconfig $IF essid $NAME
            
        else
            /bin/echo "Wireless network adapter not found."
            exit 1
            
        fi      
fi

#Configure interface and gateway.

case $1 in
        home)
                /sbin/ifconfig $IF x.x.x.x netmask y.y.y.y
                /sbin/route add default gw $GWHOME
                ;;
        work)
                /sbin/ifconfig $IF x.x.x.x netmask y.y.y.y
                /sbin/route add default gw $GWTCC
                ;;
        down)
                #Bring down the wireless interface.
                /sbin/ifconfig $IF down
                
                #Remove device driver modules.
                if /sbin/lsmod | grep zd1211rw > /dev/null; then modprobe -r zd1
211rw; fi
                if /sbin/lsmod | grep ath_pci > /dev/null; then modprobe -r ath_
pci; fi
                if /sbin/lsmod | grep ndiswrapper > /dev/null; then modprobe -r 
ndiswrapper; fi
                
                exit 0
                ;;
        *)
                echo "Usage: wlan {home|work|down}"
                exit 1
                ;;
esac

#Set DNS addresses
cp /etc/$RESOLV /etc/resolv.conf

#Exit with no errors.
exit 0
You can copy this and modify to suit your adapter and access points. Mine is obviously setup for four different adapters (it's a laptop) and two access points. I also have static /etc/resolv.conf files that, as you can see, get copied to /etc/resolv.conf depending on the connection.
 
Old 11-13-2007, 02:40 PM   #6
BCarey
Senior Member
 
Registered: Oct 2005
Location: New Mexico
Distribution: Slackware
Posts: 1,639

Rep: Reputation: Disabled
Quote:
Originally Posted by Tux-Slack View Post
Well not exactly the slackware way, but it will do for some time until I find some time to do it the slackware way. Thank you both.
I guess I don't know what you mean by the "slackware way". One of the links provided suggested using two standard files (rc.inet1.conf and wpa_supplicant.conf) for all your configuration information, which would automatically bring up whatever network is reachable at boot, and using the standard rc.inet1 script (unmodified) should you need to change networks without rebooting. How much more "slackware way" can you get! CLI text editor based configuration and all !

Brian
 
Old 11-13-2007, 03:02 PM   #7
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Original Poster
Rep: Reputation: 37
BCarey I was talking about wcid. Those other two links I had only time to run through them on a rough scale.
Slackware way - Less gui is better. More CLI configuration editing is even greater.

dracolish: Thank you for your script.
One thing I don't get, you then manually run this script?

Last edited by Tux-Slack; 11-13-2007 at 03:03 PM.
 
Old 11-13-2007, 04:21 PM   #8
dracolich
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,274

Rep: Reputation: 63
Quote:
Originally posted by Tux-Slack
dracolish: Thank you for your script.
One thing I don't get, you then manually run this script?
Precisely. After saving the script using whatever name you want run chmod on it to make it executable and then use it like this:

su -c "scriptname home"

where scriptname is the name you saved it as, and home is one of the parameters defined in the script. Use su because the ifconfig, iwconfig and route commands need root permission.

Yours sounds simpler than mine. For example, only two adapters - one wired and one wireless. Something like this might work for you:

Code:
#!/bin/bash

#Determine SSID and Gateway IP.

if [ $1 = "home" ]; then
    NAME=******
    GWHOME=******
    RESOLV=resolv.conf.home
elif [ $1 = "school" ]; then
    NAME=******
    GWSCHOOL=******
    RESOLV=resolv.conf.school
elif [ $1 = "eth" ]; then
    NAME=******
    GWETH=******
    RESOLV=resolv.conf.eth
elif [ $1 = "down" ]; then
    /bin/echo ""
else
    /bin/echo "Usage: wlan {home|school|eth|down}"
    exit 1
fi

#To bring up or down the interface.

case $1 in
        eth)
                /sbin/ifconfig eth0 x.x.x.x netmask y.y.y.y
                /sbin/route add default gw $GWETH
                ;;
        home)
                /sbin/ifconfig wlan0 x.x.x.x up
                iwpriv wlan0 set AuthMode=WPAPSK
                iwpriv wlan0 set EncrypType=TKIP
                iwpriv wlan0 set WPAPSK=mypsk
                /sbin/route add default gw $GWHOME
                ;;
        school)
                /sbin/ifconfig wlan0 x.x.x.x up
                /sbin/route add default gw $GWSCHOOL
                ;;
        down)
                #Bring down the wireless interfaces.
                /sbin/ifconfig eth0 down
                /sbin/ifconfig wlan0 down
                ;;
        *)
                /bin/echo "Usage: wlan {home|school|eth|down}"
                exit 1
                ;;
esac

#Set DNS addresses
cp /etc/$RESOLV /etc/resolv.conf

#Exit with no errors.
exit 0
Again, modify it as necessary to suit your needs.

EDIT: After rereading your original post I see you're asking for a bit of automation. With this the best I can offer is to simply run the script before startx. If you call the script net then run a quick 'su -c net school' before startx or from an xterm.

Last edited by dracolich; 11-13-2007 at 04:27 PM.
 
Old 11-14-2007, 03:12 PM   #9
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Original Poster
Rep: Reputation: 37
I have just found an (untested) way of how to improve your script.
Use iwlist command to scan for ESSIDs. I know that in my case it will work...Or at least I think.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't access to internet after switching from.... binary_0011 Ubuntu 4 10-13-2006 01:34 PM
Unable to access the internet through firefox when switching from school to home jalsk Fedora 3 07-30-2006 08:41 AM
Mandrake is switching the eth1 and eth0 interfaces... how can I switch them back? LaptopLinux Mandriva 3 03-28-2005 09:23 PM
Switching networks and interfaces? mlg9000 Linux - Laptop and Netbook 0 11-17-2004 10:39 PM
xfce switching between graphical interfaces el_pajaro! Linux - Software 3 09-10-2004 12:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration