Start telnet server with "nix shell" command

I tried to establish a telnet connection between my Windows 11 machine and my NixOS machine, but it said “could not establish connection, connection timed out” kind of message on puTTY which I used on the Windows 11 side.

I used the following on NixOS.

nix shell nixpkgs#busybox
sudo telnetd -F

On the Windows 11 side, I simply used puTTY to connect to the NixOS machine on port 23 using telnet.
The error says

Network error: Connection timed out

What am I doing wrong?

PS: Both machines are connected to the same router via ethernet cable, and I checked the IP of my NixOS telnet server using ip a before connecting with puTTY on Windows 11.

On the NixOS machine you would want to run the telnetd command (e.g., sudo telnetd -F), not telnet. You connect to a telnet server with the command telnet, you start the telnet daemon on a server with telnetd.

With that out of the way, it sounds like a puTTY configuration or networking error. I have no issues connecting to the busybox telnet daemon running on my NixOS host which was started with sudo telnetd -F. I did notice I have to specify a program to run at login otherwise it just closes the connection after successfully connecting.

1 Like

You are right, and sorry, that’s what I did, but I forgot the “d” in my message above.

So, after running sudo telnetd -F, I checked the telnet server is indeed listening on default port 23.

$ netstat -tuln | grep :23
tcp6       0      0 :::23                   :::*                    LISTEN   

But still, the connection fails from the Windows 11 machine, after hanging up for a few minutes.

I also tried on my smartphone using Termius app, and got the same error.

So I am wondering if there is any setting I am missing on the NixOS side.

The only other thing I can think of is that NixOS enables the firewall by default, have you either disabled the firewall on the NixOS machine or poked a hole in it to allow port 23?

1 Like

@bzLem0n ,

I have the firewall TCP port 23 opened when I check my current config with nix repl '<nixpkgs/nixos>'.
Here is the value I get for the currently open ports.

nix-repl> config.networking.firewall.allowedTCPPorts
[ 22 23 27015 27036 ]

I tried to explicitly mark it open in my configuration.nix, then sudo nixos-rebuild switch, then running a new terminal and the telnet server.
This time, I tried to connect from my smartphone with the Termius app, and interestingly enough, the error now is error: connection reset by peer.

Which is strange, because it does sound like a port blocked from server side, right?

Maybe I should tell the background of this issue. I wanted to setup an SSH connection between my Windows 11 and NixOS PCs, so I thought of sending my Windows 11 SSH pubkey over telnet to the NixOS PC. Turns out to be harder than I thought, so I ended up using the SneakerNet ( ;D ) instead.

But still, it’d be cool to setup telnet which I’ve never used.
I checked the router settings like address translations but nothing telling me the 23 is blocked.
If nothing works, I may try a different approach which is to set up a telnet server on Windows 11 and connect from NixOS.

I believe you got it working by opening the port as the message error: connection reset by peer is what telnetd returns when you connect successfully but haven’t specified a login command. Try launching the server with something like sudo telnetd -F -l bash but be aware that will connect to a root bash shell.

It worked as you explained, thanks!
Just double checking my setup was the right thing to do.
Now I have to learn telnet :wink:
Thanks guys!