Fixes

Fix

Service works on localhost but not from another machine

The service listens on 127.0.0.1 only, so connections to the machine's real address are refused. Make it listen on 0.0.0.0 or on that address.

Likely causes

  1. The program binds to 127.0.0.1 (often a default, or a --host/bind setting).
  2. A firewall on the server or on the path, which shows as a timeout instead of a refusal.

Diagnose

Run these in order. The output is what each printed on a lab's real Linux machines.

appServer:~# nc 127.0.0.1 8080
On the server itself the service answers.
admin panel
laptop:~# telnet 10.0.2.10 8080
From another machine, Connection refused: nothing listens on 10.0.2.10:8080.
telnet: can't connect to remote host (10.0.2.10): Connection refused
appServer:~# ss -tulnp
ss -tulnp shows why: port 8080 listens on 127.0.0.1:8080, while 443 and 80 listen on 0.0.0.0 or *, every address.
Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:PortProcess                       
udp   UNCONN 0      0         127.0.0.11:44457      0.0.0.0:*                                 
udp   UNCONN 0      0                  *:7                *:*    users:(("socat",pid=89,fd=5))
tcp   LISTEN 0      5          127.0.0.1:8080       0.0.0.0:*    users:(("socat",pid=90,fd=5))
tcp   LISTEN 0      4096      127.0.0.11:33481      0.0.0.0:*                                 
tcp   LISTEN 0      511          0.0.0.0:443        0.0.0.0:*    users:(("nginx",pid=80,fd=5))
tcp   LISTEN 0      9                  *:80               *:*    users:(("httpd",pid=74,fd=3))
tcp   LISTEN 0      5                  *:7                *:*    users:(("socat",pid=81,fd=5))

Fix

pkill -f '^socat TCP-LISTEN:7,'; sleep 0.5; setsid socat TCP-LISTEN:7,bind=0.0.0.0,fork,reuseaddr EXEC:cat >/dev/null 2>&1 < /dev/null &
Restart the service bound to 0.0.0.0. For your own program, the same: change its listen address and restart it.

The fix the lab's challenge "The echo service only talks to itself" checks.

Break it and fix it yourself

Each lab is a small network of real Linux machines in your browser, where this fault happens.

Open TCP and UDP: ports, connections and datagrams

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Start with a free account: Google or email, no card.

Start this lab, free