Saturday, 30 May 2020

Putting an idle WiFi router to use as a LAN-WLAN bridge

In the current situation I have time to do the little chores I promised myself to do.

One was to set up an unused WiFi router as an auxiliary access point. In parts of my abode, the WiFi signal from the main router isn't strong, and besides it only handles the older standard. I have a spare router which handles the latest WiFI standards which I decided to put to use.

You may ask at this point why not swap the unused router in? Two reasons, the old router has DD-WRT on it and I have a particular set up for it, and the new router has gigabit Ethernet ports so I can use it as an Ethernet switch at the same time, and not have to run another Cat-6 cable to that area. Finally I use the Internet more from the new location.

Note that this is not about setting up a WiFi relay. You can buy such devices off the shelf to boost the signal. This is using a spare WiFi router as a LAN-WLAN bridge so you need to have wired Ethernet already. It also doesn't matter what the front end of the router is, whether ADSL or cable, as we don't use it at all. So ignore any Ethernet ports that say WAN or Internet. We only use the ones that say LAN or Ethernet. Here's a typical back panel. We want the yellow interfaces.


These are the steps you need to do:
  1. Reset the router to factory settings.
  2. Connect to it with a computer, usually a laptop, at the factory IP address and login.
  3. Disable the DHCP server of the router.
  4. Change the LAN address of the router to a free IP address in your subnet that isn't in the dynamic range of the main DHCP server.
  5. Reconnect to the router at the new address.
  6. Set up the WiFi using the same SSID and passwords as your main router.
  7. Check tnat WiFi clients connect to your router.
  8. Backup the configuration to a file on your computer.
Let's go through each of the steps.

1. Reset the router to factory settings

Usually this is done by poking a paper clip into a recessed reset button on the back or bottom of the router.

2. Connect to it with a computer, usually a laptop, at the factory IP address and login

Connect with an Ethernet patch cable and access the web interface. You need to know the factory default IP address and login/password. The manual will tell you or it may be on a sticker on the router. Often the address iis 192.168.0.1. You could either let the laptop get an address by DHCP, but since you will need to change it in step 5, you might as well learn how to configure it to a static address. Change the admin password after you have logged in.

3. Disable the DHCP server of the router

Somewhere in the settings, probably advanced, is where you turn off the DHCP server of the router. This is so that it won't clash with the main router. In my case it wasn't sufficient to disable it. I also had to shrink the range to a small one or it would say illegal address at the next step.

4. Change the LAN address of the router

You need to assign the router a fixed address that is on your LAN but not in the DHCP range of the main router. Say your main router gives out addresses from 192.168.100.100 to 192.168.200.200. In this example .99 or .201 is available. After you have changed this, your laptop cannot reach the router, so proceed to:

5. Reconnect to the router at the new address

For this you can either change the IP address of your laptop's Ethernet interface, or switch to the main router's WiFi which will be on the same subnet. For the former you would take another address on your LAN, say 192.168.100.202. The router address you give to your browser is for the last example: http://192.168.100.201

6. Set up the WiFI using the same SSID and passwords as your main router

Otherwise your devices will be confused which one to log onto. Naturally you should use the same standard, which is usually WPA2-AES. At the point you may wish to choose the wireless channel for least overlap with your neighbours, but if you are close enough to the router, it's not as important as your signal will be stronger. For this tuning task there are various WiFi analysis apps.

7. Check that WiFi clients connect to your router

The router may have a page that shows the WiFi clients connected to it. You should see entries in it when your phone or tablet connects.

8. Backup the configuration to a file on your computer

Most routers have a web page where you can download a dump of the configuration so that you can restore it quickly if you ever do a factory reset again.

The other Ethernet ports of the router (usually 3 left after you have used one) can be used to plug in other wired devices. In this case I connected an existing desktop to a free port, using the router as an Ethernet switch.

That's it. Enjoy faster Internet access from your secondary location.

Wednesday, 13 May 2020

How to convert text from one charset to another within vim

Sometimes when you edit a file with vim it sees the extended characters and guesses the charset of the file. If it isn't UTF-8 it usually guesses Latin-1 or ISO8859 and displays (converted) on the message line. In the case of a file of mine that had Chinese characters encoded in GBK, when I tried to convert the contents in situ with:

:1,$! iconv -f GBK -t UTF-8

I ended up with a buffer displaying the Chinese characters correctly, but when trying to write it out, vim indicated an error. Trying to force the write with w! gave me the original file.

The trick is you have to tell vim that the charset has changed. Do:

:set fileencoding=utf-8

before you write and quit and all will be well. You can check the current encoding at any point with:

:set fileencoding