How to configure wifi from the commandline

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

How to configure wifi from the commandline

#1 Post by tempestuous »

Puppy's Network Wizard is one of the best in the business. It supports all currently available Linux wifi drivers including the unconventional linux-wlan-ng (prism2) drivers, plus ndiswrapper. And it fully supports WPA & WPA2 encryption via wpa_supplicant, even with the Ralink drivers, which out-of-the-box are not normally compatible with wpa_supplicant.

In a DistroWatch review of Puppy 3.00 http://distrowatch.com/weekly.php?issue=20071008#review
Susan Linton said this -
The network wizard requires several steps and clicking back and forth, but it works even with Wi-Fi Protected Access (WPA). I've tested maybe three distros with graphical network configurations that actually work for my chip. It's an amazing accomplishment.
But it's worth knowing the commands that operate behind the Wizard, especially if you need to troubleshoot a problem, or you have an unconventional setup.
First it's worth knowing what module (driver) is being used for your wifi device. The correct module is NOT determined by the manufacturer of the wifi adaptor, but by the CHIPSET contained within the wifi adaptor.
From version 2.12 onwards, Puppy Linux includes EXTENSIVE wifi driver support, including many Linux drivers written by independent development projects not aligned with the official Linux kernel.

For wifi chipsets not supported by a native Linux driver, Puppy also includes ndiswrapper, which will "wrap" a Windows driver. Obviously, you must supply the Windows driver files.
ndiswrapper is a workaround solution, but sometimes it's the ONLY solution.

Usually, Puppy will automatically detect your wifi device, and load the suitable driver from its "zdrv" compressed driver collection.
Run this command to see which modules are currently loaded

Code: Select all

lsmod
When a wifi module loads, it creates a network interface, which will be called "eth0" "wlan0" "ra0" "ath0" or "rausb0".
But if you also have an ethernet interface, this has probably taken the interface name "eth0" so the wifi interface will be "eth1".
First check that your wifi module has created an interface, with these 2 commands

Code: Select all

ifconfig -a

Code: Select all

iwconfig
For the sake of this example, let's assume your wifi interface is "eth1".
It's often necessary to "bring up" the interface unconfigured with this command

Code: Select all

ifconfig eth1 up
PART 1: WEP encryption.
(To configure for WPA encryption, see PART 2.)

To configure for WEP encryption -

Code: Select all

iwconfig eth1 essid MY_ESSID
iwconfig eth1 key open 1234567890
iwconfig eth1 mode managed
You will often see reference to these 3 parameters, essid/key/mode, being used within a single iwconfig command instead of 3 separate commands, but apparently the configuration is more reliable when the parameters are run separately.
Obviously replace "MY_ESSID" with your SSID, and "1234567890" with your WEP encryption key - as hexadecimal digits.
If you want to use your WEP password (ASCII string) instead of the true WEP hex key, then you must use the s: prefix. In this case the 2nd command would be -

Code: Select all

iwconfig eth1 key open s:MY_WEP_PASSWORD
And if your password contains spaces, you should enclose it in quotation marks.

Most wifi routers use "open" WEP authentication, but it could be "restricted", in which case the 2nd command should be

Code: Select all

iwconfig eth1 key restricted 1234567890
Or if your router has no encryption, the 2nd command should be

Code: Select all

iwconfig eth1 key off
Now to obtain an automatic IP address (DHCP)
for Puppy 3.x and earlier -

Code: Select all

