Hi all,

I am using Ubuntu 10.4 LTS and I need to get telnet server on my machine to work (connect) to localhost at port 4242. I tried:

~> telnet localhost 4242
Trying ::1...
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

*telnet does work (for example on port 23).
Tried to flush/open possible firewall issues by using:

~> sudo ip6tables --flush
~> sudo iptables --flush
~> sudo ufw allow 4242

And still nothing works. Also used nmap to scan open ports on localhost ( sudo nmap localhost ) and port 4242 doesn't appear there.

What am I missing? How can I configure telnet server to be opened on port 4242?
Thanks a bunch!
-Ruslan

Dani AI

Generated

— "Connection refused" means the kernel refused the TCP connect because nothing is listening on that port (see the connect(2) errno descriptions) [https://man7.org/linux/man-pages/man2/connect.2.html]. Changing /etc/services only maps a name to a port; it does not make any process bind that port (services(5)). Because your telnetd is already serving on 23, you need to configure the same server to be started for 4242 as well (or run a separate listener).

A safe approach on Ubuntu 10.04 is either:

  • Add an alias in /etc/services and add a matching line for that service to your inetd config so inetd will listen on the new port. Use the same telnet server binary referenced by the existing telnet entry.
  • Or, install/use xinetd and create an xinetd service file that points the new port at the telnet server; xinetd has a bind option so you can restrict the listener to 127.0.0.1 if you only want localhost access (Debian/xinetd docs: https://wiki.debian.org/xinetd).

Example entries you will adjust are the service-name in /etc/services and a corresponding inetd/xinetd service definition (use the same server path that your current telnet entry uses). After editing, reload the super-server (openbsd-inetd/xinetd) so it re-reads the config.

Verify a listener after reload with tools like ss/netstat or lsof (look for a LISTEN socket on :4242). If your client tries ::1 first (as your telnet output shows), remember to bind an IPv6 listener or add a ::1 bind as well. Finally, telnet transmits credentials in plaintext; do not expose this port beyond loopback and prefer SSH for remote shell access (telnet is insecure: https://en.wikipedia.org/wiki/Telnet).

Ok there is a partial solution to that:
by editing /etc/services I can change telnet port from 23 to 4242. Is it possible to add a port? Meaning that telnet connections be made both through 23 and 4242?

Thanks a bunch,
-R

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.