Showing posts with label wireless. Show all posts
Showing posts with label wireless. Show all posts

Tuesday, 13 January 2009

Tuning a Wi-Fi Router with Linux

Nowadays, with Wi-Fi broadband routers becoming the de-facto standard in the home, comes a new problem for people who live in cities: interferences between neighbouring wireless networks. This can lead to slow connections or even dropped connections. A few years ago it was not a problem, few people had Wi-Fi routers at home and if you had one your router would work great out of the box. Nowadays, everybody's got a Wi-Fi router at home, whether it be a traditional router or a phone that masquerades as one. Wi-Fi was designed to avoid interferences by being able to work on a number of frequencies and every single router allows you to choose what frequency to use by selecting a channel. In the UK, you will typically have the choice of a channel value between 1 and 13. Just go to the wireless settings area of your router administration page and you should be able to change the channel, as shown on this example from a Netgear router:

Netgear wireless settings screen, set to Channel 4

Netgear wireless settings screenshot

That's simple: change the value, ensure it's applied and, depending on the manufacturer, reboot the router. But what is a good value that will ensure a good connection? Well, it depends on your environment. As you want to avoid interferences, this value should be as far as possible from other routers in the range of your equipment. But how do you tell what channel other routers in your area use? The Linux wireless tools come to the rescue, and in particular the one called iwlist. If you have a Wi-Fi laptop running Linux, it will have this utility installed as standard. The basic command we want is:

$ iwlist [interface] scan[ning]

To do a full scan, we need to run it as root so we'll prepend sudo to it. It is not necessary to specify a network interface but you might as well do so to avoid scanning non-wireless adapters. On my laptop, the wireless interface is eth1 so here is what I obtain by running iwlist against it:

$ sudo iwlist eth1 scan
eth1      Scan completed :
          Cell 01 - Address: 02:1D:68:4B:6D:F6
                    ESSID:"BTOpenzone"
                    Protocol:IEEE 802.11bg
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:off
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s
                              11 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
                              48 Mb/s; 54 Mb/s
                    Quality=27/100  Signal level=-83 dBm  
                    Extra: Last beacon: 240ms ago
          Cell 02 - Address: 00:1D:68:4B:6D:F5
                    ESSID:"BTHomeHub-954D"
                    Protocol:IEEE 802.11bg
                    Mode:Master
                    Frequency:2.412 GHz (Channel 1)
                    Encryption key:on
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s
                              11 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s
                              48 Mb/s; 54 Mb/s
                    Quality=29/100  Signal level=-82 dBm  
                    Extra: Last beacon: 248ms ago

... and so on

Each Cell section provides the details of a wireless hub in range. For each of them, the line we are interested in is the one that start with the word Frequency. So, if we use grep to filter the data, we get:

$ sudo iwlist eth1 scan | grep Frequency
Frequency:2.412 GHz (Channel 1)
Frequency:2.412 GHz (Channel 1)
Frequency:2.412 GHz (Channel 1)
Frequency:2.427 GHz (Channel 4)
Frequency:2.442 GHz (Channel 7)
Frequency:2.442 GHz (Channel 7)
Frequency:2.462 GHz (Channel 11)
Frequency:2.442 GHz (Channel 7)

This shows that I am in range of 8 wireless hubs. The one I am using is the fourth one, set to use channel 4. But that's because I changed it yesterday. It used to be configured with its default setting, using channel 11, which was clashing with the one before last. In fact, running the command at different times, it appears that all routers in my area use channels 1, 7 or 11. With a possible set of channels between 1 and 13, there are 5 unused channels between 1 and 7, 3 between 7 and 11 and 2 above 11. So the best choice is halfway between 1 and 7: channel 4. And since I reconfigured the router to use that channel, speed has improved significantly and dropped connections have been a thing of the past.

Now, why router manufacturers don't design their products to be able to scan neighbouring wireless networks at start-up and choose a frequency that doesn't clash with other hubs, I don't know. By any means, leave the ability to power users to explicitly specify the channel but a little bit of automation would go a long way in making Wi-Fi easier for the average home user.

Update

After all this, I had to change the router's channel again earlier, as more access points were switched on during the evening. At one point, a full scan showed a grand total of 24 wireless networks! So I changed my router to channel 13 and it all seems fine so far. Methinks I'll have to do something about improving the range of that router. While I was at it, I also upgraded the firmware so we'll see if it makes a difference.

Sunday, 2 March 2008

Asus Eee PC, Nokia E65 and WPA Wireless Networks

My home wireless network uses WPA for security. When I received my Asus Eee PC, it could not connect to my wireless network complaining about the shared key being too long, which I found odd because all other devices connected fine. Then when I got my Nokia E65, it couldn't connect either but wouldn't tell me why.

Then, over the weekend and prompted by a friend, I decided to fiddle with the Eee PC and get it to connect to the wireless network. So, in an attempt to humour the machine, I changed the pass phrase on my network to something shorter. An lo and behold, the Eee connected! It could then ping all the machines on the network except the router it was actually connected to. As a result, it couldn't route any traffic outside the network so couldn't get on the internet. Checking the routing tables, everything looked fine. It could resolve any name into an IP address so it had nothing to do with the DNS. I thought there could be something dodgy with DHCP so I re-configured the interface manually... and it worked! Going backwards, I set it back to DHCP and... it worked fine, even though I didn't change anything compared to the first attempt. That's IT for you: sometimes, doing the same thing twice fails the first time and works the second, for no apparent reason.

Now all chuffed by my success with the Eee, I decided to try again with the Nokia E65. I first spent a good 20 minutes trying to find how to set up access points and being defeated by the completely non-intuitive menu system of the S60 operating system that runs on those phones. I then turned to the user manual (yes, I know, RTFM) which only marginally helped because said manual is riddled with mistakes and the relevant menu option mentioned did not exist. So I spent another 10 minutes finding out where the manual was wrong. I eventually found what I wanted and set up my access point. Of course, in keeping with the experience with the Eee, it failed to connect first time. The main difference was that the E65 just closed the browser without explanation rather than tell me what went wrong. But trying a second time it worked fine.

So there you go: shortening the WPA secret key means that all my wireless enabled devices can now connect to my home network (apart from the Nintendo DS but that's because it doesn't support WPA at all). Some might say that a shorter key means my network is less secure. Yes and no: considering the network doesn't advertise its SSID in the first place, that's two pieces of information you need to guess. And then, because I knew I was shortening the pass phrase, I took more time to think of something that would be more difficult to guess.

PS: Nokia, could you please ditch the poor excuse for an operating system called S60 and give use something intuitive and user friendly instead? Now that you've acquired Trolltech, could we have nice Qtopia based phones please?