An office VPN with WireGuard: secure remote work
An employee is at home and needs files from the office. The simplest solution, an open remote desktop port, is an invitation to every scanner on the internet. A VPN is safer: one encrypted tunnel to the office and nothing else exposed to the outside.
The short answer: on the office firewall (the device between the office network and the internet) you switch on a VPN, and every laptop or phone gets its own key. One port is exposed to the internet, and it answers only devices with a known key. To the rest of the world, everything else looks like a closed network.
Why a VPN, and not an open remote desktop
An open remote desktop port can be seen from outside. Automated scanners check ports like this all the time and try passwords one after another. One weak password or one hole in the system is enough for a stranger to end up on a computer in the office, and from there in the whole network.
A VPN turns this around. The VPN port doesn’t answer anyone who lacks the right key, so a scanner doesn’t even get a reply. Only after connecting does the employee see the office as if they were sitting at their own desk: file shares, the printer, the company’s programs. You decide exactly what they have access to.
What the employee sees
For the employee it looks simple. On the laptop or phone they have the WireGuard app, a VPN program, with one saved profile. They flip the switch, wait a second and open the same addresses and folders as in the office. They don’t type a second password and don’t switch between programs.
When they finish work, they flip the switch off or leave the connection on. WireGuard runs in the background and uses little battery. If a laptop gets lost, you delete one entry on the firewall and that key stops working. The rest of the team notices nothing.
What to prepare
Before you start, gather a few things:
- a pfSense firewall in the office (pfSense is popular free firewall software), with admin access,
- the office’s public IP address, or a dynamic DNS name if the provider changes the address,
- an address plan: a subnet only for the VPN, different from every network in the office,
- a list of what each employee should have access to.
In the examples below I use the office network 192.168.1.0/24 and the VPN subnet 10.0.0.0/24. Replace them with your own. The VPN subnet must not overlap with any other network, including the one created by containers on your servers. Containers can take address ranges that look free, and then routing stops working in strange ways.
Step by step: the tunnel on pfSense
- In
VPN > WireGuard > Tunnelsadd a tunnel. Mark it as enabled, choose the listen port (51820by default), generate the keys and give the tunnel the address10.0.0.1/24. Copy the public key, because it goes to every client. The private key stays on the firewall. - In
Interfaces > Assignmentsadd a new interfacetun_wg0, enable it and set a static address. That way you can write rules for it like for any other network. - In
Firewall > Rules > WANadd a rule: protocol UDP, destination the WAN address, port the same as in the tunnel. If pfSense sits behind the provider’s router, add a forward of the same UDP port to the firewall’s WAN address there. - In
VPN > WireGuard > Peersadd an entry for each device: a description (for examplelaptop-anna), the device’s public key,Keep Aliveset to25andAllowed IPsset only to that device’s address in the tunnel, for example10.0.0.2/32. - In
Services > DNS Resolver, in theNetwork Interfacesfield, add the WireGuard interface. Without it, names won’t resolve throughDNS = 10.0.0.1from the client profile. If you don’t want the client to ask the firewall for names, leave theDNSline out of the profile.
The device’s keys are generated by the device itself. The private key never goes to the firewall or into an email.
I also give each client its own pre-shared key (Pre-shared Key in the device entry, the same value in the client profile as PresharedKey). It’s an extra layer of encryption, and with a few devices it costs a minute of work for each.
Step by step: setting up the client
The client profile looks like this (the values are examples):
[Interface]
PrivateKey = <device private key>
Address = 10.0.0.2/32
DNS = 10.0.0.1
[Peer]
PublicKey = <tunnel public key from pfSense>
Endpoint = vpn.company.example:51820
AllowedIPs = 10.0.0.0/24, 192.168.1.0/24
PersistentKeepalive = 25
Two places are confusing. Allowed IPs on the pfSense side says who the device is, so it should be narrow. AllowedIPs in the client says what to send through the tunnel, so it should list the tunnel and every office network the employee needs to reach. If you add a range covering the whole internet there, all of the employee’s traffic will go through the office. Usually you don’t want that.
When you change the list of addresses in an existing profile, turn the tunnel off and on again. Otherwise the client keeps using the old list.
Firewall rules: test first, then strict rules
At the start, add one temporary rule on the WireGuard interface that lets everything through. With it you can check that the tunnel and the routes work before you start hunting for permission errors. When everything works, delete it and replace it with rules that name their destinations, from top to bottom, because the first match wins:
Pass TCP source 10.0.0.0/24 dest 192.168.1.10 port 445 (files)
Pass TCP source 10.0.0.0/24 dest 192.168.1.11 port 443 (business program)
Pass TCP/UDP source 10.0.0.0/24 dest 10.0.0.1 port 53 (names)
Pass ICMP source 10.0.0.0/24 dest 192.168.1.0/24, 10.0.0.1 (ping for diagnosis)
The rule for port 53 is needed because by default pfSense blocks everything on this interface that you don’t let through, including name queries to the firewall itself.
If different employees have different access, use the device’s address (/32) in the rules instead of the whole subnet. Limit access to specific ports, not to the whole network. Also think about whether the pfSense panel should be reachable over the VPN, and decide that on purpose, not by accident through a broad rule.
What can go wrong
Test in layers: first the handshake (VPN > WireGuard > Status should show a recent time), then a ping to 10.0.0.1, then a ping to a computer in the office, and finally a server name and a real program. If one step fails, you know which layer to look at.
- There is no handshake. Usually the rule on the WAN is missing, the port forward at the provider is missing, or the wrong address was entered in the client. It’s also possible that the provider hides your address behind CGNAT. Then port forwarding won’t work without a fixed IP address from the provider.
- There is a handshake, but nothing answers. Check that the WireGuard interface is enabled and that the rules aren’t blocking it.
- The tunnel answers, but you can’t see the office computers. The office network is missing from
AllowedIPsin the client, or the target network doesn’t accept traffic from the VPN subnet. - IP addresses work, names don’t. The DNS resolver on pfSense must also listen on the WireGuard interface. This is the most common cause when the connection is up but nothing loads.
- A test from your home network gets nowhere. Connecting from home Wi-Fi to your own public address is often blocked by the router. Test from an outside network, for example mobile data on a phone.
When to do it yourself and when to ask for help
If you have one pfSense firewall, a few employees and some practice with networks, you’ll manage the steps above. The most important things are to test in layers and not to leave a rule that lets everything through.
It’s worth asking for help when the network is split into many segments, when the provider changes your address or hides it behind CGNAT, when employees should have different access, or when you aren’t sure what else is exposed to the internet. Then it’s easy to miss the one rule that weakens the whole setup.
If the provider gives you a changing address, set up dynamic DNS on pfSense (Services > Dynamic DNS) and put the name in the client profiles instead of the address. I use it with Cloudflare myself. Even when the address hasn’t changed for months, the name costs little, and it saves you fixing the profile on every laptop on the day the provider does change it.
If you want someone to do this for you, or to check what already works, see the network, internet and Wi-Fi page. You can also start with a free audit: I’ll check one part of your IT, for example what in your office can be seen from the internet, and you’ll get a short written report.