A personal VPN gateway becomes more complicated as soon as it must do more than carry ordinary Internet traffic. In this deployment, every personal device needs a stable Finnish IPv4 and IPv6 identity, DNS must remain inside the tunnel, and a corporate MacBook must still reach private services through either the office network or Feilian without disrupting its home LAN.
This article documents the resulting design on a Hetzner server running Ubuntu 26.04 LTS. It covers the server, Apple clients, recursive DNS, split DNS, and the three-state macOS routing policy that ties the system together.
Designing the gateway
The deployment starts from a set of required behaviours rather than from a chosen topology. The architecture and the address plan follow from those requirements, not the other way round.
Objectives
The gateway must provide the following behaviour:
- All IPv4, IPv6, and DNS traffic from an iPhone, personal MacBook, and Mac mini passes through the Hetzner server.
- Every personal device presents the same stable Finnish egress addresses to the public Internet.
- The server runs a local recursive resolver, preventing client DNS traffic from escaping the tunnel.
- Apple devices use system-level On-Demand VPN rules for automatic start-up, background operation, and reconnection after a network change.
- A corporate MacBook can run the Hetzner full tunnel while continuing to reach the corporate network.
- In the office, corporate traffic goes directly through the physical gateway.
- At home, when Feilian is connected, corporate traffic uses the Feilian tunnel.
- At home without Feilian, no stale corporate routes remain.
- Devices on the home LAN continue to communicate directly rather than through Hetzner or Feilian.
The design therefore has three paths:
Public traffic:
Apple client
--> WireGuard full tunnel
--> Hetzner Finland
--> Internet
Corporate traffic in the office:
Corporate MacBook
--> en0
--> corporate gateway
--> corporate network
Corporate traffic at home with Feilian:
Corporate MacBook
--> Feilian utunN
--> corporate network
Architecture
Internet
^
|
+---------------+----------------+
| Hetzner Finland server |
| Ubuntu 26.04 LTS |
| |
| Public IPv4 |
| 204.168.142.215 |
| |
| Public IPv6 |
| 2a01:4f9:c014:e6d2::1 |
| |
| wg0 |
| 10.8.0.1/24 |
| fd42:8::1/64 |
| |
| NAT44 + NAT66 |
| Unbound DNS |
+---------------+----------------+
|
WireGuard IPv4/IPv6 full tunnel
|
+--------------------+--------------------+
| | |
iPhone Personal MacBook Personal Mac mini Personal
10.8.0.3 10.8.0.4 10.8.0.5
fd42:8::3 fd42:8::4 fd42:8::5
|
MacBook NIO
10.8.0.2
fd42:8::2
|
+------------------+-------------------+
| | |
Public traffic Office network Home + Feilian
--> Hetzner WG --> en0 gateway --> Feilian utunN
Address plan
The WireGuard network uses these internal ranges:
IPv4 subnet: 10.8.0.0/24
IPv6 subnet: fd42:8::/64
| Device | WireGuard IPv4 | WireGuard IPv6 |
|---|---|---|
| Hetzner server | 10.8.0.1/24 |
fd42:8::1/64 |
| MacBook NIO | 10.8.0.2/24 |
fd42:8::2/64 |
| iPhone Personal | 10.8.0.3/24 |
fd42:8::3/64 |
| MacBook Personal | 10.8.0.4/24 |
fd42:8::4/64 |
| Mac mini Personal | 10.8.0.5/24 |
fd42:8::5/64 |
Each server-side peer receives exact host routes:
10.8.0.X/32
fd42:8::X/128
Every device needs its own private key, public key, IPv4 address, IPv6 address, and server-side peer entry. Never share a WireGuard key pair or an internal address between devices.
Building the server
The server side is built in a single pass, from a bare Ubuntu install to a running tunnel with its own recursive resolver.
Server environment
The server used here has the following properties:
Operating system: Ubuntu 26.04 LTS
Public interface: eth0
Public IPv4: 204.168.142.215
Public IPv6: 2a01:4f9:c014:e6d2::1/64
WireGuard UDP port: 51820
Before beginning, the server should already have:
- a normal administrative user named
ailven, which is the only non-root user withsudoaccess; - direct root SSH login disabled;
- SSH key authentication enabled;
- UDP port 51820 allowed by the Hetzner firewall or the host firewall; and
- working public IPv4 and IPv6 connectivity.
Install the required packages:
sudo apt update
sudo apt install -y wireguard qrencode unbound dnsutils tcpdump
Enable IPv4 and IPv6 forwarding
Create /etc/sysctl.d/99-wireguard.conf:
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.default.forwarding=1
Apply and verify the settings:
sudo sysctl --system
sysctl net.ipv4.ip_forward
sysctl net.ipv6.conf.all.forwarding
sysctl net.ipv6.conf.default.forwarding
The expected values are:
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
net.ipv6.conf.default.forwarding = 1
WireGuard creates an encrypted layer-three interface; it does not, by itself, make the server a router. Successful Internet access still depends on kernel forwarding, FORWARD-chain rules, IPv4 NAT, and either IPv6 NAT or native IPv6 routing.
Manage WireGuard keys
Generate the server keys:
sudo -s
cd /etc/wireguard
umask 077
wg genkey | tee server_private.key |
wg pubkey > server_public.key
Generate a separate pair for every client:
wg genkey | tee macbook_nio_private.key |
wg pubkey > macbook_nio_public.key
wg genkey | tee iphone_personal_private.key |
wg pubkey > iphone_personal_public.key
wg genkey | tee macbook_personal_private.key |
wg pubkey > macbook_personal_public.key
wg genkey | tee macmini_personal_private.key |
wg pubkey > macmini_personal_public.key
Set restrictive permissions:
sudo chmod 600 /etc/wireguard/*private.key
sudo chmod 644 /etc/wireguard/*public.key
Only server_private.key is required for normal server operation. Once each client configuration has been imported, its private key should not remain on the server.
Configure the WireGuard server
Create /etc/wireguard/wg0.conf with the following structure:
[Interface]
Address = 10.8.0.1/24, fd42:8::1/64
ListenPort = 51820
PrivateKey = <SERVER_PRIVATE_KEY>
# IPv4 forwarding and NAT44
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostUp = iptables -A FORWARD -o wg0 -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
PostDown = iptables -D FORWARD -o wg0 -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
# IPv6 forwarding and NAT66
PostUp = ip6tables -A FORWARD -i wg0 -j ACCEPT
PostUp = ip6tables -A FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
PostUp = ip6tables -t nat -A POSTROUTING -s fd42:8::/64 -o eth0 -j MASQUERADE
PostDown = ip6tables -D FORWARD -i wg0 -j ACCEPT
PostDown = ip6tables -D FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
PostDown = ip6tables -t nat -D POSTROUTING -s fd42:8::/64 -o eth0 -j MASQUERADE
[Peer]
# MacBook NIO
PublicKey = <MACBOOK_NIO_PUBLIC_KEY>
AllowedIPs = 10.8.0.2/32, fd42:8::2/128
[Peer]
# iPhone Personal
PublicKey = <IPHONE_PERSONAL_PUBLIC_KEY>
AllowedIPs = 10.8.0.3/32, fd42:8::3/128
[Peer]
# MacBook Personal
PublicKey = <MACBOOK_PERSONAL_PUBLIC_KEY>
AllowedIPs = 10.8.0.4/32, fd42:8::4/128
[Peer]
# Mac mini Personal
PublicKey = <MACMINI_PERSONAL_PUBLIC_KEY>
AllowedIPs = 10.8.0.5/32, fd42:8::5/128
Use the IPv6 ULA prefix consistently in every location:
Server address: fd42:8::1/64
Client address: fd42:8::X/64
Server peer AllowedIPs: fd42:8::X/128
NAT66 source: fd42:8::/64
Although compressed IPv6 forms can be equivalent, adopting one spelling throughout the configuration avoids subtle NAT and route-matching mistakes.
Start and manage WireGuard
Enable and start the interface:
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
For a complete restart, use:
sudo systemctl restart wg-quick@wg0
Inspect the service and the interface:
sudo systemctl status wg-quick@wg0 --no-pager
sudo wg show
An active (exited) state is normal. [email protected] is a oneshot unit: it creates wg0, applies the WireGuard parameters and addresses, sets the MTU, executes PostUp, and installs routes. The kernel then maintains the interface without a resident user-space process.
Perform a full restart after changing Address, ListenPort, PostUp, PostDown, NAT rules, the MTU, or other interface-level settings.
Verify the firewall and NAT
Inspect IPv4 rules:
sudo iptables -S FORWARD
sudo iptables -t nat -S POSTROUTING
They should include at least:
-A FORWARD -i wg0 -j ACCEPT
-A FORWARD -o wg0 -j ACCEPT
-A POSTROUTING -o eth0 -j MASQUERADE
Inspect IPv6 rules:
sudo ip6tables -S FORWARD
sudo ip6tables -t nat -S POSTROUTING
They should include at least:
-A FORWARD -i wg0 -j ACCEPT
-A FORWARD -o wg0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A POSTROUTING -s fd42:8::/64 -o eth0 -j MASQUERADE
Confirm that WireGuard is listening:
sudo ss -lunp | grep 51820
To observe the outer UDP exchange:
sudo tcpdump -ni eth0 udp port 51820
A normal handshake commonly appears as:
Client --> Server: UDP length 148
Server --> Client: UDP length 92
Client --> Server: UDP length 32
With PersistentKeepalive = 25, a small keepalive datagram should appear roughly every 25 seconds.
Run a private recursive resolver with Unbound
Clients use the WireGuard gateway itself as their DNS server:
Client
--> WireGuard
--> 10.8.0.1:53
--> Unbound recursive resolver
--> authoritative DNS hierarchy
This keeps DNS on the same path as public traffic, avoids dependence on the client’s local network, and leaves the resolver inaccessible from the public Internet.
Create /etc/unbound/unbound.conf.d/wireguard.conf:
server:
interface: 10.8.0.1
access-control: 10.8.0.0/24 allow
access-control: 0.0.0.0/0 refuse
hide-identity: yes
hide-version: yes
prefetch: yes
prefetch-key: yes
serve-expired: yes
serve-expired-ttl: 3600
Validate, restart, and inspect the listener:
sudo unbound-checkconf
sudo systemctl restart unbound
sudo ss -lntup | grep ':53'
Unbound should listen on 10.8.0.1:53 over both UDP and TCP, not on 0.0.0.0:53 or [::]:53.
Test it directly:
dig @10.8.0.1 google.com A +dnssec +stats
Even when the server answers from cache, the latency observed by a remote client still includes at least one round trip to Finland.
Personal devices
With the server running, each personal device needs a profile and a mechanism for keeping the tunnel up without manual intervention.
Create the full-tunnel client profile
Use this template for each client:
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.8.0.X/24, fd42:8::X/64
DNS = 10.8.0.1
MTU = 1420
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = 204.168.142.215:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
AllowedIPs = 0.0.0.0/0, ::/0 sends all IPv4 and IPv6 traffic through WireGuard. DNS = 10.8.0.1 sends name resolution through the tunnel to Unbound. PersistentKeepalive = 25 preserves NAT state across mobile networks, home NAT, CGNAT, locked devices, network changes, and long idle periods.
Keepalive and On-Demand solve different problems:
PersistentKeepalive:
preserves an existing NAT mapping
On-Demand:
starts the VPN after a reboot, network change, or tunnel interruption
Configure each personal device
The iPhone profile is:
[Interface]
PrivateKey = <IPHONE_PRIVATE_KEY>
Address = 10.8.0.3/24, fd42:8::3/64
DNS = 10.8.0.1
MTU = 1420
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = 204.168.142.215:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
If iOS reports the tunnel as connected but the server receives no UDP traffic, the log contains no Sending handshake initiation, and unsatisfied route appears repeatedly, delete the old tunnel and recreate it. Begin with restricted routes:
AllowedIPs = 10.8.0.0/24, fd42:8::/64
Once the server observes a handshake, restore the full-tunnel setting:
AllowedIPs = 0.0.0.0/0, ::/0
The personal MacBook profile is:
[Interface]
PrivateKey = <MACBOOK_PERSONAL_PRIVATE_KEY>
Address = 10.8.0.4/24, fd42:8::4/64
DNS = 10.8.0.1
MTU = 1420
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = 204.168.142.215:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
The Mac mini profile is:
[Interface]
PrivateKey = <MACMINI_PERSONAL_PRIVATE_KEY>
Address = 10.8.0.5/24, fd42:8::5/64
DNS = 10.8.0.1
MTU = 1420
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = 204.168.142.215:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
Enable background operation on Apple devices
WireGuard tunnels on Apple platforms are managed by the system’s Network Extension framework. The graphical WireGuard application does not need to remain in the foreground.
On the iPhone, enable On-Demand activation for both Wi-Fi and cellular networks. This reconnects the tunnel after start-up, transitions between Wi-Fi and cellular, lock-screen periods, and temporary loss of connectivity.
On the personal MacBook, enable On-Demand for Wi-Fi and Ethernet. Do the same on the Mac mini; Ethernet must be selected if it is the machine’s normal connection.
There is no need to add the WireGuard GUI to Login Items. A login item merely opens the application and does not replace Network Extension’s automatic connection policy.
Verify the macOS connection with:
scutil --nc list
The tunnel should appear as:
(Connected) VPN (com.wireguard.macos)
Verify dual-stack egress
Check the public IPv4 address:
curl -4 https://api.ipify.org
echo
The expected result is 204.168.142.215.
Check the public IPv6 address:
curl -6 https://api6.ipify.org
echo
The expected result is 2a01:4f9:c014:e6d2::1.
Then test the internal gateway, public IPv6 reachability, and DNS:
ping -c 5 10.8.0.1
ping6 -c 5 fd42:8::1
ping6 -c 5 2606:4700:4700::1111
dig google.com A +stats
The DNS server reported by dig should be 10.8.0.1#53.
The corporate MacBook and dynamic routing
The corporate MacBook is the part a single full tunnel cannot solve, because its traffic has three different correct destinations depending on where the machine is.
Account for the corporate MacBook
The corporate MacBook uses all of the following at different times:
- the Hetzner WireGuard full tunnel;
- the physical office network;
- the home network;
- the Feilian corporate VPN;
- internal corporate DNS; and
- an internal SOCKS5
ProxyCommand.
The Hetzner profile installs full-tunnel routes:
0.0.0.0/0 --> Hetzner WireGuard
::/0 --> Hetzner WireGuard
Any corporate address without a more specific route will therefore be sent to Hetzner and become unreachable. The MacBook needs a routing policy that changes with its network environment.
Define the corporate private ranges
The core corporate ranges are:
10.0.0.0/8
100.64.0.0/10
172.16.0.0/12
The physical office network may additionally require 192.168.0.0/16. That entire range must not be forced through Feilian at home, because home LANs commonly use subnets such as 192.168.0.0/24, 192.168.1.0/24, 192.168.31.0/24, or 192.168.123.0/24.
The resulting policy is:
Office mode:
10/8 --> corporate physical gateway
100.64/10 --> corporate physical gateway
172.16/12 --> corporate physical gateway
192.168/16 --> corporate physical gateway
Feilian mode:
10/8 --> Feilian utunN
100.64/10 --> Feilian utunN
172.16/12 --> Feilian utunN
192.168/16:
not claimed wholesale by this script;
the home LAN remains local;
Feilian manages the more-specific 192.168.x routes it needs.
There is no need to manage 127.0.0.0/8 or 169.254.0.0/16. The former belongs to the loopback interface and the latter is link-local; the operating system installs both routes automatically.
Configure split DNS for internal domains
The corporate resolvers are:
10.110.3.129
10.110.3.130
The internal domains are nioint.com and nevint.com. Create the macOS resolver directory:
sudo mkdir -p /etc/resolver
Create both /etc/resolver/nioint.com and /etc/resolver/nevint.com with this content:
nameserver 10.110.3.129
nameserver 10.110.3.130
Flush the caches:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
Inspect the scoped resolvers:
scutil --dns | grep -A6 -B2 -E 'nioint\.com|nevint\.com'
Test resolution through the macOS system resolver:
dscacheutil -q host -a name nts-proxy.hlidc.nioint.com
The intended split is:
nioint.com and nevint.com
--> 10.110.3.129 / 10.110.3.130
All other domains
--> 10.8.0.1
--> Hetzner Unbound
A plain dig hostname does not necessarily reproduce macOS’s scoped-resolver selection. Prefer dscacheutil and scutil --dns when verifying the system path.
Model routing as three mutually exclusive states
The final script recognises three states.
State 1: the office network. The IPv4 address on en0 belongs to 10.110.32.0/20. Routes for 10/8, 100.64/10, 172.16/12, and 192.168/16 use the current physical gateway on en0.
State 2: an external network with Feilian connected. Feilian has installed a route to a known corporate anchor, in this case 10.137.10.37/32, on a utun interface. Routes for 10/8, 100.64/10, and 172.16/12 use that interface. The script deliberately does not add 192.168.0.0/16, thereby preserving the home LAN.
State 3: an external network without Feilian. The script removes every corporate bypass route it manages. Public traffic continues through Hetzner, whilst corporate destinations have no available corporate path. This is safer than sending private corporate traffic to the home gateway.
Discover the Feilian interface dynamically
macOS does not guarantee a stable utunN number. Feilian might currently be utun6 and WireGuard utun7, but a reboot, VPN reconnection, Network Extension rebuild, another VPN, or a sleep/wake cycle can change both numbers.
Never hard-code this:
FEILIAN_INTERFACE="utun6"
Instead, ask macOS for the route that Feilian installs to its anchor:
route -n get 10.137.10.37
If the result names interface: utun6, then utun6 is the active Feilian interface. Choose an anchor that exists only while Feilian is working, is installed by Feilian itself, remains stable, and cannot be confused with an exact route created by WireGuard or the physical network.
Install the dynamic routing script
Create /usr/local/sbin/wireguard-bypass-routes.sh:
#!/bin/bash
set -euo pipefail
PHYSICAL_INTERFACE="en0"
CORPORATE_NETWORK="10.110.32.0/20"
# A route installed by Feilian when its corporate tunnel is active.
FEILIAN_ANCHOR_IP="10.137.10.37"
# Broad corporate ranges used on both office Wi-Fi and Feilian.
CORE_CORPORATE_NETWORKS=(
"10.0.0.0/8"
"100.64.0.0/10"
"172.16.0.0/12"
)
# Used only on the corporate physical network.
# Do not install this through Feilian because it may cover the home LAN.
OFFICE_ONLY_NETWORKS=(
"192.168.0.0/16"
)
# Known cloned host routes that may retain a stale gateway/interface.
CLONED_HOSTS=(
"10.110.3.129"
"10.110.3.130"
"172.21.150.89"
)
log() {
printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*"
}
get_interface_ip() {
/usr/sbin/ipconfig getifaddr "$PHYSICAL_INTERFACE" 2>/dev/null || true
}
get_physical_gateway() {
/sbin/route -n get -ifscope "$PHYSICAL_INTERFACE" default 2>/dev/null |
/usr/bin/awk '/gateway:/{print $2; exit}'
}
ip_in_network() {
local ip="$1"
local network="$2"
/usr/bin/python3 - "$ip" "$network" <<'PY'
import ipaddress
import sys
try:
address = ipaddress.ip_address(sys.argv[1])
network = ipaddress.ip_network(sys.argv[2], strict=False)
except ValueError:
sys.exit(1)
sys.exit(0 if address in network else 1)
PY
}
get_feilian_interface() {
local interface
interface="$(
/sbin/route -n get "$FEILIAN_ANCHOR_IP" 2>/dev/null |
/usr/bin/awk '/interface:/{print $2; exit}'
)"
case "$interface" in
utun*)
printf '%s\n' "$interface"
;;
*)
return 1
;;
esac
}
delete_exact_network_route() {
local network="$1"
/sbin/route -n delete -net "$network" >/dev/null 2>&1 || true
}
delete_managed_routes() {
local network
for network in \
"${CORE_CORPORATE_NETWORKS[@]}" \
"${OFFICE_ONLY_NETWORKS[@]}"
do
delete_exact_network_route "$network"
done
}
clear_cloned_host_routes() {
local host
for host in "${CLONED_HOSTS[@]}"; do
/sbin/route -n delete -host "$host" >/dev/null 2>&1 || true
done
}
install_routes_via_gateway() {
local gateway="$1"
local network
delete_managed_routes
for network in \
"${CORE_CORPORATE_NETWORKS[@]}" \
"${OFFICE_ONLY_NETWORKS[@]}"
do
/sbin/route -n add -net "$network" "$gateway"
done
clear_cloned_host_routes
}
install_routes_via_feilian() {
local interface="$1"
local network
delete_managed_routes
for network in "${CORE_CORPORATE_NETWORKS[@]}"; do
/sbin/route -n add -net "$network" -interface "$interface"
done
# Deliberately do not add 192.168.0.0/16 here:
# - it could capture the home LAN;
# - Feilian keeps control of its own more specific 192.168.x routes.
clear_cloned_host_routes
}
main() {
local physical_ip
local physical_gateway
local feilian_interface
physical_ip="$(get_interface_ip)"
# State 1: directly connected to the corporate physical network.
if [[ -n "$physical_ip" ]] &&
ip_in_network "$physical_ip" "$CORPORATE_NETWORK"; then
physical_gateway="$(get_physical_gateway)"
if [[ -z "$physical_gateway" ]]; then
log "Corporate Wi-Fi detected, but no gateway was found on ${PHYSICAL_INTERFACE}" >&2
exit 1
fi
install_routes_via_gateway "$physical_gateway"
log "Mode=office: corporate routes installed through ${physical_gateway} on ${PHYSICAL_INTERFACE}"
exit 0
fi
# State 2: outside the office, but Feilian has installed its anchor route.
if feilian_interface="$(get_feilian_interface)"; then
install_routes_via_feilian "$feilian_interface"
log "Mode=feilian: corporate routes installed through ${feilian_interface}"
exit 0
fi
# State 3: neither corporate Wi-Fi nor Feilian is available.
delete_managed_routes
clear_cloned_host_routes
log "Mode=external: corporate bypass routes removed"
}
main "$@"
Set the permissions, check the syntax, and run it manually:
sudo chmod 755 /usr/local/sbin/wireguard-bypass-routes.sh
bash -n /usr/local/sbin/wireguard-bypass-routes.sh
sudo /usr/local/sbin/wireguard-bypass-routes.sh
The final line should report one of these modes:
Mode=office: corporate routes installed through 10.110.32.1 on en0
Mode=feilian: corporate routes installed through utun6
Mode=external: corporate bypass routes removed
Persist routing with a LaunchDaemon
Create /Library/LaunchDaemons/com.ailven.wireguard-bypass-routes.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.ailven.wireguard-bypass-routes</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/wireguard-bypass-routes.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardOutPath</key>
<string>/var/log/wireguard-bypass-routes.log</string>
<key>StandardErrorPath</key>
<string>/var/log/wireguard-bypass-routes.err</string>
</dict>
</plist>
Set the required ownership and permissions:
sudo chown root:wheel \
/Library/LaunchDaemons/com.ailven.wireguard-bypass-routes.plist
sudo chmod 644 \
/Library/LaunchDaemons/com.ailven.wireguard-bypass-routes.plist
Validate and load it:
plutil -lint \
/Library/LaunchDaemons/com.ailven.wireguard-bypass-routes.plist
sudo launchctl bootstrap system \
/Library/LaunchDaemons/com.ailven.wireguard-bypass-routes.plist
To reload it after an edit:
sudo launchctl bootout system \
/Library/LaunchDaemons/com.ailven.wireguard-bypass-routes.plist \
2>/dev/null || true
sudo launchctl bootstrap system \
/Library/LaunchDaemons/com.ailven.wireguard-bypass-routes.plist
Force an immediate run and inspect its status:
sudo launchctl kickstart -k \
system/com.ailven.wireguard-bypass-routes
sudo launchctl print \
system/com.ailven.wireguard-bypass-routes |
grep -E 'state =|runs =|last exit code'
For this short-lived periodic job, state = not running together with last exit code = 0 is normal. Read its logs with:
sudo tail -n 30 \
/var/log/wireguard-bypass-routes.log \
/var/log/wireguard-bypass-routes.err
Understand why the home LAN remains directly reachable
Suppose the home network is:
MacBook: 192.168.123.166/24
Router: 192.168.123.1
Other device: 192.168.123.20
From the DHCP lease and interface address, macOS installs a connected route:
192.168.123.0/24 --> en0
WireGuard installs its full-tunnel route:
0.0.0.0/0 --> utunN
Routing uses longest-prefix matching. 192.168.123.0/24 is more specific than 0.0.0.0/0, so packets for 192.168.123.20 use en0, not the Hetzner tunnel:
MacBook
--> ARP lookup for the destination MAC address
--> home access point / layer-two network
--> 192.168.123.20
This traffic does not cross the home router at layer three, Hetzner, WireGuard, or Feilian. Verify the decision with:
route -n get 192.168.123.20
netstat -rn -f inet | grep '^192\.168\.123'
The result should identify destination 192.168.123.0 and interface en0. Local reachability follows from the connected route, longest-prefix matching, and layer-two communication within the same subnet.
Do not let Feilian claim all of 192.168.0.0/16
Even though a local /24 normally wins over a /16, the script should not add this broad route:
192.168.0.0/16 --> Feilian
There are several reasons:
- Different homes use different
192.168.x.0/24networks. - Hotels and mobile hotspots sometimes advertise unusual masks.
- Virtual machines, containers, and development tools may use
192.168.x.x. - Feilian already installs the more-specific routes it requires.
- The helper script should not claim private address space that does not belong to the company.
- Broad capture risks interfering with LAN discovery, AirPlay, file sharing, and device management.
Feilian mode therefore adds only 10/8, 100.64/10, and 172.16/12. Feilian remains responsible for exact corporate routes within 192.168.x.
Verify Feilian mode
Connect the home Wi-Fi, Hetzner WireGuard, and Feilian. Inspect the tunnel interfaces and anchor route:
ifconfig | grep '^utun'
route -n get 10.137.10.37
The anchor route should name a utunN interface. Then inspect representative destinations:
for ip in \
10.60.68.80 \
10.110.3.129 \
10.115.16.89 \
172.21.150.89 \
172.22.34.62 \
192.168.123.1
do
echo "=== ${ip} ==="
route -n get "${ip}" |
grep -E 'destination:|gateway:|interface:|flags:'
done
The expected choices are:
10.60.68.80 --> Feilian utunN
10.110.3.129 --> Feilian utunN
10.115.16.89 --> Feilian utunN
172.21.150.89 --> Feilian utunN
172.22.34.62 --> Feilian utunN
192.168.123.1 --> en0
Finally, exercise the actual services:
dscacheutil -q host \
-a name nts-proxy.hlidc.nioint.com
nc -vz -w 5 \
nts-proxy.hlidc.nioint.com 8889
ssh workshop_tvm
Operating the gateway
What remains is the part that outlives the build: what performance to expect, where the secrets live, and what to check when something drifts.
Set realistic performance expectations
The measured round-trip time from the client to Finland was approximately 225–250 ms, with occasional excursions to about 300 ms. A representative Google HTTPS request broke down as follows:
DNS: approximately 10 ms
TCP connect: approximately 250 ms
TLS: approximately 490 ms
TTFB: approximately 1.0 s
Total: approximately 1.5 s
WireGuard itself added no significant RTT, MTU 1420 worked correctly, and DNS was not the principal bottleneck. Most latency came from the physical distance and cross-border route between China and Finland. Subscription proxy services can be faster because they may offer an East Asian ingress point, an optimised route, or an intermediate relay. WireGuard tuning cannot remove the lower bound imposed by the physical path.
The value of this design lies elsewhere: dedicated egress, stable public addresses, a consistent Finnish dual-stack identity, complete DNS control, one egress point for several devices, no dependence on shared proxy nodes, and full control of both ends. It is not a low-latency international private circuit.
Remove client secrets from the server
After importing the personal client profiles, delete their private keys from the server:
sudo rm -f \
/etc/wireguard/iphone_personal_private.key \
/etc/wireguard/macbook_personal_private.key \
/etc/wireguard/macmini_personal_private.key
Remove any saved client configuration files as well:
sudo rm -f \
/etc/wireguard/clients/iphone_personal.conf \
/etc/wireguard/clients/macbook_personal.conf \
/etc/wireguard/clients/macmini_personal.conf
Retain only what the server needs:
/etc/wireguard/wg0.conf
/etc/wireguard/server_private.key
/etc/wireguard/server_public.key
/etc/wireguard/*_public.key
Protect the sensitive files and encrypt all backups:
sudo chmod 600 /etc/wireguard/wg0.conf
sudo chmod 600 /etc/wireguard/server_private.key
Perform routine operational checks
The following commands cover the principal failure points:
# WireGuard state and service
sudo wg show
sudo systemctl status wg-quick@wg0 --no-pager
# Recursive DNS
sudo systemctl status unbound --no-pager
# Listeners
sudo ss -lunp | grep 51820
sudo ss -lntup | grep ':53'
# NAT
sudo iptables -t nat -S POSTROUTING
sudo ip6tables -t nat -S POSTROUTING
# Peer handshakes and transfer counters
sudo wg show |
grep -E 'peer:|endpoint:|latest handshake:|transfer:'
# Dynamic routing logs on the corporate MacBook
sudo tail -n 50 \
/var/log/wireguard-bypass-routes.log \
/var/log/wireguard-bypass-routes.err
Resulting network behaviour
Personal devices always behave as follows:
IPv4 Internet
--> Hetzner WireGuard
--> 204.168.142.215
IPv6 Internet
--> Hetzner WireGuard
--> NAT66
--> 2a01:4f9:c014:e6d2::1
DNS
--> 10.8.0.1
--> Unbound
On the corporate MacBook in the office:
Public IPv4/IPv6
--> Hetzner WireGuard
Corporate private IPv4
--> en0
--> corporate physical gateway
nioint.com / nevint.com
--> corporate DNS
On the corporate MacBook at home with Feilian connected:
Public IPv4/IPv6
--> Hetzner WireGuard
10/8, 100.64/10, and 172.16/12
--> Feilian utunN
Corporate 192.168.x resources
--> Feilian's own specific routes
Home LAN
--> en0
On the corporate MacBook at home without Feilian:
Public IPv4/IPv6
--> Hetzner WireGuard
Home LAN
--> en0
Script-managed corporate bypass routes
--> removed
The completed system provides stable Finnish IPv4 and IPv6 egress, private recursive DNS, automatic connections across several Apple devices, direct office routing, Feilian routing at home, direct home-LAN access, dynamic VPN-interface discovery, and automatic management of all three routing states.