I've been learning about socket programming recently, and am just beginning learning about tcp/ip sockets. My study material gives an example of connecting to the localhost daytime service by running telnet 127.0.0.1 13 with the expected result that a telnet session should be opened. I have an entry for daytime 13/tcp in my /etc/services file, and I have the xinetd service running, but when I try the telnet command, I immediately get Connection refused.Q: why doesn't telnetting to the daytime service work?Q: are there other localhost services that would accept a telnet connection? I tried to telnet to a random selection of services that had tcp entries in /etc/services, but all of them gave the same Connection refused error.My short-term goal is just to replicate my study material's successful telnet connection to a localhost tcp service - if not inetd, then anything else; I just want to learn by practice.>telnet 127.0.0.1 13Trying 127.0.0.1...telnet: connect to address 127.0.0.1: Connection refused>telnet 127.0.0.1 49000Trying 127.0.0.1...telnet: connect to address 127.0.0.1: Connection refused>telnet 127.0.0.1 9009Trying 127.0.0.1...telnet: connect to address 127.0.0.1: Connection refused>uname -aLinux linuxbox 3.11.10-301.fc20.x86_64 #1 SMP Thu Dec 5 14:01:17 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
What services accept tcp connection?
fedora;services;telnet;xinetd;inetd
The /etc/services does not indicate what services are actually running. See purpose of /etc/services. You will need to find a service that is running (or start one). You can see what is listening by looking at netstat -nlt. The particular services will vary, but you will see something like:$ netstat -nltActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         Statetcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTENtcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTENtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTENtcp6       0      0 :::3306                 :::*                    LISTENtcp6       0      0 :::111                  :::*                    LISTENtcp6       0      0 :::22                   :::*                    LISTENtcp6       0      0 ::1:631                 :::*                    LISTENtcp6       0      0 ::1:25                  :::*                    LISTENSo:daytime service is probably not running. If it does not appear in the list (and you can see from the listing above I do not have it running), then nothing is listening on the port. It may be possible to start the service if it is installed.There are lots of other potential services depending upon what is installed and active. In the listing above, port 25 is listening, which is the mail service. So I could connect via telnet to port 25. As telnet is not installed by default, I use nc to connect, but the principle is the same:$ nc 127.0.0.1 25220 centos7.feedthecoder.com ESMTP PostfixHELO me.theworld.com...Edit: as mentioned in a comment, it could of course be a firewall issue. Generally installations do not block 127.0.0.1, but it is always a possibility.Also, depending upon your distribution, daytime may not be installed, which would be a further impediment. If it is installed, you should be able to start it via the normal service start (e.g., service start daytime, or the distro equivalent).Edit: it turns out that daytime is provided solely by xinetd as an internal service. So while the information above about listing services is correct, to have daytime, ensure that xinetd is installed, and that the file /etc/xinetd/daytime-stream has disabled set to no.