# Telnet SetUp



## jaymax (Aug 11, 2010)

```
FreeBSD my.domain.com 7.2-RELEASE FreeBSD 7.2-RELEASE #0: Fri May  1 08:49:13 UTC 2009     
[email]root@walker.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC  i386
```

Testing a Qmail SMTP installation with Telnet

(normally use SSH for networking)

Temporary Telnet set up for testing ==>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Server set up ==>


```
% cat /etc/services | grep telnet
	    telnet           23/tcp
	    telnet           23/udp

% cat /etc/services | grep smtp
	    smtp             25/tcp    mail         #Simple Mail Transfer
	    smtp             25/udp    mail         #Simple Mail Transfer

% cat /etc/rc.conf
	   inetd_enable="YES"
```
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

But


```
% telnet 0 smtp
	0: servname not supported for ai_socktype

% telnet localhost 25
	   Trying 127.0.0.1...
	   telnet: connect to address 127.0.0.1: Connection reset by peer
	   Trying ::1...
	   telnet: connect to address ::1: Connection refused
	   telnet: Unable to connect to remote host
```
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



Do I have to add 

```
telnetd_enable="YES"
```
to /etc/rc.conf also, or is there another problem?


----------



## graudeejs (Aug 11, 2010)

jaymax said:
			
		

> Do I have to add
> telnetd_enable="YES"
> to /etc/rc.conf also, or is there another problem?




No... and why do you need inted?

show `# sockstat -4`


AND
write your posts formated:
http://forums.freebsd.org/showthread.php?t=8816


----------



## wblock@ (Aug 11, 2010)

jaymax said:
			
		

> Temporary Telnet set up for testing ==>
> 
> 
> ```
> ...



All you need for testing an SMTP server is the telnet *client*.  Enabling the telnet *server* is not necessary and to be avoided.

PS:
`# grep telnet /etc/services`
...to avoid UUOC.


----------



## jaymax (Aug 11, 2010)

killasmurf
	
	



```

```
Thanks, here it is, with changes to IP numbers and login name only

```
sockstat -4
USER     COMMAND    PID   FD PROTO  LOCAL ADDRESS         FOREIGN ADDRESS
myname   sshd       1732  3  tcp4   nnn.xxx.yyy.zzz:22       aaa.bbb.ccc.ddd:1256
root     sshd       1709  3  tcp4   nnn.xxx.yyy.zzz:22       aaa.bbb.ccc.ddd:1256
root     gnome-sess 1529  10 tcp4   *:54384               *:*
www      httpd      1328  3  tcp4   nnn.xxx.yyy.zzz:80       *:*
www      httpd      1328  4  tcp4   nnn.xxx.yyy.zzz:443      *:*
www      httpd      1327  3  tcp4   nnn.xxx.yyy.zzz:80       *:*
www      httpd      1327  4  tcp4   nnn.xxx.yyy.zzz:443      *:*
www      httpd      1326  3  tcp4   nnn.xxx.yyy.zzz:80       *:*
www      httpd      1326  4  tcp4   nnn.xxx.yyy.zzz:443      *:*
www      httpd      1325  3  tcp4   nnn.xxx.yyy.zzz:80       *:*
www      httpd      1325  4  tcp4   nnn.xxx.yyy.zzz:443      *:*
www      httpd      1324  3  tcp4   nnn.xxx.yyy.zzz:80       *:*
www      httpd      1324  4  tcp4   nnn.xxx.yyy.zzz:443      *:*
root     Xorg       1314  3  tcp4   *:6000                *:*
root     inetd      1267  6  tcp4   *:143                 *:*
root     sshd       1239  4  tcp4   *:22                  *:*
root     httpd      1207  3  tcp4   nnn.xxx.yyy.zzz:80       *:*
root     httpd      1207  4  tcp4   nnn.xxx.yyy.zzz:443      *:*
avahi    avahi-daem 1176  15 udp4   *:5353                *:*
avahi    avahi-daem 1176  16 udp4   *:60699               *:*
mysql    mysqld     948   11 tcp4   *:3306                *:*
root     perl5.8.9  794   5  tcp4   *:10000               *:*
root     perl5.8.9  794   6  udp4   *:10000               *:*
qmaild   tcpserver  778   3  tcp4   *:25                  *:*
root     tcpserver  776   3  tcp4   *:110                 *:*
root     mountd     667   7  udp4   *:914                 *:*
root     mountd     667   8  tcp4   *:914                 *:*
root     syslogd    580   7  udp4   *:514                 *:*
root     ntpd       371   20 udp4   *:123                 *:*
root     ntpd       371   22 udp4   nnn.xxx.yyy.zzz:123      *:*
root     ntpd       371   25 udp4   127.0.0.1:123         *:*
```


