0

I’m renting a VPS and wanted to use it to send my mail. But the only VPN connection I’ve got to it is via Tailscale. So I thought, why not use it as an exit node and send my mail that way?

Well, there are a few problems to this idea, most are self inflicted. The first mayor one is that I do not want to use the exit node for anything other than email, so no package updates or anything else. The second one is that it needs to be accessible through my Tailnet. Either directly or through a subnet router that I have in the same network.

My first attempt was to simply install Tailscale the normal way, enable the exit node and add some routing rules using ip rule to direct only traffic targeting port 25 into the Tailnet and leave everything else to the normal routes. This worked, at least for sending mail and accessing the Internet, but connectivity from the Tailnet did not work at all. So I had to figure something else out.

The solution that I found in the end was to use Tailscales userspace-networking feature, originally intended for containers that do not have access to /dev/tun. This works by creating a SOCKS5 or HTTP Proxy that the application can connect to to access the Tailnet. So far so good, the only problem was that my MTA, Postfix, does not support either to send mail.

So to fix that I needed another piece of software called Redsocks. It allows you to route arbitrary connections through a SOCKS5 Proxy, with the help of a firewall. Since Tailscale has a dependency on NFTables (at least on Debian) I chose to use it for this setup.

So, this is how I configured everything in the end: Tailscaled is started with the flags --tun=userspace-networking --socks5-server=localhost:20000 easily configured in /etc/default/tailscaled. I connected it to my Tailnet and enabled the exit node, making sure that the ACLs allowed a connection to the internet on port 25.

Redsocks is configured to route the requests to Tailscale by setting the following in its /etc/redsocks.conf

base {                                                                                                                                                                                       
        // my common settings, not relevant here
}
redsocks {
        local_ip = 127.0.0.1;
        local_port = 20001;
        ip = 127.0.0.1;
        port = 20000;
        type = socks5;
}

Now I can route any request to my exit node using NFTables. This is done by adding a new NAT table with a chain called REDSOCKS. This chain redirects all requests that it handles to Redsocks on the correct port. I configured this using the legacy iptables interface since I know how to use it. First creating the chain with iptables -t nat -N REDSOCKS then add the redirect with iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 20001 and finally the rule to direct any traffic from Postifx there iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner postfix -m tcp --dport 25 -j REDSOCKS.

The end result was a working setup sending my mail, and only my mail, through my VPS. But we aren’t quite done yet. If the system reboots then the firewall rules are lost. Using nft list ruleset to get the rules that NFTables generated and saving it to /etc/nftables.conf persists the firewall changes as well. Here is the section that I needed to add:

table ip nat {
        chain REDSOCKS {
                ip protocol tcp counter packets 1 bytes 60 redirect to :20001
        }

        chain OUTPUT {
                type nat hook output priority dstnat; policy accept;
                ip protocol tcp skuid 103 tcp dport 25 counter packets 1 bytes 60 jump REDSOCKS
        }
}

This was quite the adventure using Tailscale in a way that is apparently wasn’t intended to be used. But I’m quite happy with the end result. I hope that this small guide can be of use for some of you.

top 1 comments
sorted by: hot top new old
[-] greyfox@lemmy.world 1 points 2 hours ago

I'm not very familiar with Tailscale, but what are you using for a home firewall/router?

If your firewall has the capability to setup a vpn tunnel as a site to site connection you could do policy based routing and match the specific traffic that you want to route through the vps.

This keeps all of the config off of your email server and lets you easily select other traffic from any machine on your network to route through the vps in the future.

this post was submitted on 01 Dec 2026
0 points (NaN% liked)

Selfhosted

64254 readers
154 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

Detailed Rules Post

  1. Be civil.

  2. No spam.

  3. Posts are to be related to self-hosting.

  4. Don't duplicate the full text of your blog or readme if you're providing a link.

  5. Submission headline should match the article title.

  6. No trolling.

  7. Promotion posts require active participation, with an account that is at least 30 days old. F/LOSS without a paywall has exceptions, with requirements. See the rules link for details. Tags [CBH] or [AIP] are required, see the links in Rule 8 for details.

  8. AI-related discussions and AI-involved promotional posts have additional requirements for tagging, as noted in Rule 7 and the AI & Promotional Post Expanded Rules post, and find example disclosures here.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 3 years ago
MODERATORS