
Infrastructure: WireGuard — VPN for remote employees and between offices
🌐 Machine-translated from Russian. Show original
In this part:
Why VPN#
Opening 1C, RDP, databases, and file balls to the internet is the most common way small companies can hack . A VPN gives remote employees and branches access to internal resources without exposing them to the outside.
WireGuard is a modern VPN: fast, easy to set up, built into the Linux kernel, with clients available for Windows, macOS, Android, and iOS.
Server#
sudo apt install wireguard
wg genkey | sudo tee /etc/wireguard/server.key | wg pubkey | sudo tee /etc/wireguard/server.pub
sudo chmod 600 /etc/wireguard/server.key
/etc/wireguard/wg0.conf:
[Interface]
Address = 10.10.0.1/24
ListenPort = 51820
PrivateKey = <содержимое server.key>
# Сотрудник: ноутбук Айгерим
[Peer]
PublicKey = <публичный ключ клиента>
AllowedIPs = 10.10.0.2/32
sudo systemctl enable --now wg-quick@wg0
sudo ufw allow 51820/udp
To get clients into the office network, enable routing: net.ipv4.ip_forward = 1 in /etc/sysctl.conf (sudo sysctl -p) and NAT rules or routes on the office router.
Client#
On the employee's device — the WireGuard application, keys are generated within it or also via wg genkey. Configuration:
[Interface]
Address = 10.10.0.2/32
PrivateKey = <приватный ключ клиента>
DNS = 192.168.1.1
[Peer]
PublicKey = <содержимое server.pub>
Endpoint = vpn.example.kz:51820
AllowedIPs = 10.10.0.0/24, 192.168.1.0/24
PersistentKeepalive = 25
AllowedIPsclient — which networks to run through VPN. Only office networks — the internet goes directly.0.0.0.0/0— all traffic goes through the office.PersistentKeepalivehelps clients with NAT (mobile internet, home routers).
For phones, it is convenient to provide configuration with QR codes: qrencode -t ansiutf8 < client.conf.
Office — office#
To connect two offices, routers (or servers) in each office are peers of each other, and in AllowedIPs — networks on opposite sides: 192.168.2.0/24 on one side and 192.168.1.0/24 on the other. Office networks should not overlap — choose different bands in advance.
Key Management#
- One employee — one key (or better yet, one key per device). Then disable the dismissed employee — delete one block
[Peer]. - Keep a list: whose key, which device, which IP.
- Never send private keys via messenger in plain text.
Verification#
sudo wg show
The connected client shows latest handshake — the time of the last exchange. No handshake — check if UDP 51820 is open and if keys match. Don't forget to add a VPN to monitoring.
Comments · 0
No comments yet.Sign in to comment, rate and see all comments.