Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow access outside localhost

People also ask

Can localhost be accessed from outside?

Conclusion. If you're working on a computer with an active internet connection, you can now set up access to your localhost from anywhere in only a few minutes!

How do I access localhost from another network?

You need to do a number of things: Ensure that you can reach the site from another computer on the LAN. Configure the computer running Tomcat to have a fixed IP address on your LAN. Forward the required port(s) from your router to the fixed IP of the Tomcat server.

Can access through localhost but not IP?

If you can access a server running on your own machine via 127.0. 0.1 (or localhost ) but not via the computer's ip address, this means that the server software is configured to listen on the localhost interface only.


Using ng serve --host 0.0.0.0 will allow you to connect to the ng serve using your ip instead of localhost.

EDIT

In newer versions of the cli, you have to provide your local ip address instead

EDIT 2

In newer versions of the cli (I think v5 and up) you can use 0.0.0.0 as the ip again to host it for anyone on your network to talk to.

As a side note Make sure your connection is set to Public in your OS settings.


Mac users:

  1. Go to System Preferences -> Network -> Wi-Fi
  2. Copy the IP address below Status (Usually 192.168.1.x)
  3. Paste it in your ng serve like: ng serve --host 192.168.1.x

Then you must be able to see your page on other devices through 192.168.1.x:4200.


run command

ng serve --host=0.0.0.0 --disable-host-check

this will disable host check and allow to access from outside(instead of localhost) with IP address


You can use the following command to access with your ip.

ng serve --host 0.0.0.0 --disable-host-check

If you are using npm and want to avoid running the command every time, we can add the following line to the package.json file in the scripts section.

"scripts": {
    ...
    "start": "ng serve --host 0.0.0.0 --disable-host-check"
    ...
}

Then you can run you app using the below command to be accessed from the other system in the same network.

npm start