How I improved my network security with an admin VPN
I moved the admin access of my OpenWrt router, access point and Wi-Fi bridge, and the access to my homelab servers, behind a few WireGuard peers.
At home I have three OpenWrt devices. The router is a NanoPi R3S. Behind it there is a Wi-Fi access point, and a TP-Link which works as a Wi-Fi bridge for a few wired machines. My homelab servers are in a separate zone on the router.
Until this week, the admin pages and SSH of all three devices were open to every device in the home Wi-Fi. The server zone too: any phone or TV at home could open any port on my servers.
Why I did not simply allow my own addresses
The first idea was to allow admin only from the addresses of my own devices. But in the home network an address proves nothing. Any device can set any address, and a DHCP reservation does not stop it.
In WireGuard every device has its own key, and the router accepts an address only from the device with the right key.
So my plan was simple: give a small part of the VPN range to admin devices, and allow admin only from this part.
I did not compare WireGuard much with other VPNs. It was already on my router for the phone, and it is small and simple to set up on OpenWrt. It also does not answer anything to a packet without a valid key, so from outside the open UDP port looks closed. A phone gets its config simply from a QR code.
Which devices got admin access
I took a /28 part of the range, which is 16 addresses. My phone got 10.10.10.h, the tablet 10.10.10.i and my PC 10.10.10.j. Every device has its own key, and on the router there are only the public keys.
The old phone peer, which had an address outside of this part, I removed at the end.
What I changed on the router and the access points
On the router there are three new rules from the VPN zone, all with the source 10.10.10.g/28: to the router itself on TCP 22, 80 and 443, to the access point and the TP-Link on the same ports, and to the server zone with no port limit. The first one looks like this:
uci set firewall.admin_router=rule
uci set firewall.admin_router.src=vpn
uci set firewall.admin_router.src_ip=10.10.10.g/28
uci set firewall.admin_router.proto=tcp
uci set firewall.admin_router.dest_port='22 80 443'
uci set firewall.admin_router.target=ACCEPT
uci commit firewallAt home the phone connects to the public address of the router from inside the home network, so this traffic comes to the router from the LAN zone. Without a rule for UDP 51820 from the LAN, the VPN worked only outside of my home.
The access point and the TP-Link have their own firewalls. The router does not masquerade between its zones, so a request from the VPN comes to them with its real VPN address. There I only added the same source limit to the existing admin rules.
In which order I did it
I did it in two steps. First I only added things: the new peers and the new rules. The old access from the home network still worked, and I tested all three devices at home and over mobile data. Only after that I removed the old rules: admin from the home network on all three devices, and the forwarding from the home network to the server zone.
Every removal ran together with a small rollback. If I lost the access, after ten minutes the old config would come back by itself.
How I checked the result
At the end I checked from a non-admin device that the router, the access point and the TP-Link do not answer anymore:
for h in 192.168.0.x 192.168.0.y 192.168.0.z; do
timeout 4 bash -c "echo > /dev/tcp/$h/22" && echo "$h open" || echo "$h closed"
doneAll three were closed, and the same with port 443.
Why I did not keep a fallback
I did not keep any fallback, not even the local address of the TP-Link on its wired ports. If I lose all three admin devices, the only way to get the access again is the failsafe mode of OpenWrt, with a cable and the reset button.
Now before any admin work I turn on the VPN, also at home. On the phone it is always on anyway, so for me almost nothing changed.