this post was submitted on 09 Feb 2026
32 points (97.1% liked)

Selfhosted

56208 readers
1526 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:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

  7. No low-effort posts. This is subjective and will largely be determined by the community member reports.

Resources:

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

Questions? DM the mods!

founded 2 years ago
MODERATORS
 

So I have some services and wireguard running locally on a "home" network. I also have wireguard, a DNS resolver, and a reverse proxy set up on a remote server. Since I don't want to expose the home IP to the public, to access my services I connect to the VPN on the remote, which then forwards my request home. But this means that when I'm at home, connecting to my local services requires going out to the remote. Is there some way to have the traffic go over the switch when at home, but go over wireguard when away, without having to manually switch the VPN on/off?

I could move the DNS resolver (which handles the internal names for the services) from the remote to the home server. But then similarly every DNS request will need to go through both the remote and home servers, doubling the hops. I'd like to use my own DNS server at all times though, both at and away from home. Which tradeoff seems better?

edit: thanks for all the suggestions, I'll look into some of these solutions and see what works best

all 23 comments
sorted by: hot top controversial new old
[–] tangeli@piefed.social 3 points 2 hours ago

You might find the techniques used in Network-Aware Firewall useful. You can use firewall configuration to handle connections differently depending on whether you are connected to your home network or not. Or you can use the same techniquest to do other things, depending on network connection, like bringing up your VPN or not; modifying DNS or hosts file or not; etc.

[–] plateee@piefed.social 1 points 2 hours ago (1 children)

Could you do a subdomain for internal? Using Nginx host base routing to get to the same port would let you have a valid cert for both service.lan.your.fqdn and service.your.fqdn.

Let's Encrypt wildcard certs for the *.lan.your.fqdn would simplify things.

Your DNA server could then resolve the lan fqdns to your internal network and the non-lan to your Internet exposed?

[–] mrh@mander.xyz 2 points 1 hour ago (1 children)

Yes that would work, but it feels a bit cumbersome to have 2 fqdns per service, which I would have to switch between using depending on on whether I'm local or not.

[–] plateee@piefed.social 1 points 43 minutes ago

Yeah, in that case, I'd probably split my DNS duties. I started with internal resolution by having Pihole do hard coded DNS entries for internal systems, but my current setup seems to be much more resilient.

I have two PowerDNS servers (main and replica) with recursors to Open DNS internet servers and resolvers for my lab network. It plays very nicely with Terraform or (crucially lately) Kubernetes.

[–] Shimitar@downonthestreet.eu 9 points 5 hours ago (1 children)

Going the split DNS way is doable but had other issues (android devices bypassing local DNS for example or DNS over HTTPS issues)

I set up my opnSense to redorect all internal traffic to the external IP on port 443 to my internal server ip.

Works fine, it's transparent, and doesn't mess with DNS.

[–] mrh@mander.xyz 2 points 5 hours ago

And so when away do you just directly connect to the external IP and do port forwarding?

[–] French75@slrpnk.net 3 points 4 hours ago

I have opnsense, and it was pretty easy. I use DNS overrides and a local reverse proxy. When I'm on the home network, the local dns overrides point to the local reverse proxy. When I'm outside the home, public DNS records point to my VPS, which reverse proxies the traffic to my home machine. This way I'm only hitting the VPS when I'm outside the home. Much more efficient.

I think Side of Burritos' youtube channel has a guide on how to set this up, but it's fairly straightforward.

[–] Willoughby@piefed.world 2 points 4 hours ago* (last edited 4 hours ago) (1 children)

My Setup:

OpenWRT Router: wireguard server, backup DNS

NAS: Main DNS Server - pihole, no wireguard

VPS: Client - Endpoint 10.1.99.0/24, 192.168.2.0/24

Phone: Client - Endpoint 0.0.0.0/0, ::/0

10.1.99.0 clients can talk to 192.168.2.0 clients and back and forth. The NAS can talk to anyone, anyone can talk to the NAS. Any new client can talk to anything.

They all use the NAS for DNS, so they all resolve hostnames and domain names.

why not dns on the router?

I didn't like the unbound/adblock gui on Openwrt. I like pihole more. Personal pref.

[–] nymnympseudonym@piefed.social 1 points 1 hour ago

I too run a PiHole in an RPi, physically plugged in to my OpenWRT router

[–] pedroapero@lemmy.ml 2 points 4 hours ago (2 children)

There are Wireguard clients that connect based on wifi / mobile status. On f-droid WG Tunnel, WG Auto Connect, or Rethink should do.

