Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've switched my CentOS machine from DHCP to static routing, using telnet to connect to it has gone from practically instantaneous, to taking around 30 seconds for the initial login prompt to display.

Apparently, this has something to do with the server doing a reverse DNS lookup to figure out who is connecting to the box, which relies on the hosts file.

Should I add something to /etc/hosts to speed up the process? My file is extremely limited right now, this is pretty much a fresh install.

[root@Azaz07]# cat /etc/hosts
127.0.0.1       localhost.localdomain localhost
::1     localhost6.localdomain6 localhost6

Telnet0 done locally responds right away.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

My telnet rant

In general i'd advise you to not use telnet, but to use ssh instead. Telnet is a security liability that no one should be using in this day and age. See this article for a demonstration of how someone can easily sniff telnet packets as they traverse the network using wireshark, and gain access to your credentials. Th e article is titled: Sniffing Telnet Using Wireshark. Here's a screenshot of a login attempt using telnet:

ss of wireshark sniffing telnet

Fixing your issue

However, if you have to absolutely use telnet then I'd start by diagnosing the telnet command you're using with the tool, strace.

Example

To demonstrate the issue you're ultimately experiencing, I modified my /etc/resolv.conf file so that there was a bogus DNS server in the mix. This would cause the slowness that the OP was ultimately experiencing.

# /etc/resolv.conf
# Generated by NetworkManager
domain mydom.net.
search mydom.net.
nameserver 1.2.3.4
nameserver 192.168.1.101

I then ran telnet like so:

$ strace -T telnet skinner

This section of the output shows what's taking so long:

...
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3 <0.000021>
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("1.2.3.4")}, 16) = 0 <0.000023>
poll([{fd=3, events=POLLOUT}], 1, 0)    = 1 ([{fd=3, revents=POLLOUT}]) <0.000012>
sendto(3, "\275N\1\0\0\1\0\0\0\0\0\0\7grinchy\5bubba\3net\0\0"..., 35, MSG_NOSIGNAL, NULL, 0) = 35 <0.000073>
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 5000) = 1 ([{fd=3, revents=POLLOUT}]) <0.000012>
sendto(3, "\373\262\1\0\0\1\0\0\0\0\0\0\7grinchy\5bubba\3net\0\0"..., 35, MSG_NOSIGNAL, NULL, 0) = 35 <0.000027>
poll([{fd=3, events=POLLIN}], 1, 4999)  = 0 (Timeout) <5.004038>
...

The above poll that experienced the "Timeout" was our DNS query to server 1.2.3.4 on port 53. We can see when we use the -T switch that, this one function call took ~5 seconds until it timed out.

We can also confirm the length of time using the time command like so:

$ time telnet skinner
Trying 192.168.1.3...
telnet: connect to address 192.168.1.3: Connection refused

real    0m10.030s
user    0m0.001s
sys 0m0.003s

Using a correct DNS server

Putting in a correct DNS server into /etc/resolv.conf, and telnet is now much more performant.

$ strace -T telnet skinner
...
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.1.101")}, 16) = 0 <0.000018>
poll([{fd=3, events=POLLOUT}], 1, 0)    = 1 ([{fd=3, revents=POLLOUT}]) <0.000010>
sendto(3, "D\363\1\0\0\1\0\0\0\0\0\0\7grinchy\5mydom\3net\0\0"..., 35, MSG_NOSIGNAL, NULL, 0) = 35 <0.000054>
poll([{fd=3, events=POLLIN|POLLOUT}], 1, 5000) = 1 ([{fd=3, revents=POLLOUT}]) <0.000009>
sendto(3, "s\342\1\0\0\1\0\0\0\0\0\0\7grinchy\5mydom\3net\0\0"..., 35, MSG_NOSIGNAL, NULL, 0) = 35 <0.000021>
poll([{fd=3, events=POLLIN}], 1, 4999)  = 1 ([{fd=3, revents=POLLIN}]) <0.005300>
ioctl(3, FIONREAD, [84])                = 0 <0.000024>
recvfrom(3, "D\363\205\200\0\1\0\1\0\1\0\1\7grinchy\5mydom\3net\0\0"..., 2048, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.1.101")}, [16]) = 84 <0.000016>
poll([{fd=3, events=POLLIN}], 1, 4994)  = 1 ([{fd=3, revents=POLLIN}]) <0.003688>
...

Timing it using time also shows the same:

$ time telnet skinner
Trying 192.168.1.3...
telnet: connect to address 192.168.1.3: Connection refused

real    0m0.009s
user    0m0.000s
sys 0m0.002s
share|improve this answer
1  
yeah, I would if I could. We're developing software for a testing lab that uses telnet internally. –  some1 Nov 15 '13 at 22:21

I was using 4.2.2.1 and 4.2.2.2 for statically assigned DNS servers -- I switched these to 192.168.0.1 for the router and it resolved the issue.

share|improve this answer
1  
It was probably trying to connect to those DNS servers and timing out. –  slm Nov 15 '13 at 22:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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