Add Bonjour/mDNS service discovery for VPN clients#1815
Add Bonjour/mDNS service discovery for VPN clients#1815mav2287 wants to merge 3 commits intohwdsl2:masterfrom
Conversation
Add optional Bonjour/mDNS service discovery so VPN clients can see devices on the server's local network (printers, AirPlay, file shares, etc.). Uses a real-time event-driven watcher that monitors multicast mDNS traffic and generates native dnsmasq DNS-SD records within seconds of devices appearing or disappearing on the LAN. Supports IKEv2, IPsec/XAuth, and IPsec/L2TP modes. Detects IKEv2-only mode, existing DNS servers, and custom VPN subnets. Closes hwdsl2#1232
- Replace modecfgdomains="local" with modecfgdomains="local, ." to prevent split DNS. The "." (root domain) acts as a catch-all so VPN DNS handles ALL queries, preventing DNS leak to the client's cellular/WiFi DNS. - Add strict-order to dnsmasq config to ensure internal DNS server is queried before public DNS, preventing NXDOMAIN race conditions for internal domains (.private, etc.) - Add iptables DNAT rule to capture mDNS multicast (224.0.0.251) from VPN clients and redirect to dnsmasq as additional fallback - Remove detect_search_domains() — no longer needed with catch-all approach
|
@mav2287 Hello! Thank you for your contribution. I plan to take a more detailed look when I have time. From a brief review, please remove the added |
|
Thanks for taking a look, this took a LONG time to figure out so there may need to be some tweaks and adjustments. I updated the files. Just let me know if there is anything else you need. |
|
Thanks for the detailed PR. The architecture is well thought out and the documentation is thorough. I've reviewed the scripts and have a few items to address before merging. Blockers1. In VPN_SERVER_IP="${VPN_SUBNET_PREFIX}.2" # expands to ".2"
2. Both scripts use PCRE grep ( These need to be rewritten using POSIX ERE (
Should Fix3. Full-tunnel DNS override needs a clear warning Setting 4. The backup restoration handles the common case correctly. In the fallback (no backup exists), the sed range 5.
6. Debounce loop in A chatty device can keep resetting the 3-second timer indefinitely, preventing 7. VPN clients use the DNS address pushed over the tunnel, not the server's Worth Noting8. With the reflector enabled, a VPN client's own mDNS announcements (device name, advertised services) get forwarded to the local LAN, so LAN devices can see what the VPN client is advertising. For a home VPN this is likely acceptable, but it should be documented. Setting MinorThe |
Summary
Adds optional Bonjour/mDNS service discovery so VPN clients can see devices on the server's local network — printers, AirPlay, file shares, and other services that advertise via mDNS/DNS-SD.
Closes #1232
How it works
A real-time service watcher uses
avahi-browseto passively monitor multicast mDNS traffic on the LAN. When devices appear or disappear, it generates native dnsmasq DNS-SD records (PTR, SRV, TXT) within seconds. VPN clients query dnsmasq through the tunnel and get the same service discovery results they would on the local network.The watcher is event-driven — zero CPU/network overhead when nothing changes. It listens to multicast packets already on the network.
Supports all three VPN modes:
Detects IKEv2-only mode (
ikev1-policy=drop) and skips XAuth/L2TP configuration when active. Detects existing DNS servers (BIND, etc.) on port 53 and uses an alternate IP to avoid conflicts. Handles custom VPN subnets.Files changed
extras/enable_bonjour.sh— Enable script (installs avahi + dnsmasq, sets up real-time service watcher for all detected VPN modes)extras/disable_bonjour.sh— Cleanly reverts all changes from backupsextras/vpnuninstall.sh— Added warning to run disable_bonjour.sh before uninstalling VPNdocs/advanced-usage.md/docs/advanced-usage-zh.md— New documentation sectionREADME.md+ all language variants (zh, zh-Hant, ja, ru) — Added link in Advanced usage listTest plan