rm /etc/dhcpc/*.pid
dhcpcd -t 30 -h puppypc -d eth1
for Puppy 4.0 onwards, the version of dhcpcd is different, thus -

Code: Select all

rm -f /var/lib/dhcpcd/*.info
rm -f /var/run/*.pid
dhcpcd -t 30 -h puppypc -d eth1
If this dhcpcd command fails, try it with extra parameters which avoid any use of the new logic for ipv6-compatible Client ID, like this -

Code: Select all

dhcpcd -I '' -t 30 -h puppypc -d eth1
That's hyphen, capital i, space, apostrophe, apostrophe (not quotation marks). Thanks to rerwin for this information.

Or to obtain a static IP address,
modify /etc/resolv.conf to include your nameservers, then

Code: Select all

ifconfig eth1 192.168.0.xx broadcast 192.168.0.255 netmask 255.255.255.0
route add default gw 192.168.0.1 eth1
Obviously replace the appropriate IP addresses.

Puppy contains an alternative wifi configuration utility, RutilT. This is more than just a script, it's a full application, and may be useful if the Network Wizard fails, especially at the last point of setup; acquiring an IP address.
But RutilT supports WPA encryption ONLY with Ralink wifi drivers (for which RutilT was originally written) and even then, only the basic WPA/PSK-TKIP variant.
Last edited by tempestuous on Tue 08 Jul 2008, 09:27, edited 3 times in total.

jonyo

#2 Post by jonyo »

Last edited by jonyo on Tue 05 Feb 2008, 21:28, edited 2 times in total.

raffy
Posts: 4798
Joined: Wed 25 May 2005, 12:20
Location: Manila

excellent

#3 Post by raffy »

Thanks! An excellent HowTo from an esteemed developer for Puppy Linux. This will be useful for inclusion in Puppy Linux manuals.

Recently, I experimented with a simple user-editable script for activating wifi in a simple network setup using only ESSID. The example device is D-Link USB DWL-G122 with driver rt2570.

Code: Select all

#!/bin/sh
# Edit this file to input your own WiFi values
# then save and click to get your WiFi working!
# The file is in /root (open /root via Menu - Files - Rox)

####################################################################
# change rt2570 below to the name of your wifi chip

modprobe rt2570
sleep 5 # give it some time

####################################################################
# "rausb0" is for USB wifi device; use "ra0" if it is an internal device

ifconfig rausb0 up

####################################################################
# now start it - change "rausb0" to "ra0" if needed
# also change "linksys" to the essid of your wifi network

iwconfig rausb0 essid linksys

####################################################################
# clear the dhcpc folder (nothing to change here)

rm /etc/dhcpc/dhcpcd-eth0.pid 2>/dev/null #clear stale files
rm /etc/dhcpc/dhcpcd-eth0.cache 2>/dev/null #ditto
rm /etc/dhcpc/dhcpcd-eth0.info 2>/dev/null #ditto

####################################################################
# automatically get an IP address
# change "rausb0" to "ra0" if needed

dhcpcd -t 20 rausb0
(As to Jonyo, that could help. But note that Puppy was described as "amazing" in the Ubuntu forum: http://ubuntuforums.org/showthread.php?t=281922 )
Puppy user since Oct 2004. Want FreeOffice? [url=http://puppylinux.info/topic/freeoffice-2012-sfs]Get the sfs (English only)[/url].

Vettephil
Posts: 40
Joined: Mon 15 Oct 2007, 17:49

#4 Post by Vettephil »

Here is my script for Puppy 3.00 Retro with a Netgear Wireless USB adapter:

Code: Select all

#!/bin/sh
modprobe r8187
sleep 5s
ifconfig wlan0 up
sleep 10s
iwconfig wlan0 essid PWB
iwconfig wlan0 key off
iwconfig wlan0 mode managed
rm /etc/dhcpc/*.pid
dhcpcd -t 30 -h puppypc -d wlan0
ifconfig
iwconfig

Works like a charm - thanks for the command line info!
-PHIL

jprsa
Posts: 14
Joined: Mon 05 Nov 2007, 17:23

#5 Post by jprsa »

hi, im using a dell inspiron b120 laptop. the wifi pci uses bcm43xx but i can't seem to get puppy 3.0 to connect to my belkin router.

normally, when i scan for wifi networks using the network wizard, it sees my essid but i can't get an ip via dhcp. i tried using a wep key and i tried it without a wep key. both times failed.

i followed your instructions but i still get the same problem..

can i request for some assistance ?

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#6 Post by tempestuous »

See rarsa's comments about the bcm43xx module
http://www.murga-linux.com/puppy/viewtopic.php?t=22459

tlcstat
Posts: 87
Joined: Mon 29 Oct 2007, 00:56
Location: SW Virginia mountains

Getting a IP with the bcm43xx

#7 Post by tlcstat »

Greetings, jprsa
If you have the Dell with broadcom try this.
Open /etc/resolv.conf and enter your Nameserver info, should look like this
Nameserver xx.xx.xx.xx
Nameserver xx.xx.xx.xx

Then set your card up for a static Ip. Don't know about the belkin but most routers want a static ip above 100 such as
192.168.1.100 or 192.168.0.100 or what ever the address is on your system. If there is other users on the network use a higher number so it doesn't create a conflict on the network.like 192.168.1.107.
I also suggest you use the Windows drivers with Ndiswrapper on the Dell. The bcm43xx driver is buggy. It will log in sometimes and not others. If you have a question about this post send me a PM.
Thanks
tlcstat

jprsa
Posts: 14
Joined: Mon 05 Nov 2007, 17:23

#8 Post by jprsa »

thanks for your replies,


unfortunately, i already tried doing the rmmod bcm43xx and modprobe bcm43xx commands in the terminal but i still could not get an ip from my dhcp server.

i also tried using a static ip but i still could not connect. pinging my router results in network not found.


anyway, i'll retry everything, hopefully i will get lucky.

jprsa
Posts: 14
Joined: Mon 05 Nov 2007, 17:23

#9 Post by jprsa »

finally got my puppy online!

i did have to rmmod bcm43xx. from the network wizard, i loaded a different version of the driver. (windows version bcmwl5.inf)


thanks for the help!!!!

i just wish the 3.01 and higher will have this installed automatically.

tlcstat
Posts: 87
Joined: Mon 29 Oct 2007, 00:56
Location: SW Virginia mountains

Skip loading module

#10 Post by tlcstat »

Greetings,
I wanted to blacklist the bcm43xx but it didn't show up in the blacklist wizard. So, did this
open, /etc/rc.d/modulesconfig
Put your module at the end of the SKIPLIST. (should be at the bottom)
Just need to make sure there is a space between the module name and the quote mark.
That pestky driver will be gone!

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#11 Post by tempestuous »

PART 2: WPA encryption.

For WPA encryption the "iwconfig" utility cannot be used at all. Instead, the "wpa_supplicant" utility is needed, and this is the utility which is used by Puppy's Network Wizard to configure WPA connections.

Exception:
Ralink drivers in Puppy versions older than ver 4.1 can be set up for WPA encryption with unique "iwpriv" commands. See -
"PART 3: WPA encryption with Ralink devices"
http://www.murga-linux.com/puppy/viewto ... 339#159339

wpa_supplicant needs to have a "-D" (driver) parameter specified, depending on which wifi driver is being used;

Compatible drivers using the "hostap" parameter:
hostap

Compatible drivers using the "ipw" parameter:
r8180
r8187

Compatible drivers using the "wext" (generic) parameter:
acx
ath5k
ath_pci
b43
b43legacy
bcm43xx
ipw2100
ipw2200
ipw3945
iwl3945
iwl4965
libertas_cs
libertas_sdio
ndiswrapper
p54pci
p54usb
rndis_wlan (Broadcom USB)
rt2400pci
rt2500pci
rt2500usb
rt2860sta
rt2870sta
rt61pci
rt73usb
rtl8180
rtl8187
usb8xxx
zd1211
zd1211b
zd1211rw

Compatible drivers using the "ralink" parameter:
rt61
rt73

INSTRUCTIONS
Use Geany to modify the WPA configuration file to include your SSID and Personal Security Key (PSK).
Puppy already contains 2 different configuration files;
/etc/network-wizard/wireless/wpa_profiles/wpa_supplicant.conf - for WPA encryption
/etc/network-wizard/wireless/wpa_profiles/wpa_supplicant2.conf - for WPA2 encryption

As an example, let's assume your wifi driver is the ipw2200 (so the -D parameter will be "wext") and this driver has created the network interface "eth1", and your wifi router is set for WPA2 encryption. First you must load your driver if Puppy has not automatically done so already

Code: Select all

modprobe ipw2200
It's often necessary to "bring up" the interface unconfigured

Code: Select all

ifconfig eth1 up
Remove stale wpa_supplicant file if it exists

Code: Select all

rm /var/run/wpa_supplicant/*
Start wpa_supplicant with debugging enabled (-dd) in case of problems

Code: Select all

wpa_supplicant -i eth1 -D wext -c /etc/network-wizard/wireless/wpa_profiles/wpa_supplicant2.conf -dd
wpa_supplicant may take about 30 seconds to negotiate the connection.
Hopefully you will see a connection reported, then you can open a second console and proceed to obtain an IP address (DHCP).
It's possible to background the wpa_supplicant process in order to keep using the same xterminal by adding "-B" to the command
... but do this only once you know that the wpa_supplicant command is successful, because once backgrounded you won't see any error messages.

Now for DHCP with Puppy 3.x and earlier -

Code: Select all

rm /etc/dhcpc/*.pid
dhcpcd -t 30 -h puppypc -d eth1
for Puppy 4.0 onwards, the version of dhcpcd is different, thus -

Code: Select all

rm -f /var/lib/dhcpcd/*.info
rm -f /var/run/*.pid
dhcpcd -t 30 -h puppypc -d eth1
If this dhcpcd command fails, try it with extra parameters which avoid any use of the new logic for ipv6-compatible Client ID, like this -

Code: Select all

dhcpcd -I '' -t 30 -h puppypc -d eth1
That's hyphen, capital i, space, apostrophe, apostrophe (not quotation marks). Thanks to rerwin for this information.

or to obtain a static IP address,
modify /etc/resolv.conf to include your nameservers, then

Code: Select all

ifconfig eth1 192.168.0.xx broadcast 192.168.0.255 netmask 255.255.255.0
route add default gw 192.168.0.1 eth1
Obviously replace the appropriate IP addresses.
Last edited by tempestuous on Mon 21 Mar 2011, 23:57, edited 8 times in total.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#12 Post by tempestuous »

PART 3: WPA encryption with Ralink devices (pre-Puppy 4.1 ONLY)
Updated Aug 7 2008
From kernel version 2.6.23 on, there is a completely new range of Ralink drivers called "rt2x00" series. These drivers use conventional WPA configuration using the "wext" -D parameter with wpa_supplicant. Refer to instructions earlier in this thread.

But the older "enhanced legacy" Ralink drivers have native support for WPA encryption without the need for wpa_supplicant.
Specifically these drivers are; rt2500, rt2570, rt61, rt73.

INSTRUCTIONS - let's assume your driver is rt61, and your network interface is "ra0"
(the USB drivers, rt2570 and rt73, create an interface called "rausb0").
First load your driver if Puppy has not automatically done so already

Code: Select all

modprobe rt61
It's often necessary to "bring up" the interface unconfigured

Code: Select all

ifconfig ra0 up
Now here are the critical WPA configuation commands:

Code: Select all

iwconfig ra0 mode managed
iwpriv ra0 set AuthMode=WPAPSK
iwpriv ra0 set EncrypType=TKIP
iwconfig ra0 essid "MY_ESSID"
iwpriv ra0 set WPAPSK="MY_SECRET_PASSPHRASE"
iwconfig ra0 essid "MY_ESSID"
Obviously replace "MY_SECRET_PASSPHRASE" with your Personal Security Key (PSK) and "MY_ESSID" with your SSID.
Notice that the iwconfig command is run twice, but when a 64 character hex string is used, the first iwconfig command may be omitted.

If your wifi router uses WPA2 encryption (not WPA) then the "EncrypType" value is different -

Code: Select all

iwpriv ra0 set EncrypType=AES
Now for DHCP with Puppy 3.x and earlier -

Code: Select all

rm /etc/dhcpc/*.pid
dhcpcd -t 30 -h puppypc -d ra0
for Puppy 4.0 onwards, the version of dhcpcd is different, thus -

Code: Select all

rm -f /var/lib/dhcpcd/*.info
rm -f /var/run/*.pid
dhcpcd -t 30 -h puppypc -d ra0
If this dhcpcd command fails, try it with extra parameters which avoid any use of the new logic for ipv6-compatible Client ID, like this -

Code: Select all

dhcpcd -I '' -t 30 -h puppypc -d ra0
That's hyphen, capital i, space, apostrophe, apostrophe (not quotation marks). Thanks to rerwin for this information.

or to obtain a static IP address,
modify /etc/resolv.conf to include your nameservers, then

Code: Select all

ifconfig ra0 192.168.0.xx broadcast 192.168.0.255 netmask 255.255.255.0
route add default gw 192.168.0.1 ra0
Obviously replace the appropriate IP addresses.

Puppy contains an alternative wifi configuration utility, RutilT, which was originally written specifically for Ralink wifi drivers. It should be possible to use RutilT to configure WPA connections with the older Ralink drivers.


PART 4: Troubleshooting, encryption problems

You can see from the instructions so far that encryption, either WEP, WPA, or WPA2, adds an extra layer of complexity to the setup.
It makes sense, therefore, that during initial setup and testing it's a good idea to disable encryption at your wifi router. Once you have successfully established a working wifi connection you can then re-enable encryption, and add the extra setup parameters related to encryption.
In many instances, wifi problems are directly linked to encryption issues.

A common cause of these problems is that encryption requires some additional cryptographic modules to be loaded. Sometimes the wifi modules (which are already loaded) will automatically load the extra modules, but sometimes not. The solution is quite simple; manually load the required modules.
for Puppy version 2.x
ieee80211_crypt_wep
ieee80211_crypt_ccmp
ieee80211_crypt_tkip
arc4
aes
crc32c
michael_mic (only for the ipw2100/ipw2200 modules)

for Puppy version 4.1.x and 4.2.x
ieee80211_crypt_wep
ieee80211_crypt_ccmp
ieee80211_crypt_tkip
arc4
ecb
cbc
crypto_blkcipher
aes_generic
crc32c
michael_mic (only for the ipw2100/ipw2200 modules)

for Puppy version 4.3.x and 5.x
lib80211_crypt_ccmp
lib80211_crypt_tkip
lib80211_crypt_wep
arc4
ecb
cbc
aes_generic
crc32c

Some wifi modules do not use generic cryptographic modules, but have unique encryption-related modules. For example, the ath_pci (MADWiFi) module depends on the wlan_wep module.
Last edited by tempestuous on Mon 21 Mar 2011, 23:58, edited 11 times in total.

User avatar
davids45
Posts: 1326
Joined: Sun 26 Nov 2006, 23:33
Location: Chatswood, NSW

#13 Post by davids45 »

G'day Tempus,
Had a go last night with your WPA advice above, on my RALINK2500 usb in-built wifi that I was having trouble connecting using the wizard in 3.01. The wizard in 2.17 works perfectly on my WPA managed network for both my desktops having these in-built RALINK 2500 usb wifis.
Wizard 3.01 had said the rt2570 driver did not support WPA and would only offer me WEP.
I tried commanding with the rt73 usb driver and stipulating rausb0 (based on the 2.17 success) but got an error when I reached "iwpriv...set...." along the lines that "set" was an invalid command.
Nonetheless I kept going and got some sort of connection to somewhere (blinky started up).
I thought your two iwconfig "might (?) be needed in rare cases" lines applied to my computer set-up. I typed them in and got no error messages.
The final iwconfig output was a RT2500usb interface with my correct ssid but a missing "NickName" variable.
I'll try again tonight, but can you clarify the "set" error?

RutilT - should it respond when I have my RT2500 wireless working with 2.17 through my WPA network? I thought it only could see WEP or Open networks? But you say it will monitor RALINK/WPA set-ups, but only these for WPA? I had not been able to get anything set up here with RutilT and WPA. I only recall seeing WEP during goes with RutilT set-up.

Thanks for all your help,

David S.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#14 Post by tempestuous »

Oops, I just realised that I should have made it clear that the Puppy Network Wizard uses wpa_supplicant for WPA configuration.
I have amended earlier instructions just now.

With your particular Ralink device in Puppy 3.01 you have 2 main options, with several sub-options:

A. unload the rt2570 module, and load the rt73 module instead, like this

Code: Select all

rmmod rt2570
modprobe rt73
Don't assume that your interface name is "rausb0". I think that more recent versions of the rt73 driver (and the rt2570 driver) now create the more conventional interface "wlan0".
Run "ifconfig -a" to check. Then:

A1. Use the Network Wizard. The rt73 driver is compatible with wpa_supplicant so the Wizard should now work.

A2. Or if you prefer to run commands manually, use the wpa_supplicant commands explained in PART 2.

A3. If your wifi access point uses WPA, not WPA2, then you could use the iwpriv commands explained in PART 3, or you could use RutilT.

B. leave the rt2570 module loaded, then:
B1. Use iwpriv commands explained in PART 3, but again, don't assume that your interface name is "rausb0".

B2. Use Rutilt, which is effectively the same as B1.

tempestuous
Posts: 5464
Joined: Fri 10 Jun 2005, 05:12
Location: Australia

#15 Post by tempestuous »

PART 4: ad-hoc wifi connections, October 2009

ad-hoc is a peer to peer network connection. There's no master station, so there's no management of network communication. Multiple peers can join the same ad-hoc network, but network communication becomes more difficult as more peers join, since no one gives permission to talk.

ad-hoc mode should not be confused with mesh networking!

I have successfully established an ad-hoc wifi connection under Linux a few years ago using the prism2_usb driver, but wifi drivers have changed significantly since the recent introduction of the underlying mad80211 wifi stack, so the following information is theoretically correct, but untested by me.

When a Linux wifi driver loads, it defaults to "station" (managed) mode. To change the mode to ad-hoc (or any other mode) you must first bring down the interface, as such -

Code: Select all

ifconfig wlan0 down
Now you can change the mode to ad-hoc -

Code: Select all

iwconfig wlan0 mode ad-hoc
Now the interface can be brought up (made active) again -

Code: Select all

ifconfig wlan0 up
Now let's say you want to create an adhoc connection, using the ESSID (wifi network identifier) "pup2pup" and a WEP encryption key (in hex form, not alphanumeric) of "1234567890". Do this -

Code: Select all

iwconfig wlan0 channel 6
(both ad-hoc peers must select the same channel)

Code: Select all

iwconfig wlan0 essid pup2pup
iwconfig wlan0 key 1234567890 restricted
Now each ad-hoc peer must select an IP address on the same subnet -

Code: Select all

ifconfig wlan0 192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0
I chose 192.168.0.2 to deliberately avoid the common IP address used by routers: 192.168.0.1
Your other ad-hoc peer should select something like 192.168.0.3
It's possible, but somewhat overcomplicated, to have one peer act as a DHCP server and the other peer acquire an automatic IP address.

It's possible to use WPA encrytion instead of WEP by replacing the "iwconfig wlan0 key ..." command with a wpa_supplicant command, but I haven't bothered to investigate this. And given that most ad-hoc connections are of a temporary nature, WPA encryption doesn't seem a vital requirement to me.
Last edited by tempestuous on Thu 29 Oct 2009, 09:58, edited 1 time in total.

User avatar
davids45
Posts: 1326
Joined: Sun 26 Nov 2006, 23:33
Location: Chatswood, NSW

#16 Post by davids45 »

G'day 'stu',
Thanks for your continued advice.
I did have another play last night trying wlan0 in place of rausb0 but got much the same result with your original code lines.
An extra Blinky appeared (eth0 is there and OK) but nothing wifi actually working.

However while later adding an sfs to my frugal /mnt/home, I noticed the 'system start' tool for doing this also has a black-listing capability for 'de-fault' drivers that are not suitable (= "the-fault drivers"??). So, using this, I stopped rt2570 from loading and added "ndiswrapper" as a to-be-loaded driver. On re-starting the 'puter, and then the network wizard, there was no pre-loaded default wifi network driver and I was able to click the ndiswrapper tab and link to my XP rt2500 inf file without error messages, or 'no new network' boxes when then testing with the wizard. So I had a working WPA wireless network. And it was registering on RutilT which I had thought was only for WEP systems.

The big test was this morning with a cold re-start. Having two minutes** before fleeing to work, had time to start-up, see the two network blinkies, use RutilT to check the wireless blinky was my network (and not one of the neighbours' open systems), check my email, then close down. So, success!

Thanks again,
David S.

**do that with Windows!

nobles
Posts: 9
Joined: Wed 12 Dec 2007, 15:55
Location: Winnipeg, Canada

#17 Post by nobles »

I edited /etc/wpa_supplicant.conf and followed the commands in Part 2 and did get WPA working with my DLink WPA-PSK router but I had to start another terminal session to enter the dhcpcd command as the wpa_supplicant command never successfully returned to the command prompt (although it obviously did its work as the encryption was setup). When I entered the dhcpcd command in the second terminal, I successfully got an IP address and I could browse the Internet. This was with a DLink Atheros based card using the ath_pci driver.

User avatar
yorkiesnorkie
Posts: 504
Joined: Mon 04 Jun 2007, 13:11
Location: George's Island

Re: excellent

#18 Post by yorkiesnorkie »

Hi,

I'm still a linux command line newbie. I can follow the command line stuff here but I'm not sure I quite understand what to do with a script. Where does the following script go? Is it just a file in /root? Do you call it anything special? Or, do I add it to one of the files?

Yorkiesnorkie
:-)

edit: I'm reading stuff on bash scripting...
raffy wrote:Thanks! An excellent HowTo from an esteemed developer for Puppy Linux. This will be useful for inclusion in Puppy Linux manuals.

Recently, I experimented with a simple user-editable script for activating wifi in a simple network setup using only ESSID. The example device is D-Link USB DWL-G122 with driver rt2570.

Code: Select all

#!/bin/sh
# Edit this file to input your own WiFi values
# then save and click to get your WiFi working!
# The file is in /root (open /root via Menu - Files - Rox)

####################################################################
# change rt2570 below to the name of your wifi chip

modprobe rt2570
sleep 5 # give it some time

####################################################################
# "rausb0" is for USB wifi device; use "ra0" if it is an internal device

ifconfig rausb0 up

####################################################################
# now start it - change "rausb0" to "ra0" if needed
# also change "linksys" to the essid of your wifi network

iwconfig rausb0 essid linksys

####################################################################
# clear the dhcpc folder (nothing to change here)

rm /etc/dhcpc/dhcpcd-eth0.pid 2>/dev/null #clear stale files
rm /etc/dhcpc/dhcpcd-eth0.cache 2>/dev/null #ditto
rm /etc/dhcpc/dhcpcd-eth0.info 2>/dev/null #ditto

####################################################################
# automatically get an IP address
# change "rausb0" to "ra0" if needed

dhcpcd -t 20 rausb0
(As to Jonyo, that could help. But note that Puppy was described as "amazing" in the Ubuntu forum: http://ubuntuforums.org/showthread.php?t=281922 )

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#19 Post by Pizzasgood »

The only important thing is that you set it executable. You could right-click it and go to properties or permissions to do it, or from the commandline run
chmod 755 script_name
(if you aren't in the same directory as it, you need to include the path to the script rather than just its name)

As for naming, scripts sometimes end with a .sh extension, but that's optional. Very few scripts in Puppy use that. You can pretty much name them whatever you want, but it's best to choose something unique, especially if you put it in the path.

Where you put it is up to you. If it's something to run each boot, you might want to put it in /etc/rc.d/ and maybe name it starting in rc.<whatever> (but that doesn't affect anything).

One thing to keep in mind with placement is that if you put it in the path (/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, etcetera) you can run it by just typing it's name in the commandline, just like it's another application. Otherwise, you need to include the path to run it.


If you want it run every boot, you could add a line in /etc/rc.d/rc.local to run it (just type the name or path as appropriate on a blank line). Another method is to add an
if [ "$1" = "start" ]; then
to the beginning (after the #!/bin/sh part though), and a
fi
to the end, then place it in /etc/init.d. Then it will be automatically run every time Puppy boots. (The reason for the changes is because Puppy runs ever executable file in that directory with the "start" parameter on boot, and with the "stop" parameter on shutdown. As it was, it would run the same no matter what parameters were passed in. For booting, that's fine. But you don't really want it getting run again when you try to shut down. You could actually add another section to bring down the wireless interface, but that's not necessary (might be handy if you needed to disable it though, like to unplug the USB dongle without locking up the machine).

Code: Select all

if [ "$1" = "stop" ]; then
ifconfig rausb0 down
rmmod rt2570
fi
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
yorkiesnorkie
Posts: 504
Joined: Mon 04 Jun 2007, 13:11
Location: George's Island

Awesome Response

#20 Post by yorkiesnorkie »

Hi Pizzasgood,

Thanks for the detailed reply. Its awesome! That's exactly the information I was looking for to connect the dots. This stuff is very interesting I might add. While not a programming expert, I can see the potential to tinker with the inner workings and get it working the way I want.

So now I have to edit Raffy's script to fit my situation. I also have a choice to make, whether to run it myself whenever I want it to connect, or to have it run automatically. Hmmm... Well I'll definitely take a run at this because it would be nice to have it work on startup since the first thing I do usually is check the mail.

Until later!

Yorkiesnorkie
:-)

Post Reply