Let it be ordering food or the daily ranting on Twitter, hands seek mobile phones over other devices. Living in a place where your phone laughs at you with an E on the top is a painful thing. So, why I’m in such a situation?
- All the mobile operator promises just doesn’t work inside my hostel.
- My university provides Wi-Fi only for laptops and sadly I have a MacBook Pro which can’t create access point from a Wi-Fi.
- My MacBook pro is too honest to allow me share Enterprise Wi-Fi over Bluetooth.
Missing out important texts and seeing windows users having mobile hotspot on touch of a button made me desperate to tweak my MacBook to share its Wi-Fi over to my phone. And this pretty much explains, why I made the following DIY setup to share Enterprise Wi-Fi on a MacBook.
1. Someone please be an Access point
Macbook’s Wi-Fi adapter can't act as both receiver and an access point. Access point is the device that creates the Wi-Fi network (Think of a hotspot). Macbook pro can't be connected to Wi-Fi network and create a Wi-Fi network at the same time. (Same as why you can't have wifi and hotspot turned on at the same time in your phone). This struck me for so long until I found my old ADSL modem lying around. Actually an ADSL modem is for a telephone network and it has nothing to do for me. However, mine has a router built in. (Ignore if the term ADSL modem doesn't make sense to you, think of it as a Wi-Fi hotspot and also it can connect devices over ethernet.). Thus, it can create a LAN with my phone on Wi-Fi and MacBook on Ethernet. And thus my MacBook can be connected to university Wi-Fi and my local Ethernet LAN at the same time.
Prepare the lab, it’s time to experiment.
Using the built in access point of the ADSL modem, I have my private LAN setup. Let me try to picture it below. In the picture, the middle arrow denotes ethernet connection and remaining two are Wi-Fi connection.
Umm, it seems I have connected things together. But those who got introduced to computer networks will know there’s no way for this setup to work by itself.
Yellow background denotes the private LAN, network created by the ADSL modem. My phone, ADSL modem and Macbook are in yellow network. Green background denotes the university network which only has my Macbook (that's not the case, but assume so). For this to work, the packets from the yellow network has to be relayed into the green network.
The way out
Typical computer networks will have a node called gateway. As the name says, it is the way out of the network. Think of your home Wi-Fi, most probably your router will be the gateway. All the traffic from your phone and laptop leave your home via the router and all the incoming traffic will enter your home through it. So, the next time when you come across gateway in computer networks, remember this. (It's the way out)
2. Someone please route the packets
For upstream traffic from my phone to flow through MacBook, manually setting it as gateway will work, but a NAT is badly needed to receive downstream packets. By default, the ADSL modem will be the gateway, as it created the yellow network. I need to set my Macbook as the gateway instead. So that the traffic from the yellow network will leave through Macbook (Gateway, you remember :p)
Anyway in this case the gateway needs a NAT service. MacBooks don’t allow such Internet sharing services on an Enterprise network like my university Wi-Fi.
It’s getting complicated. Make it simple, stupid.
Who just mentioned HTTP proxy? Why on earth I’m trying to route in network layer? A HTTP proxy software running on my MacBook can simply relay the connection between the two networks in application layer. Now, it’s simple and stupid. No need to mess up with gateway settings.
As a bonus, Android Wi-Fi settings has proxy options built in. Thus my mobile will forward traffic to tinyproxy listening on my MacBook.
Well it's not working. I'm missing something. Let me unit test.
It is the incoming packets. They get lost as the Macbook doesn't know a route back to my phone. (I know what to do now :p) After adding a route in my IP tables, Yay it works!!
What it Cost?
An old ADSL modem with inbuilt access point, an Ethernet cable and a visit to electronics store to get an Ethernet to USB adapter (It’s a MacBook). Also few hours of messing up with network settings and IP tables.
What doesn’t work?
I’m able to get most of the apps working. Still, Messaging apps don’t work through HTTP proxy and it’s bad. Currently trying to replace the setup with SOCKS proxy creating a SOCKS tunnel between phone and MacBook. For some reason, it doesn’t work and I’m on it.
Happy Internet :)