24

I'm working on my desktop computer. On this machine I also run Tomcat for my Java development so that I can visit my local address:

 http://192.168.1.1:8080/myapp

Now I go to whatsmyip.com and get my IP lets say it is: 119.56.1.78

Now what I want is that: I go to another PC (not on my LAN) or any PC around the world connected to Internet and type the following address:

http:// 119.56.1.78:8080/myapp

this should show me the same page that I can access locally from http:// 192.168.1.1:8080/myapp.

Is this possible?

1
  • 2
    Yes it's possibile, did you tried it?
    – Atropo
    Commented Dec 28, 2012 at 12:03

5 Answers 5

17

Yes, it is possible. It is called "Port Forwarding".

119.56.1.78 - is your public IP address.
192.168.1.1 - is your private IP address on the LAN.

To see how port forwarding is done read this very good and short tutorial with lots of nice pictures:
How to Forward Ports on Your Router

6

You need to do forward your 8080 port through your router.

If your IP changes (you have a dynamic IP or a static IP, this is determined by your ISP) you can get a host name from dyndns and set up your router to update dyndns with your new IP when it changes. this will allow you to access your application like so:

hostname.dynsns.org/your_app

Alternatively, you can rent a hosted server and a domain name.

5

If it is for short term, you can use localtunnel (same like ngrok).

Just follow these steps (require: NodeJS):

  1. Install localtunnel by running

    npm install -g localtunnel
    
  2. Assumes, your app is running on http://localhost:8080/, then run

    lt --port 8080
    

    It will create a public url domain with a random name like this.

Note: You can create custom url as well (eg: lt --port 4200 -s "sangeeth", -s means subdomain).

Ta-da! It's done!

2
  • Cool! But what if my local address is 192.168.1.25:80? can I still use lt? Commented Sep 21, 2022 at 21:21
  • visitors have to enter password which I should provide, not convenient for testing webhooks
    – temirbek
    Commented Feb 27 at 6:12
2

Similar to @KernelMode answer, using ngrok but if you are on a macOS, open a terminal to the directory you downloaded ngrok and type ./ngrok http 8080 this will give you a http and a https public URL that you can use to access your localhost from other machines:

enter image description here

Below is a brief info about ngrok and things it can do with examples:

enter image description here

Note: if you want to access a particular link in your local server, no need to pass that as a command parameter in the terminal, once URL is assigned just append the sub-section to the URL.

For example: Assigned URL: http://1234567890.ngork.io and section you want to access: http://1234567890.ngork.io/myAppSub-section

1
  1. Download ngrok.
  2. Run your service.
  3. Assuming your tomcat server listen on port 8080, run ngrok in command line with this command:

ngrok.exe http 8080

ngrok starts port forwarding and it looks like this:

enter image description here

Now, the client can run request with the url http://a9bb8562.ngrok.io/myapp.

3
  • is ngrok able to handle production traffic? let say handling concurrent request before tunneling it to our network Commented Mar 30, 2020 at 15:10
  • 2
    I don't use this approach for production, only temporary for POC. In my example, it is just a local executable that is not managed, has no scale and no resiliency, so I don't think you should use it as-is for production.
    – elirandav
    Commented Apr 1, 2020 at 6:31
  • 1
    Do not use this approach for production. This is only for local server testing on your own private machine. If you need to do this for production you need to use a DNS server like Cloudflare or whatever other services you prefer.
    – Hassen Ch.
    Commented May 4, 2020 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .