Linux Fu: Sharing Your Single WiFi

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.

24 thoughts on “Linux Fu: Sharing Your Single WiFi

  1. I had no idea this was possible: I thought you needed two wireless cards to hotspot, and have an old laptop with a pcmcia card in it just for this. Very cool that you found a way to get this working, and very useful.

    1. Your wifi card has to support concurrent mode, not every card does. Check `iw phy phy0 info` and search for “valid interface combinations”. I think i can configure mine to create 8 networks (i do have 3 currently in use) and 2048(?!) connections as a client on other networks simultaneously, it all has to be on the same frequency tho.
      valid interface combinations:
      * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1,
      total <= 2048, #channels <= 1, STA/AP BI must match

  2. The problem is the access portal right? You can’t complete the login page on the chromecast? Since most of those attribute portal completion with the device mac, wouldn’t an easier solution be to spoof the chromecast’s mac on your linux laptop, complete the login page, shut off the laptop wifi, then connect the chromecast to the network.

  3. I’m honestly not sure what would happen if you tried to bridge the two wireless networks adapters together. WiFi has that weird problem where it only tracks 3 MAC Addresses, and doing a multi-hop WiFi connection needs 4 MAC Addresses tracked to fully resolve the return route.

    1. Or use something like an Android streaming box or stick or anything else that can run a browser able tohandle the captive portal login part. Chromecast has its optimal use cases. IMHO, this isn’t one of them . This is a clever workaround, though.

  4. I’ve got a portable hard drive that has WiFi and a low power Linux capable chip inside, I used to use it up at camp for watching shows off a Plex server it could also run (couldn’t transcode but most files worked fine). That had the ability to both connect to and rebroadcast a WiFi connection, very useful as it meant all I needed to do to have a privately controllable Chromecast in my room was just to use the drives hotspot for my devices.

  5. Interesting setup. No extra hardware.

    I use an old phone connected to my laptop by USB.
    Phone connects to hotel wifi, VPN on laptop gets rid of double/triple NAT problem, and laptop wifi is AP (setup in network manager).

    1. I carry a GL.Inet Slate 750 S wherever I go, flashed with mainline OpenWrt. two independent WiFi adapters (2.4 and 5GHz) means you can have one connected to the hotel WiFi and the other as an AP, but OpenWrt does also support client and AP on the same interface if your hotel only offers 2.4GHz, and your devices are also only 2.4GHz (e.g. ESP8266/ESP32 haxoring).
      Laptop can join via WiFi or Ethernet, router can connect upstream via WiFi or Ethernet, as well as running VPN clients as needed.
      And running your own AP sidesteps any access points enforcing client isolation (one client may not talk to another client), which makes actually telling your Chromecast what to stream a bit more difficult!

      All of which ignores that the original premise of the article was not to require any additional hardware.

  6. I used to day dream about setting up a pi zero to do exactly this.

    But… then I bought an unlocked phone. After that I could re-share the WiFi connection or just share my cellular connection using just the built in features of the Android operating system. Not long after Verizon changed something in their settings and now my wife and daughter’s phones, which were purchased from Verizon and have not been unlocked can do it too! Even without paying extra for any sort of tethering service.

  7. I think any smartphone nowadays can do that. Redistribute WiFi (not Mobile Data). Or is this just a Samsung feature?
    Turn on WiFi.
    Turn off Mobile Data.
    Turn on Mobile Hotspot.
    Click Ok on info pop-up.

  8. Thank you lakinduakash and Al Williams for the write-up. This has saved my bacon in a hotel with wifi literally today. The instructions on Github are great, so thanks again lakinduakash!

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.