Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an app running on my computer at 127.0.0.1:3000

I would like to access that app from an iPhone connected to the same network. I have done this before but blanking out on how I did it. Any ideas?

share|improve this question

6 Answers 6

up vote 11 down vote accepted

First you need to determine the ip address or name of the machine you are running the webserver on. I'm assuming you are running the webserver on a mac since you tagged your post macosx athough the instructions are similar for linux machines. So, on your mac:

  • Open Terminal.app. It's under Applications->Utilities.
  • Run ifconfig in the terminal. That shows you all the network interfaces on the machine. One of them is the network your machine is actively connected to. If you mac is on a wired connection that should be en0. Make a note of the address after inet - that should be the address your machine uses.
    • Let's assume you discover it's 192.168.10.1.
  • Verify that you can connect to that address from your server with nc -v 192.168.10.1 3000.
    • You should see a message like Connection to 192.168.10.1 3000 port [tcp/http] succeeded!.
    • If that doesn't work, see below.
    • If it does work, hit ctrl-C to exit the nc session.
  • Now try to connect on your client machine.

If you are unable to connect to your application on the server's real address, that means your application isn't listening on that address. You will need to investigate how to change your application configuration to modify that behavior. Since I don't know what application you are running I can't offer any good ideas on that.

share|improve this answer
    
10x mate... whats the difference when talking about a windows based system with Wamp server on it... is there any difference ? –  Sagive SEO Jan 9 '12 at 21:09

Find the name of your Mac using hostname (at the Terminal prompt) and use that in your URL. E.g. http://Tonys-iMac.local:3000/

If for some reason Bonjour doesn't work in your environment, find the address of the Airport on an iMac or MacBook with

ipconfig getifaddr en1

or in general with

ipconfig getifaddr $(route -n get default|awk '/interface/ { print $2 }')

share|improve this answer
    
This answer has some good optimizations over mine regarding finding your hostname and ip address. –  Phil Hollenback Feb 2 '11 at 4:49
    
why would bonjour not work ? I find my hostname is gm20152.local . But when I try gm20152.local:3000 on the same machine, it brings up a valid page. But when I try gm20152.local:3000 on my android phone, the browser on my phone could not find the host. I think this is because my phone has no way of mapping gm20152.local to my macbook's ip addr. How can I accomplish this ? –  gprasant Aug 11 at 20:35
    
@gprasant Getting Android to use Bonjour seems pretty hard –  James Sep 19 at 11:25

Basically, from firewall settings you can allow a certain application (e.g. ruby) to accept incoming connections. Plus to allow access to the outside world (e.g www), you'll need to forward traffic to your internal gateway:port via your router settings.

Here's how to do this:

  1. Mac->Sys Preferences->Sharing->Enable “Web Sharing” checkbox
  2. Mac->Sys Preferences->Security-> allow your application (e.g. ruby) to accept incoming connection
  3. Open a port on the router (via 192.168.1.1) to forward traffic from your_web_ip:port to a local_gateway:port

    1. E.g. from my Verizon's router settings -> Port Forwarding -> create rule: forward to local gateway (e.g. 192.168.1.4), custom port, protocol tcp, source=any, destination=3280, all connection types, forward to port = 3000.

Done. Now from the remote computer, open your browser to your web ip address (find via http://www.whatismyip.com/) + destination port# above, e.g. 72.189.194.65:3280, this will connect to your local 192.168.1.4:3000

Note: I'm running on Mac OSX 10.7.5

share|improve this answer

127.0.0.1 is the local address every computer has for itself. You have to find out what the real IP address (or Host/Bonjour name) of the machine is. Go to System Preferences, Network and look up the IP of the machine, either for the Ethernet port if you use a cable or the Airport if you use WLAN . Then open this address together with the :3000 part in Safari on the iPhone.

share|improve this answer
    
Also the Sharing Preference Pane always shows a name or address by which your computer can be reached. –  James Feb 4 '11 at 21:02

If the application is listening on 127.0.0.1:3000 only then you can't access it from another computer. To do so you would need to modify the configuration to Listen the IP or 0.0.0.0 (all available interfaces).Thats option one.

The second option is to use a proxy.

Third option is if you can ssh from the iphone you can also use ssh forwarding.

ssh user@host -L 3000:127.0.0.1:3000

Then on your iphone open 127.0.0.1:3000

share|improve this answer
    
AFAIK, you can't do ssh port forwarding on an iPhone. Not if it's not jailbroken anyway. –  SvW Feb 1 '11 at 3:42

Have you tried this, it worked for me (I'm not affiliated with it) :

https://github.com/progrium/localtunnel

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.