Say you're running a virtual machine on your work computer. Say this machine, for whatever reason, can only connect to the internet over NAT - as in, it does not get it's own IP address. Say this VM is running a webserver, and you need a device outside of your computer to connect to it.
If only there was a way to get your work computer to 'share' it's network, so that you could get at that VM… Here's how you do it!
For all instructions, I assume your work computer is a mac
-
Get your computer's IP address:
ifconfig
Note you need to find the local IP in your wifi network, typical values for this type of IP look like
192.168.xxx.xxx
or10.xxx.xxx.xxx
. -
Enable your remote login on your mac following steps from here: http://osxdaily.com/2011/09/30/remote-login-ssh-server-mac-os-x/.
-
Create a SOCKS proxy into your computer that allows for external traffic. First open up a terminal window, then run this command (replacing X's with your ip address or domain, and username with the user you usually SSH into your computer with, you can also find your login username when you enable remote login):
ssh -N -gv -D 1080 [email protected]
Note you need to update
username
here to your Mac's login username, andXXX.XXX.XXX.XXX
to your Mac's IP.If you do this correctly, you'll be asked to authenticate/login. Once logged in, you'll see a slew of text, at the end of which you'll see something like:
debug1: Local connections to *:1080 forwarded to remote address socks:0 debug1: Local forwarding listening on 0.0.0.0 port 1080.
You now have a SOCKS proxy set up that can accept external traffic. Leave this running.
-
Fire up your text editor, because we need to create a PAC (Proxy-auto-config) file so that the iPad can use this SOCKS proxy.
-
Create a file with an extension of
.pac
(i.e. myProxy.pac) -
Paste the following into it, replacing X's with your work computer's IP, and Y's with the port you used for the SOCKS proxy (1080 in this example):
function FindProxyForURL(url, host) { return "SOCKS XXX.XXX.XXX.XXX:YYYY"; }
-
Save this file, and make it accessible to the iPad. An easy way to do this is to throw it up on dropbox, or other cloud storage your iPad has access to.
You can also open a new terminal window,
cd
to the folder containing the PAC file, and type following command:python -m SimpleHTTPServer
, then you can use the URLhttp://XXX.XXX.XXX.XXX:8000/myProxy.pac
in the steps below. Notice if you use other file name for the pac file, you need to modify the URL accordingly.
On the iPad
- Open up settings > wifi.
- Click on the blue arrow next to your wifi connection.
- Scroll to the bottom where there is a section for HTTP Proxy.
- Select Auto from this section.
- In the URL field, key in the URL of the *.pac file you created and made web-accessible.
Voila, your iOS device should now have the network characteristics of your work computer, and all traffic from the iOS device should go through it. You can verify this by watching the SOCKS proxy running in your terminal. When you try to access a website on the iPad, you should see a connection being made in the SOCKS proxy terminal window.