简体   繁体   中英

Can't connect to a computer that I can ping

I have two devices. One is a Raspberry Pi and the other a full Linux computer from my school. I am trying to establish a TCP socket connection between the two. I can already do this between the Pi and another Pi, and likewise between the Linux box and another such box also belonging to the school. What I cannot do is connect() between the Pi and the Linux box. I can ping each from either, though, so I have reason to believe they are on the same network. My guess is that there is a firewall blocking the Pi from connecting, but is there a better explanation? How can I get the things talking?

There are many possibilities. First, you should gather more diagnostic information.

Try traceroute -n <ip> to see the intermediate hosts. They could indeed be in a different local network with a filtering router between them.

Try connecting to the peer with telnet <ip> <port> . If it says Connection refused , it is likely that the other host is reachable, but there is nothing listening on the port. If there is no response (packet is dropped), it is likely a filter blocking the connection.

Next, try nmap <ip> . This will tell you which ports are open and blocked.

Examine IP filter rules:

iptables -L INPUT

on both hosts. You can remove all (input) rules with iptables -F INPUT . Make sure the default policy is accept iptables -P INPUT ACCEPT .

You could potentially be connecting to a different host entirely if it is a local address (most often 192.168.xx or 10.xxx), and they are separated by a NAT. You could try blocking ping on the remote host temporarily to see if it has any effect:

sysctl -w net.ipv4.icmp_echo_ignore_all=1

It should no longer be possible to ping the remote host. Note: Afterwards, re-enable ping with sysctl -w net.ipv4.icmp_echo_ignore_all=0

Try a different TCP listening server, eg python's SimpleHTTPServer:

host1$ python -m SimpleHTTPServer
host2$ telnet <ip> 8000

I was facing a similar problem. On browser, it shows "This site can't be reached. xxxx refused to connect. ERR_CONNECTION_REFUSED". But on the terminal, I was able to ping the IP_Address. One of the possible problems can be because of the firewall. Try to run these commands on the xxxx machine terminal.

sudo firewall-cmd -state
systemctl stop firewalld

this will stop the firewall and now you can reload the browser URL. It will work if firewall was blocking access. If this doesn't work, you can surely refer to another answer. I also tried it but got stuck at nmap command. "nmap - RTTVAR has grown to over 2.3 seconds, decreasing to 2.0"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM