Saturday, July 30, 2022

[new] net/lstun -- lazy ssh tunnel

hello ports,

i wrote this little utility some time ago. it's a simple program that
binds a local port and lazily spawns an ssh tunnel to the configured
destination when a client attempts to connect to it and forwards the
data remotely. Optionally, the ssh tunnel is killed after some
configurable time of inactivity.

i'm currently using to send emails. I have

@reboot /usr/local/bin/lstun -B 2026:localhost:25 -b 2525 example.com

in my crontab and the following in smtpd.conf(5)

action "example" relay host localhost:2525

so then i have lstun listening on localhost:2525 and lazily spawning an
ssh tunnel on localhost:2026 to example.com:25. smtpd connects to
localhost:2525 and it transparently talks to port 25 on example.com :)

it's narrow use-case, but i needed something like that and i don't think
i've found a tool to accomplished it out of the box; plus, it was fun to
write.

No comments:

Post a Comment