[–] mrh@mander.xyz 1 points 4 hours ago* (last edited 4 hours ago) (1 children)

Right but I want to be connected to wireguard always, I just want the DNS/routing to be different based on home vs foreign network.

[–] non_burglar@lemmy.world 2 points 3 hours ago

WG Tunnel. It does exactly this.

When I leave my WiFi, tunnel turns on. When I rejoin my WiFi, tunnel turns off.

[–] slazer2au@lemmy.world 4 points 6 hours ago (1 children)

Adguard home has a DNS rewrite function that you can use to rewrite local DNS queries.

I use it to rewrite my queries at home to point to the LAN IP. When I am out I get my public IP from normal resolvers.

[–] mrh@mander.xyz 1 points 5 hours ago (1 children)

So you have a public DNS record pointing to your home IP?

[–] motruck@lemmy.zip 3 points 1 hour ago* (last edited 1 hour ago) (1 children)

DNS server you use from your home network retuns 192.168.1.20 for your service hosted at jellyfin.Bob.org

The DNS server you hit when publically looks up jellyfin.Bob.org and gets the IP from the nameserver you have set with your domain registrar often just theirs and you set this to your home WAN ip.

You have to configure both. I use opentofu / terraform to configure both all from the CLI. Any software like DNS that has a bunch of implementations that doesn't have Open-Tofu support gets skipped and an alternative is found at this stage. You just can't beat config as code for this type of set up.

You can also use NAT reflection which will effectively reroute the connection from within your network to your external IP to work on your local network.

I started with reflection and ended up going to the multiple DNS servers as it felt cleaner and I already was running Adguard so why not.

Both adguard and pihlle have opentofu modules.

Rereading your post (heh): In your case I'd just always serve over the wireguard ip local or not. Why do you want to use the local IP vs wireguard? The overhead of wireguard is pretty low

[–] mrh@mander.xyz 1 points 18 minutes ago* (last edited 15 minutes ago)

Oh hm I didn't think about your last point, maybe it's not really an issue at all. I think I'm not 100% on how the wireguard networking works.

Suppose I tunnel all of my traffic through wireguard on the remote server. Say that while I am home, I request foo.local, which on the remote server DNS maps to a wireguard address corresponding to my home machine. The remote will return to me the wireguard address corresponding to the home machine, and then I will try and go to that wireguard address. Will the home router recognize that that wireguard address is local and not send it out to the remote server?

[–] damnthefilibuster@lemmy.world 1 points 4 hours ago

I just use Avahi to use a .local domain when at home. That way felt easier. Also, I have separate bookmarks for “heimdall” and “heimdall-away” on my phone.

[–] tophneal@sh.itjust.works 1 points 5 hours ago* (last edited 5 hours ago)

I ran into a similar issue when visiting some family. Even though I was connected to home via VPN, my devices wouldn't pull servers by their IPs. Our networks were setup too similarly. I was able to fix it by editing my conf for the WG connection and added my static servers as allowed IPs. While still having to self host a server for accounting at work, we did a similar split setup so they would be able to use RDP to their desktops but all other traffic was ignored and handled locally. This forum post has pretty good, short explanation with some example config scenarios https://forum.mikrotik.com/t/wireguard-allowed-ips-unofficial-wireguard-documentation/156426

[–] Decronym@lemmy.decronym.xyz 1 points 5 hours ago* (last edited 5 minutes ago)

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:

Fewer Letters More Letters
DNS Domain Name Service/System
HTTP Hypertext Transfer Protocol, the Web
HTTPS HTTP over SSL
IP Internet Protocol
NAS Network-Attached Storage
NAT Network Address Translation
PiHole Network-wide ad-blocker (DNS sinkhole)
RPi Raspberry Pi brand of SBC
SBC Single-Board Computer
SSD Solid State Drive mass storage
SSL Secure Sockets Layer, for transparent encryption
VPN Virtual Private Network
VPS Virtual Private Server (opposed to shared hosting)

[Thread #78 for this comm, first seen 9th Feb 2026, 22:20] [FAQ] [Full list] [Contact] [Source code]

[–] ppb1701@ppb.social 1 points 6 hours ago (1 children)

@mrh
I did similar thing for my selfhosted vaulwarden with tailscale and their funnel. give the client apps my tailscale address and i can hit on lan or off as long as the device is in the tailnet....and well the server is up 😎

[–] mrh@mander.xyz 2 points 5 hours ago

I think tailscale would work, though I'd ideally want to use something like headscale instead, but that's a bit of a logistical hastle for my setup. Do you know if pangolin can handle this as well?

[–] FreedomAdvocate -2 points 5 hours ago