telnet: Unable to connect to remote host: Network is unreachable
Many ISPs will block connections to port 25 as an anti-spam measure. My ISP (Cox) does this, only allowing connections to their own mail servers on port 25. For other email services, an alternate port has to be used which may necessitate the use of SSL or TLS rather than an open connection like port 25 gives you.
Have a look at your ISP's website specifically regarding port 25.
First try connecting to your ISP's email servers if available using port 25. If that works, it's probably an ISP restriction.
As a test, you can play around with netcat a bit:
sudo nc -l -p 25
Then in a new terminal, try a telnet connection to localhost:25. If the things you type are reflected in netcat, then it's again possible that it's a restriction on your ISP.
To further test and validate this, you can set up a port forward in your router for port 25 to your current PC and then attempt the same netcat trick. Instead, though, telnet to your public IP, port 25. If this fails, then it's almost surely an ISP restriction.
Note: many ISPs use this practice -- including mobile providers such as Verizon. So, just because it didn't work on a tethered connection either doesn't mean it's not an ISP problem.
Solution
It's possible to connect to Gmail in plain text (no secure negotiation) on port 587. Therefore, you should see that telnet smtp.gmail.com 587
works just fine!
Related videos on Youtube
sonalkr132
Updated on September 18, 2022Comments
-
sonalkr132 over 1 year
I am not able to connect to gmail with telnet using any of the ports. I am using this command:
telnet smtp.gmail.com 25
and it gives following error:
Trying 74.125.68.108... Trying 74.125.68.109... Trying 2404:6800:4003:c02::6d... telnet: Unable to connect to remote host: Network is unreachable
I used this to configure my firewall using method 2 thinking this problem may be because of it.
output of command
sudo ufw status
is:Status: active To Action From -- ------ ---- 25,53,80,110,443/tcp ALLOW OUT Anywhere 53,67,68/udp ALLOW OUT Anywhere 51413/tcp ALLOW OUT Anywhere 51413/udp ALLOW OUT Anywhere 6969/tcp ALLOW OUT Anywhere 587,2525/tcp ALLOW OUT Anywhere 587,2525/udp ALLOW OUT Anywhere 25,53,80,110,443/tcp (v6) ALLOW OUT Anywhere (v6) 53,67,68/udp (v6) ALLOW OUT Anywhere (v6) 51413/tcp (v6) ALLOW OUT Anywhere (v6) 51413/udp (v6) ALLOW OUT Anywhere (v6) 6969/tcp (v6) ALLOW OUT Anywhere (v6) 587,2525/tcp (v6) ALLOW OUT Anywhere (v6) 587,2525/udp (v6) ALLOW OUT Anywhere (v6)
I even tried to use my mobile network instead of lan thinking my ISP may have blocked ports but I got the same error. Can someone help please?
UPDATE:
sudo netstat -tunlp
gives: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:23 0.0.0.0:* LISTEN 8390/xinetd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 4310/cupsd tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1405/postgres tcp 0 0 127.0.0.1:5433 0.0.0.0:* LISTEN 1779/postgres tcp 0 0 127.0.0.1:9306 0.0.0.0:* LISTEN 3275/searchd tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1171/mysqld tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 2465/dnsmasq udp 0 0 0.0.0.0:5353 0.0.0.0:* 3414/chrome udp 0 0 0.0.0.0:5353 0.0.0.0:* 749/avahi-daemon: r udp 0 0 0.0.0.0:48695 0.0.0.0:* 749/avahi-daemon: r udp 0 0 0.0.0.0:46846 0.0.0.0:* 9389/dhclient udp 0 0 127.0.1.1:53 0.0.0.0:* 2465/dnsmasq udp 0 0 0.0.0.0:68 0.0.0.0:* 9389/dhclient udp6 0 0 :::47892 :::* 749/avahi-daemon: r udp6 0 0 :::5353 :::* 749/avahi-daemon: r udp6 0 0 :::14340 :::* 9389/dhclient
-
heemayl over 9 yearsCan you ping smtp.gmail.com?
-
sonalkr132 over 9 yearsI used:
ping -c 10 mail.google.com
. It seemed to work. Output had line:10 packets transmitted, 9 received, 10% packet loss, time 9990ms
-
heemayl over 9 yearssmtp.gmail.com and mail.google.com resolve to different IP addresses so you should try to ping smtp.gmail.com as you are telnetting this host on port 25.
-
heemayl over 9 yearsCould you try telnet smtp.gmail.com 465?
-
-
sonalkr132 over 9 years
telnet localhost 25
gave output:Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
and nothing appeared in other terminal window. I just want to establish a connection with gmail, doesn't matter if its port 25 or any other port. -
heemayl over 9 yearsCould you try telnet smtp.gmail.com 465?
-
Chuck R over 9 yearsUpdated answer.
-
sonalkr132 over 9 years@heemayl
telnet smtp.gmail.com 465
doesn't work either -
sonalkr132 over 9 years@Githlar I just want to establish a connection with gmail so that I can send automated mails for my website. I was able to send mails earlier using port '587' but its not working now. I am going to try your solution now.
-
Chuck R over 9 yearsUse port 587 rather than 465, 465 is the legacy port.
telnet smtp.gmail.com 587
works in plain text, responds to HELO and everything. So, configure your email client with port 587 and it should work as expected. -
Chuck R over 9 yearsWhoops, used smtp.google.com instead of smtp.gmail.com
-
heemayl over 9 yearsThis narrowed down the problem to only server & client i.e. either your firewall is blocking or gmail's server has blocked your ISP's IP.