----------



## Terry_Kennedy (Aug 13, 2010)

jaymax said:
			
		

> ```
> 
> ```
> 
> ...



Your earlier message reported a "Connection reset by peer" error. That means you got there, but the server shut the connection down for some reason.

I'd look at your log files (in /var/log/*) and see if anything more informational was logged somewhere. I use sendmail here, so I can't say where exactly your mail server is going to log any errors. Some server programs can be started manually with an option to not run as a daemon (look in your program's manpage). If your program supports that, run it on one console (you'll need to stop the daemon version first) and try the telnet command from another console. Error messages should be logged to the first console and may be informative.


----------



## jaymax (Aug 14, 2010)

I ran the tcpdump on the lo0 interface, ran telnet as shown below, interestingly only the "telnet localhost 25"  produced an output (which I cannot fully decipher, except for the acknowledgment "hand shake" and the checksum, but can't figure out the "drop" or closure event
Oddly, "telnet localhost smtp" and "telnet localhost " produced nothing in the dumpfile, just the "localhost: servname not supported for ai_socktype" to stdout

[1]

```
mach# telnet localhost
localhost: servname not supported for ai_socktype
```

[2]

```
mach# telnet localhost smtp
localhost: servname not supported for ai_socktype
```

[3]

```
mach# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
```

Only [3] produced a tcpdump output, shown as follows ==>

```
mach# tcpdump -i lo0 -vvv >> tcpdumpfile

^C
7 packets captured
7 packets received by filter
0 packets dropped by kernel
```


```
20:31:41.366749 IP (tos 0x10, ttl 64, id 11415, offset 0, flags [DF], proto TCP (6), length 60) localhost.54336 > localhost.25: S, cksum 0x5c3a 
(correct), 1583394158:1583394158(0) win 65535 <mss 16344,nop,wscale 3,sackOK,timestamp 10736343 
20:31:41.366815 IP (tos 0x0, ttl 64, id 11416, offset 0, flags [DF], proto TCP (6), length 60) localhost.25 > localhost.54336: S, cksum 0xc615 
(correct), 2069694587:2069694587(0) ack 1583394159 win 65535 <mss 16344,nop,wscale 3,sackOK,timestamp 394525367 10736343>
20:31:41.366836 IP (tos 0x10, ttl 64, id 11417, offset 0, flags [DF], proto TCP (6), length 52) localhost.54336 > localhost.25: ., cksum 0x0c01 
(correct), 1:1(0) ack 1 win 8960 <nop,nop,timestamp 10736344 394525367>
20:31:41.398688 IP (tos 0x0, ttl 64, id 11421, offset 0, flags [DF], proto TCP (6), length 52) localhost.25 > localhost.54336: F, cksum 0x0be1 
(correct), 1:1(0) ack 1 win 8960 <nop,nop,timestamp 394525398 10736344>
20:31:41.398731 IP (tos 0x10, ttl 64, id 11422, offset 0, flags [DF], proto TCP (6), length 52) localhost.54336 > localhost.25: ., cksum 0x0bc2 
(correct), 1:1(0) ack 2 win 8960 <nop,nop,timestamp 10736375 394525398>
20:31:41.399162 IP (tos 0x10, ttl 64, id 11423, offset 0, flags [DF], proto TCP (6), length 52) localhost.54336 > localhost.25: F, cksum 0x0bc0 
(correct), 1:1(0) ack 2 win 8960 <nop,nop,timestamp 10736376 394525398>
20:31:41.399191 IP (tos 0x0, ttl 64, id 11424, offset 0, flags [DF], proto TCP (6), length 52) localhost.25 > localhost.54336: ., cksum 0x0bc0 
(correct), 2:2(0) ack 2 win 8959 <nop,nop,timestamp 394525399 10736376>
```

Shouldn't telnet localhost establish a connection?


----------



## Terry_Kennedy (Aug 14, 2010)

jaymax said:
			
		

> Oddly, "telnet localhost smtp" and "telnet localhost " produced nothing in the dumpfile, just the "localhost: servname not supported for ai_socktype" to stdout
> 
> Shouldn't telnet localhost establish a connection?


You've got two problems there. Please try looking in your log files as I described in a prior post - since the server is closing the connection before sending any output, you won't find anything with `# tcpdump`

My guess on the "servname not supported" is that you've got a problem in your /etc/services file - either corrupted or unreadable.


----------



## jaymax (Aug 14, 2010)

Thanks! Seems reasonable - likely problem in /etc/services file how would I know if it is corrupted or unreadable and is there any prescribed way of repairing or replacing it short of a re-installation?

I've searched my logs in /var/logs and could not come up with anything


----------



## Terry_Kennedy (Aug 14, 2010)

jaymax said:
			
		

> Thanks! Seems reasonable - likely problem in /etc/services file how would I know if it is corrupted or unreadable and is there any prescribed way of repairing or replacing it short of a re-installation?


You could try [cmd=""]cat /etc/services[/cmd] and see if it looks like this:


```
#
# Network services, Internet style
#
[snip]
smtp             25/tcp    mail         #Simple Mail Transfer
smtp             25/udp    mail         #Simple Mail Transfer
```

If there's something wrong with it and you installed the sources when you installed FreeBSD, you should have another copy in /usr/src/etc/services. If not, you can pull it from here (pick the revision you need and use the "download" link). On reviewing this post before hitting "reply", I see that you get the same error when not specifying a port number, so that's another hint that the problem is in that file.



> I've searched my logs in /var/logs and could not come up with anything


Perhaps someone with experience with the mail program you've installed will see this. If not, you could try running the mail program from the console, rather than as a daemon, as I posted in a previous reply. Again, I'm not familiar with it so I can't offer specific advice there. Its manpage may help.


----------



## jaymax (Aug 20, 2010)

Well not to belabor the problem

But the issue is not related to QMAIL but rather to the "telnet localhost" command itself.
The smtp SNAFU was actually a confounding effect as it was teleneting to that port which exposed the problem. Just telneting to local host produced the same problem.


```
mach# telnet localhost
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
```

I had mentioned this and raised this question before but never got a response, I was able to log in to another shell on another machine and was able to do a "telnet localhost" which confirmed the straight forward telnet problem on the 'Problem' Machine.

I can ping localhost just fine
netstat ==>

```
mach# netstat -i lo0
Name    Mtu Network       Address              Ipkts Ierrs    Opkts Oerrs  Coll
rl0    1500 <Link#1>      00:50:bf:72:6d:96    28722     0    26040     0     0
rl0    1500 nn.mm.xx.y    domain               28611     -    25973     -     -
plip0  1500 <Link#2>                               0     0        0     0     0
lo0   16384 <Link#3>                              66     0       66     0     0
lo0   16384 fe80:3::1     fe80:3::1                0     -        0     -     -
lo0   16384 ::1           ::1                     18     -       18     -     -
lo0   16384 your-net      localhost               44     -       44     -     -
```


----------



## SirDice (Aug 20, 2010)

For "telnet localhost" to work there must be a telnet daemon listening on localhost. This has nothing to do with your mail problem or the problems with the telnet command. It only means there's nothing listening on port 23.

(And you shouldn't enable it either!)


----------



## jaymax (Aug 22, 2010)

> For "telnet localhost" to work there must be a telnet daemon listening on localhost.



I did not start the daemon because of a Post from *wblock* which said ==>


> All you need for testing an SMTP server is the telnet client. Enabling the telnet server is not necessary and to be avoided.



I mentioned that I do not use telnet, I use SSH and am only running telnet for trouble shooting purposes. So it will only be in use for an hour or two

Now I have the daemon activated, replaced the /etc/services file from /usr/src/etc/services
and telnet now starts with a SRA intrusion.


```
telnet 127.0.0.1
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Trying SRA secure login:
```

This intermediate steps apparently inhibits getting to the # 25 port as in 
telnet 127.0.0.1 25

How do I turn this off, I cannot find anything to this effect in the pages etc.


----------

