0

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 0.0.0.0:22              0.0.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

^C
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 127.0.0.1/8 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 192.168.2.11/24 brd 192.168.2.255 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 http://192.168.2.11:5001
curl: (7) Failed to connect to 192.168.2.11 port 5001: Connection refused
pi@dogwood:~ $ 

or remotely, I get:


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

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


pi@dogwood:~ $ sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
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 May 2 at 17:39
4

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

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

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=0.0.0.0 parameter to bind to the INADDR_ANY. Works way better now. Thanks! – nomadic_squirrel May 2 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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