Link to home
Start Free TrialLog in
Avatar of sams20
sams20

asked on

Telnet connection refused when I was trying to telnet remote server with specific port.

Telnet connection refused when I was trying  to telnet remote server with specific port. What is the proper solution for this problem?

#telnet 172.xx.xx.xxx 3212 .

#telnet: connect to address 172.xx.xx.xxx: Connection refused.
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Sounds like the server at 172.xx.xx.xxx isn't accepting connections on port 3212.  I would start there.
Telnet connection refused

You really should be using SSH... Telnet should be disabled
Avatar of Dr. Klahn
Dr. Klahn

The telnet command line syntax for accessing a system on non-standard ports varies quite a bit.  On some systems it is "telnet target port", on others it is "telnet target:port" and on others it is "telnet --port=xxxx target."  Be sure you have the correct syntax.  An easy way to check it is to telnet to port 25 on a system with an MTA and see if you get the MTA and not a refusal instead.
What is running on port 3212
The error could be the source of your connection is not authorized
Either the entire IP is blocked or port 3212 is blocked.

On the 172.xx.xx.xxx IP issue the following to open all ports...

iptables -F

Open in new window


Then issue the following to ensure a port 3212 listener...

netstat -pluten | grep 3212

Open in new window


Now test, then regenerate all your firewall rules.

Likely you'll find you have no listener or a firewall rule blocking connections.
IMHO, connection refused means the application is accessed.
Firewall would be stuck or connection timedout

Refused suggest an active denial.
Though, rethinking possibilities
It could be a firewall restriction to a specific ip/range with an explicit denial to all others.
172.x.x.x is a private IP range, so it's with your company, right?

If you're allowed to, try using nmap to see which ports are open/available from the computer you're on:

nmap 172.xx.xx.xxx

You would get an output that looks somewhat like this:

gerwin@host:~$ nmap 172.xx.xx.xxx
Starting Nmap 7.70 ( https://nmap.org ) at 2020-02-09 18:50 CET
Nmap scan report for 172.xx.xx.xxx
Host is up (0.00072s latency).
Not shown: xxx closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
443/tcp  open  https

Nmap done: 1 IP address (1 host up) scanned in 0.30 seconds

The above example is showing 2 open ports (22 and 443) which probably mean that I can ssh to port 22 and use a secure web browser to 172.xx.xx.xxx:443, you would see "3112/tcp open telnet" there.

If you do not see 'your' port, you can use nmap to scan for a specific port like this:

nmap 172.xx.xx.xxx -p 3212

If you don't have nmap, download it here first: https://nmap.org/download.html (or when on Linux use your package manager to get nmap).
In server

check netstat-tulnp|grep portnumber


If the output shows the listening

then firewall is blocking
@sams20

I am assuming that you can logon to 172.xx.xx.xxx using ssh

Execute following kind of commands at 172.xx.xx.xxx
root@172.xx.xx.xxx /root [ 0 ]
$ /bin/netstat -nato | /bin/grep -E ":22|Local Address" | /bin/grep -E -w "LISTEN|State"
Proto Recv-Q Send-Q Local Address               Foreign Address             State       Timer
tcp        0      0 172.xx.xx.xxx:22           0.0.0.0:*                   LISTEN      off (0.00/0/0)
root@172.xx.xx.xxx /root [ 0 ]
$

Open in new window

Hence 172.xx.xx.xxx listening on port number 22 using the IP Address 172.xx.xx.xxx
Like the same you check the same for port number 3212
In my system 172.xx.xx.xxx is present in /etc/ssh/sshd_config file
$ /bin/grep -E "^ListenAddress" /etc/ssh/sshd_config
ListenAddress 172.xx.xx.xxx

Open in new window

Hence validate the same IPv4 at your configuration file for port number 3212
@sams20
Verifying port number 22 telnet at my system:
1)
Valid port number:
$ echo -e "\035\nclose" | /usr/bin/telnet 172.xx.xx.xxx 22
Trying 172.xx.xx.xxx...
Connected to 172.xx.xx.xxx.
Escape character is '^]'.

telnet> Connection closed.

Open in new window



2)
Invalid HOSTNAME
$ echo -e "\035\nclose" | /usr/bin/telnet 172.yy.yy.yyy 22
telnet: 172.yy.yy.yyy: Name or service not known
172.yy.yy.yyy: Unknown host

Open in new window


3)
Invalid port number
$ echo -e "\035\nclose" | /usr/bin/telnet 172.xx.xx.xxx 1024
Trying 172.xx.xx.xxx...
telnet: connect to address 172.xx.xx.xxx: Connection refused

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.