Archive

Archive for May, 2013

External routing to localhost

May 5, 2013 Leave a comment

Over the last couple months I’ve thought many times: “How can I get public/external access to my local machine?”  I’ve been working with OAuth providers that want a callback URL and integrating a Rails application with Salesforce.  I wanted those public applications to talk to my local machine for ease of development.  Sure I could push my project to Heroku or some other public server but it’s just so much easier to have things local for quick development and debugging.

These instructions assume you are connected to a router (probably wireless), that you can administer, which is connected to your ISP’s cable modem.

1) Enable the DMZ function of your router. I’m using DD-WRT which gives me some additional functionality so hopefully you can find a DMZ option in your configuration.  NOTICE:  “Enabling this option will expose the specified host to the Internet. All ports will be accessible from the Internet.”  It’s recommended to have a firewall enabled on your machine to protect yourself.

The configuration should ask for a specific IP to route all public traffic to.  Find the IP address assigned to you (typically in the 192.168.x.x range) and punch it in.

2) Now that you’re machine is accessible you need to know the external IP to use. The easiest way is to find the WAN IP listed in the admin console of your router.  If your router allows shell access you can also ssh in and run ifconfig or some variant to get the external IP.

You should now be able to visit that external IP from your browser and it will resolve to port 80 on your local machine.  Yay!
If you don’t have anything running on port 80 you’ll likely get an error response. If you’re running a rails server, use pu.bl.ic.ip:3000.

3) Taking it a step further is routing an official domain name to the public IP we found in step 2.  I purchased a domain for personal use and then created a new DNS A Record that points a specific subdomain (localhost.mydomain.com) to the public IP of my cable modem.

Now I can just type in a domain name and I’m routed directly to my laptop.

Yes, my locally assigned IP could change and I’d need to update the router DMZ configuration.
Yes, it’s possible that my cable modem IP will change and I’d need to update the DNS A Name record.

 

Categories: Uncategorized