Ok, so I'm stumped. I have a new Raspbian install on a Model B Rev 2 and I can ssh using the IP Address just fine, but I can't connect on any other port outside the pi. Some details:

pi@dogwood:~ $ lsb_release -a
No LSB modules are available.

Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.9 (stretch)
Release:    9.9
Codename:   stretch
pi@dogwood:~ $ 

I am trying to write a python REST API, but to troubleshoot I am using the netcat command like so:

pi@dogwood:~ $ nc -l localhost 5001

While that is waiting for a connection, I run netstat in another terminal:

pi@dogwood:~ $ sudo netstat -lpnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0    *               LISTEN      340/sshd            
tcp6       0      0 :::22                   :::*                    LISTEN      340/sshd            
tcp6       0      0 ::1:5001                :::*                    LISTEN      11887/nc            

pi@dogwood:~ $ 

Which I think means it has bound to all IPs and is listening on port 5001. That ::1:5001 looks suspicious, but I don't know enough about IPv6.

So from here, I can then do a

pi@dogwood:~ $ curl http://localhost:5001

pi@dogwood:~ $ 

And it makes a connection. The IP address of the pi is:

pi@dogwood:~ $ ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enxb827ebe4d83d: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether SO:ME:MAC:HE:RE brd ff:ff:ff:ff:ff:ff
    inet brd scope global enxb827ebe4d83d
       valid_lft forever preferred_lft forever
    inet6 fe80::f1bd:6ee:1851:66ba/64 scope link 
       valid_lft forever preferred_lft forever
pi@dogwood:~ $ 
pi@dogwood:~ $ 

However, if I use the ip address of the pi either locally on the pi:

pi@dogwood:~ $ curl
curl: (7) Failed to connect to port 5001: Connection refused
pi@dogwood:~ $ 

or remotely, I get:

myuser@appletree:~$ curl
curl: (7) Failed to connect to port 5001: Connection refused

So obviously it's a firewall... right? Except that iptables has no rules:

pi@dogwood:~ $ sudo iptables -S
pi@dogwood:~ $ 

And ufw is not installed:

pi@dogwood:~ $ sudo ufw
sudo: ufw: command not found
pi@dogwood:~ $ 

Any suggestions?

  • Did you start a listener and bind it to that port? If not, there's nothing to connect to.
    – user96931
    Commented May 2, 2019 at 17:39

1 Answer 1


Your process is listening on IPv6 address ::1 (that's the IPv6 equivalent of IPv4 (aka localhost)).

You need it to listen on :: (which is IP6ADDR_ANY as that's the IPv6 equivalent of IPv4 INADDR_ANY (

Don't use nc -l localhost 5001

If you want to connect from any other machine on your LAN. Use nc -l -p 5001 or nc -l -6 -p 5001 or nc -l -4 -p 5001

  • 1
    Awesome, yea, that was it. Incidentally, this nc rabbit hole was unnecessary, the flask run was binding the same way. I found you have to give it the --host= parameter to bind to the INADDR_ANY. Works way better now. Thanks! Commented May 2, 2019 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.