4

So I'm trying to debug my server code without deploying it (which takes a long time).

I'm serving my website through angular (the framework doesn't matter IMO) ng serve --port 8080.

When I type http://localhost:8080 into the browser everything is fine and the website is loading.

192.168.1.39 is the address my router gave my laptop (I saw that on the router's admin configuration page).

When I type http://192.168.1.39:8080/ (localhost should be the same as this ip address!) it's the same message as on a phone connected to the same Wifi network(which is what I actually want-there's an issue when it comes to mobile phones images)- connection refused.

Following the debugging instructions here https://serverfault.com/questions/725262/what-causes-the-connection-refused-message

We can clearly see that on port 8080 ng is listening-

yoni@yoni-Lenovo-Z710:~/Projects/Server$ sudo netstat -tnlp | grep :8080
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      5879/ng

and I've completely disabled the firewall through

sudo ufw disable

restarted my laptop- still connection refused.

(I know it's not recommended but I really want figure things out and this became quite frustrating after a few hours).

On top of that I've tried ports other than 8080 (the default angular's 4200 for example).

Oh yeah, and I've tried to forward all the requests from ports 4000 to 9000 to my laptop (router configuration). Same result- connection refused ;)

What do i do? How do I debug this problem?

1
  • Use sudo ufw allow 8080 on your machine and check from another machine with nmap whether the port is open.
    – kukulo
    Commented Sep 13, 2018 at 10:16

1 Answer 1

4

Hello and welcome to AskUbuntu!

As you can see from netstat, your service is listening only on localhost:

tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      5879/ng
                    ^^^^^^^^^^^^^^

You should change your ng command to:

ng serve --host 0.0.0.0 --port 8080

so it will listen on port 8080 on all available IP/Interfaces on your machine.

4
  • Wow, that worked! Just wasted 4 hours on those 20 or so characters- What is the topic that I should review so that I can avoid wasting more time in the future? And also, what does 0.0.0.0:* mean then in the netstat output line?
    – Yoni Keren
    Commented Sep 13, 2018 at 10:40
  • 1
    @YoniKeren This isn't the place for Networking 101, but maybe the following will help you: Your machine has multiple networking devices. Additional to the one you probably know about there's the so called loop back device (shortened lo). Every networking system using TCP/IP has a lo, not just Ubuntu. Maybe there are still more interfaces, for example if your machine is connected to the network by LAN and by WLAN. (cont.) Commented Sep 13, 2018 at 11:02
  • @YoniKeren IP addresses are not just assigned to a machine in the network, they're assigned to a specific interface. The IP address 127.0.0.1 is reserved for lo. So if you set ng up to listen at 127.0.0.1:8080, it listens on lo, and only there. If you call the machine on another interface (say, eth0 for a LAN connection) with the IP address 192.168.1.39, ng never knows about it because it doesn't listen on eth0. (cont.) Commented Sep 13, 2018 at 11:03
  • @YoniKeren 0.0.0.0 is a special meta IP address that's used for a number of purposes. In your case, it means "any IP address at all". So when you set up ng to listen at 0.0.0.0, it listens on any IP address it can get its hands on - in your case at least 127.0.0.1 and 192.168.1.39. Commented Sep 13, 2018 at 11:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .