Cannot access local server with IP address while localhost and 127.0.0.1 can

Check that your server is listening:

sudo lsof -n | grep TCP | grep LISTEN

You can also check the route using nc. Start nc on the server listening on an unused port and then connect from another machine -- this will verify iptables and routes are correct.

My guess is that you're listening on the localhost only.


I fixed this issue with following ways:

  1. I run the command

    sudo ufw status 
    

    And I found that the port 80 (in my case) was not in the list.

  2. Then I run the command

    sudo ufw allow 80
    

    This fixed the issue.