Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 233Network · VPN

How to set up an OpenVPN server for remote users

Remote employees need the internal wiki, file server and admin tools, but these must not be on the internet. An OpenVPN server gives each user an encrypted tunnel into the network with their own certificate, so one lost laptop is revoked without touching everyone else. This how-to builds a small CA with easy-rsa, configures the server, creates a client profile, and revokes a user.

  • 5 Lessen
  • 9 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

233.1

The quick answer

dnf install -y openvpn easy-rsa
cp -r /usr/share/easy-rsa/3 /etc/openvpn/easy-rsa && cd /etc/openvpn/easy-rsa
./easyrsa init-pki && ./easyrsa build-ca nopass
./easyrsa build-server-full vpn.example.com nopass
./easyrsa build-client-full alice nopass
./easyrsa gen-crl
openvpn --genkey secret /etc/openvpn/server/tc.key
/etc/openvpn/server/server.conf
port 1194
proto udp
dev tun
ca /etc/openvpn/easy-rsa/pki/ca.crt
cert /etc/openvpn/easy-rsa/pki/issued/vpn.example.com.crt
key /etc/openvpn/easy-rsa/pki/private/vpn.example.com.key
dh none
tls-crypt /etc/openvpn/server/tc.key
crl-verify /etc/openvpn/easy-rsa/pki/crl.pem
server 10.8.0.0 255.255.255.0
push "route 10.10.0.0 255.255.0.0"
push "dhcp-option DNS 10.10.0.2"
keepalive 10 60
user nobody
group nobody
persist-key
persist-tun
verb 3
systemctl enable --now openvpn-server@server

233.2

Step by step

  1. CA and certificates (quick answer) — keep the CA key (pki/private/ca.key) safe; better on a separate machine. nopass here only for the server key (it must start without a person); give the CA a passphrase in production.
  2. Server config — UDP 1194, a tunnel network 10.8.0.0/24, and only the office routes pushed (split tunnel). tls-crypt hides the server from scanners (no answer without the key). dh none uses modern ECDH.
  3. Routing — enable forwarding (net.ipv4.ip_forward = 1 in /etc/sysctl.d/) and either add a route for 10.8.0.0/24 on the office router, or NAT the VPN clients (firewall-cmd --add-masquerade --permanent). Open 1194/udp.
  4. Client profile — one .ovpn file per user with the certificates inline:
alice.ovpn
client
dev tun
proto udp
remote vpn.example.com 1194
nobind
persist-key
persist-tun
remote-cert-tls server
verb 3
<ca>
(contents of ca.crt)
</ca>
<cert>
(contents of issued/alice.crt)
</cert>
<key>
(contents of private/alice.key)
</key>
<tls-crypt>
(contents of tc.key)
</tls-crypt>

Send it over a secure channel, never by plain email.

  1. Revoke a user — lost laptop or person left:
cd /etc/openvpn/easy-rsa && ./easyrsa revoke alice && ./easyrsa gen-crl
systemctl restart openvpn-server@server
  1. Better login — add MFA (a PAM or RADIUS plugin) or use the CRL plus short certificate lifetimes. For many users consider WireGuard or a commercial access tool.

233.3

Check that it worked

journalctl -u openvpn-server@server shows Initialization Sequence Completed; alice connects with the profile and gets 10.8.0.x; ping 10.10.0.2 and the wiki work through the tunnel; after the revoke her connection is refused (certificate revoked in the log).

233.4

Common problems

ProblemCauseFix
Client connects, but no internal hosts reachableNo forwarding, NAT or return route.ip_forward=1; masquerade or a route on the router.
TLS handshake failedPort blocked, or tls-crypt key differs.Open 1194/udp; same tc.key in the profile.
Revoked user can still connectCRL not regenerated or not reloaded.gen-crl; restart; check crl-verify path and rights.
CRL has expired — nobody can connectThe CRL has an expiry date.Run gen-crl regularly (timer), restart.
DNS names do not resolveDNS option not applied on the client.Linux clients need update-systemd-resolved or the NetworkManager plugin.
Server fails after user nobodyFiles not readable after dropping rights.persist-key/persist-tun; check rights of the CRL.

233.5

Go further

1Why give every user their own certificate?

One lost or leaked certificate can be revoked on its own without changing the access of everyone else.

2What does tls-crypt add?

It encrypts and authenticates the TLS handshake with a shared key, so the server does not answer anyone without the key.

Alle commando's in dit hoofdstuk