Linux Fu: Sharing Your Single WiFi [Hackaday]

View Article on Hackaday

If you are trying to build a router or access point, you’ll need to dig into some of the details of networking that are normally hidden from you. But, for a normal WiFi connection, things mostly just work, even though that hasn’t always been the case. However, I ran into a special case the other day where I needed a little custom networking, and then I found a great answer to automate the whole process. It all comes down to hotel WiFi. How can you make your Linux laptop connect to a public WiFi spot and then rebroadcast it as a private WiFI network? In particular, I wanted to connect an older Chromecast to the network.

Hotel WiFi used to be expensive, but now, generally, it is free. There was a time when I carried a dedicated little box that could take a wired or wireless network and broadcast its own WiFi signal. These were actually fairly common, but you had to be careful as some would only broadcast a wired network connection. It was more difficult to make the wireless network share as a new wireless network, but some little travel routers could do it. Alternatively, you could install one of the open router firmware systems and set it up. But lately, I haven’t been carrying anything like that. With free WiFi, you can just connect your different devices directly to the network. But then there’s the Chromecast and the dreaded hotel login.

Log In Pages and The Laptop Connection

Most public hotspots don’t just directly dump you to the Internet. Instead, they show you a captive page with some ads or maybe the network policy. They might want you to accept terms or put in some sort of ID like a room number. They might offer you upgraded service for a fee. However you do it, you have to click some button or buttons to get actually connected.

This is a problem for the Chromecast — the Google TV network adapter. Even though most hotels have a TV with an HDMI port accessible, you can’t get the Chromecast on a network where you need to log in through a portal page.

No problem. Just use your laptop to connect to the WiFi, then create a new access point to rebroadcast it as though it were your private WiFi. Connect your phone and Chromecast to that new network, and you can watch your favorite shows on the road. This might seem like a first-world problem, but we’ve seen many hotels now offer you a way to log in to things like your NetFlix or YouTube accounts from the hotel TV, but it isn’t widespread. At least, not yet.

What I wanted to do is possible with hostapd. However, it isn’t trivial since that program can do many things, not all of which we care about in this context.

Make it Simple, Stupid

There had to be a better way to solve this than fumbling with hostapd configurations after a long flight. There is and it is called linux-wifi-hotspot. It uses hostapd along with networking tools like iproute2, iptables, and dnsmasq, to create a hotspot with very little effort. It is worth noting that NetworkManager can also do this if you have two WiFi adapters. But, as far as I can tell, it doesn’t know how to put the AP on the same adapter as the incoming Internet connection.

I installed the program from a package and I had to install hostapd, too. There’s also a ppa for Ubuntu, or you can build it from source by following the instructions.

The interface to the program is relatively simple. You name your hotspot and provide a password. You can make it a tough one because you can have the program display a QR code that will let your phone, for example, hook right up to it.

The linux-wifi-hotspot user interface

The tricky part is where you select the interfaces. In the screenshot, you can see that the same wireless interface appears in both slots. Of course, it would be easy to create an AP to another network interface. Even NetworkManager can do that. However, when I ran the program, I could not select the same interface as the screenshot shows.  However, I could make the internet interface “lo” and that worked. I suspect this is because NetworkManager already controlled the WiFi, but your mileage may vary.

There are a few features inside the advanced section of the interface that are initially hidden, but I didn’t need to change any of those. There’s also a way to see a list of devices currently connected to the hotspot.

In addition to the GUI, you can control the program via the command line or even set up to start when the system first runs. I didn’t care about any of that for this project.

Does it Work?

It works! To be honest, though, it doesn’t have remarkable throughput. But it managed about 15-20 Mbps with a 100 Mbs upstream connection. That sounds bad, and it certainly isn’t great. But when you consider that you are sharing the WiFi adapter, it probably isn’t too bad, and it is sufficient to stream movies.

There are other options, of course. You can spoof the Chromecast mac address on your laptop long enough to log in. There are Ethernet adapters that connect to Chromecast if you can still find a hardline connection. Some of the captive portals put the authorized mac address in the URL and don’t check it again, so if you see that, you might try replacing your mac with the Chromecast’s and logging in. So, as always, there are plenty of options. But a quick way to spin up a hotspot from your laptop has a lot of versatility, even if you don’t care about connecting a streaming box.

The best way to do this would be to add a second USB WiFi adapter. In that configuration, you could also bridge with NetworkManager, so you might not need this software for that case.

Of course, something like this may not work with your exact setup. There are notes that it has some trouble with some 5 GHz adapters and some RealTeK adapters. There are workarounds, and you can read about them on the project’s web page.

If you have free access to WiFi and you can just log in, you are probably better off doing that. But if you have a router or a device like a Chromecast that won’t tolerate a sign on page, this is a handy way to beam access to as many of your devices as you like. If you are paying per connection, this might save you some money, too.

This doesn’t quite fall into the realm of a true network hack. If that worries you, you can probably roll your own VPN easily.