Failing to unblock a port to use telnet on a non-standard port

I have changed telnet port to 9999 via /etc/services but I cannot make it work.

On default port, I can telnet localhost and it works fine but after the change I cannot connect via telnet localhost 9999. I have attempted yay -Rv firewalld yet the port is still locked.

Here is the list of my currently running services:

List of running services

#systemctl | grep running
proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats File System Automount Point
init.scope loaded active running System and Service Manager
session-2.scope loaded active running Session 2 of User anon
accounts-daemon.service loaded active running Accounts Service
atd.service loaded active running Deferred execution scheduler
avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
dbus-broker.service loaded active running D-Bus System Message Bus
dirmngr@etc-pacman.d-gnupg.service loaded active running GnuPG network certificate management daemon for /etc/pacman.d/gnupg
NetworkManager.service loaded active running Network Manager
opensnitchd.service loaded active running Application firewall OpenSnitch
polkit.service loaded active running Authorization Manager
power-profiles-daemon.service loaded active running Power Profiles daemon
rtkit-daemon.service loaded active running RealtimeKit Scheduling Policy Service
sddm.service loaded active running Simple Desktop Display Manager
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running User Login Management
systemd-udevd.service loaded active running Rule-based Manager for Device Events and Files
tor.service loaded active running Anonymizing overlay network for TCP
udisks2.service loaded active running Disk Manager
upower.service loaded active running Daemon for power management
user@1000.service loaded active running User Manager for UID 1000
wpa_supplicant.service loaded active running WPA supplicant
avahi-daemon.socket loaded active running Avahi mDNS/DNS-SD Stack Activation Socket
dbus.socket loaded active running D-Bus System Message Bus Socket
dirmngr@etc-pacman.d-gnupg.socket loaded active running GnuPG network certificate management daemon for /etc/pacman.d/gnupg
systemd-journald-dev-log.socket loaded active running Journal Socket (/dev/log)
systemd-journald.socket loaded active running Journal Sockets
systemd-udevd-control.socket loaded active running udev Control Socket
systemd-udevd-kernel.socket loaded active running udev Kernel Socket

$ telnet localhost 9999

Trying ::1… Connection failed: Connection refused Trying 127.0.0.1… telnet: Unable to connect to remote host: Connection refused

What could be blocking the port?

I don’t seem to have nftables or iptables running so there shouldn’t be anything to block it.

Are you sure that /etc/services is the configuration file for the port? According to my reading of man services, it’s just a text file that makes it easier to find a port for a service.

Better look into the telnet configuration file for systemd, there should be a service that can be edited using systemctl edit <servicename> (probably telnet, I don’t have it installed). There is usually the configuration for the service.

If I set telnet to default 23 in /etc/services then it works, but if I set any other port in the file, it stops working, so I assume it is the configuration file.

Still looking for a solution.

I do not have any other firewall but firewalld but even with firewalld disabled and iptables and nftables not running the issue remains.

How did you install telnetd? I would guess you are using it thru systemd and not with xinetd

Edit telnet.socket

sudoedit /usr/lib/systemd/system/telnet.socket

Locate ListenStream=23 and change it to ListenStream=9999

Then do

sudo systemctl daemon-reload 
sudo systemctl restart telnet.socket
systemctl status telnet.socket

I tried suggesting to @Tiravian that the file might not be the right place to configure the port. I mean setting it to the default port and using the default port successfully is indistinguishable from the application using the default port and /etc/services not being the correct place to re-configure the port.

Maybe @Tiravian should look into a reconfiguration of the port using systemd, as I suggested above. The correct way to do it would be to

sudo systemctl edit

and override the port there. Directly editing the systemd file will probably result in it being overwritten by the next telnet service update.

Yes, agreed they should use systemctl edit, but I think it would confuse them more, because you need to clear ListenStream with empty value first. The proper ™ way to do it would be

sudo systemctl edit telnet.socket

then in the override file

[Socket]
ListenStream=
ListenStream=9999

Ended up as other package breaking nftables configs, after fixing them everything works.