Port listening on localhost:8000 but not on ip:8000

26,677

Solution 1

As @JamesHenstridge points out, the behaviour you're observing is not due to Ubuntu blocking your application on some IPs, but due to your application explicitly binding only to the local loopback interface (127.x.x.x). At least if you didn't install and set up a firewall to specifically block that port.

You need to consult your application's documentation to see if there's a setting to make it listen on other (or on all) interfaces.

Solution 2

In one configuration file of your application, you should ensure that your IP is 192.168.1.7 and you should also set up your application to listen to "external IPs:yourport".

In your current configuration, your app is listening to requests from 127.0.0.1:xxxx or localhost:xxxx only.

You may need to change the IP address of your server in a configuration file from 127.0.0.1:8000 to 192.168.1.7:8000

Somewhere in your app you may need to change the listening IP address from 127.0.0.1:8000 to 0.0.0.0:8000

0.0.0.0:8000 means that your app should listen to any IP on port 8000.

By typing

 sudo netstat -plnt | grep 8000

you should see the following which will confirm that your app is listening on any ports:

tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN nnnn/yourapp

Share:
26,677

Related videos on Youtube

Marionette
Author by

Marionette

Updated on September 18, 2022

Comments

  • Marionette
    Marionette over 1 year

    Hello I'm running a web application on port 8000. When I access it from the host server localhost:8000 it responds ok, 127.0.0.1:8000 also works, but 192.168.1.7:8000 does not work. 192.168.1.7 is the ip of my server.

    Also if i try to go to another web application running on port 80 it works 192.168.1.7

    I enabled ufw firewall and set ufw default allow. I am using ubuntu server 12.04

    Any suggestions on why I can't get to my app on port 8000 using the ip-address:8000?

    Thanks in advance!

    • James Henstridge
      James Henstridge over 11 years
      The application is probably listening to the localhost address (127.0.0.1) rather than to all local addresses (0.0.0.0). You haven't provided enough information on your app for people to help you fix this though.
    • Marionette
      Marionette over 11 years
      My app running on port 8000 is just a website. Perhaps this netstat copy/paste will reveal more about my network:
    • James Henstridge
      James Henstridge over 11 years
      Well, running netstat -tln | grep 8000 might cast some light on the problem. If the server's local address is 127.0.0.1:8000 rather than 0.0.0.0:8000, then it will only be reachable via the loopback interface.
    • Admin
      Admin over 11 years
      check your iptables
  • wlraider70
    wlraider70 about 11 years
    Also are you familiar with port forwarding on your router? If you are going to connect to it from the internet on port 8000 you need to forward port 8000 to that machines ip.