How to make my IP publicly accessible to make my local Tomcat server public?

94,573

Solution 1

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

Solution 2

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.

Solution 3

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!

Solution 4

  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.

Solution 5

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

Share:
94,573

Related videos on Youtube

jayesh
Author by

jayesh

Updated on September 18, 2022

Comments

  • jayesh
    jayesh almost 2 years

    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?

    • helper12345
      helper12345 over 11 years
      Yes it's possibile, did you tried it?
  • Adiyat Mubarak
    Adiyat Mubarak about 4 years
    is ngrok able to handle production traffic? let say handling concurrent request before tunneling it to our network
  • elirandav
    elirandav about 4 years
    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.
  • Hassen Ch.
    Hassen Ch. about 4 years
    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.