Search code examples
apacheipwebserver

how to access localhost using ip of pc?


I am trying to run my local host app using my system ip but its not working.

http://localhost/bootstrap/bs1.html - working

http://xxx.xxx.xx.xx/bootstrap/bs1.html -not working

using ipconfig command I got the ipv4 .

how to make it?


Solution

  • As you are using IPConfig, I assume you are using Windows as well.

    Open notepad as administrator, navigate to Windows\System32\drivers\etc and open hosts file (Windows 10).

    Uncomment or add a new line with following entry:

    127.0.0.1 localhost

    Then flush your DNS cache in your terminal with command:

    ipconfig /flushdns

    You might experience browser caching at this point, close and reopen browser if needed.

    This is for localhost only, so host machine and guest machines (if any).

    If you want to give an access to your server externally, like for anyone over the internet, this is much more complicated tasks and would require port forwarding.

    But there is simpler solution and workaround for doing it and I recommend using Ngrok which is super simple CLI tool that will do work for you. It's a secure solution as you are not exposing anything on your computer directly but instead it uses a secure tunnel to provide your localhost on *.ngrok.com/* link.