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.

1 comment:

Newport Beach Movers said...

Great blog I enjoyed readding