wiki:openvpn_installation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
wiki:openvpn_installation [2024/04/09 15:59] – [See also] add ovpn_file_example antisa | wiki:openvpn_installation [2024/07/02 13:49] (current) – [Shorewall] add detect option antisa | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{tag> | + | {{tag> |
====== Openvpn installation ====== | ====== Openvpn installation ====== | ||
Line 68: | Line 68: | ||
cp vars.example vars | cp vars.example vars | ||
- | 1. Create the CA: | + | Also add the '' |
+ | '' | ||
+ | < | ||
+ | etc/ | ||
+ | # X509 extensions for a client | ||
+ | |||
+ | basicConstraints = CA:FALSE | ||
+ | subjectKeyIdentifier = hash | ||
+ | authorityKeyIdentifier = keyid, | ||
+ | extendedKeyUsage = clientAuth | ||
+ | keyUsage = digitalSignature, | ||
+ | </ | ||
+ | |||
+ | 1. Initialize the PKI directories | ||
./easyrsa init-pki | ./easyrsa init-pki | ||
- | 2. Create | + | 2. Create |
- | ./ | + | ./ |
- | 3. Sign CSR and create crt. Here you need to provide the password of the CA.key in step 1: | + | 3. Generate Diffie-Hellman (DH) params. |
+ | ./easyrsa gen-dh | ||
+ | |||
+ | 4. Create the vpn server' | ||
+ | ./easyrsa gen-req server nopass | ||
+ | ./easyrsa sign-req server server | ||
+ | |||
+ | 5. Create client signing request and certificate. Change EntityName, '' | ||
+ | ./easyrsa gen-req EntityName nopass | ||
./easyrsa sign-req client EntityName | ./easyrsa sign-req client EntityName | ||
- | 4. Generate Diffie-Hellman (DH) params | + | |
- | ./easyrsa gen-dh | + | |
| | ||
- | For each new client just repeat | + | For each new client just repeat |
==== Creating configuration files for server and clients ==== | ==== Creating configuration files for server and clients ==== | ||
Line 109: | Line 129: | ||
You can now try running the openvpn on client and server like mentioned in Simple setup above. | You can now try running the openvpn on client and server like mentioned in Simple setup above. | ||
+ | |||
+ | ==== Redirecting traffic over VPN ==== | ||
+ | === Redirect all traffic === | ||
+ | In server.conf add | ||
+ | |||
+ | push " | ||
+ | |||
+ | |||
+ | In client.conf add: | ||
+ | redirect-gateway def1 | ||
+ | |||
+ | === Redirect only some IPs (aka Split tunnel) === | ||
+ | In server.conf add: | ||
+ | |||
+ | push "route 192.168.10.0 255.255.255.0" | ||
+ | push "route 192.168.20.0 255.255.255.0" | ||
+ | ... | ||
+ | |||
+ | Remove the redirect-gateway lines from conf. | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | [[https:// | ||
+ | </ | ||
+ | |||
+ | ===== Redirect DNS through VPN ===== | ||
+ | First uninstall any other DNS server/ | ||
+ | |||
+ | apt install dnsmasq | ||
+ | |||
+ | Now make the /// | ||
+ | |||
+ | nameserver ::1 | ||
+ | nameserver 127.0.0.1 | ||
+ | options trust-ad | ||
+ | |||
+ | You might need to [[https:// | ||
+ | |||
+ | In /// | ||
+ | |||
+ | listen-address=:: | ||
+ | interface=tun0 | ||
+ | # Google' | ||
+ | server=8.8.8.8 | ||
+ | server=8.8.4.4 | ||
+ | |||
+ | Adapt the listen-address IP to your VPN interface IP and interface as well and uncomment '' | ||
+ | |||
+ | In /// | ||
+ | |||
+ | ... | ||
+ | push " | ||
+ | push " | ||
+ | ... | ||
+ | | ||
+ | <WRAP center round info 60%> | ||
+ | If you run into problems with DNS not going through VPN in Windows installed as a VM in Virtualbox for example, you will need to disable automatic metric on VPN interface and set it to lower then the default Ethernet or wifi. To check open the powershell and type '' | ||
+ | {{ : | ||
+ | </ | ||
+ | |||
+ | ==== Resolve specific domains names to hard-coded IP ==== | ||
+ | Say you need to always resolve example.org to 1.2.3.4 address, you have two options. | ||
+ | |||
+ | 1. Add the resolution to /// | ||
+ | |||
+ | ... | ||
+ | 1.2.3.4 www.example.org example.org | ||
+ | |||
+ | 2. Remove the above from /// | ||
+ | address=/ | ||
+ | |||
+ | Also [[https:// | ||
===== Firewall setup ===== | ===== Firewall setup ===== | ||
Line 120: | Line 211: | ||
#ZONE | #ZONE | ||
net | net | ||
- | vpn tun0 | + | vpn |
</ | </ | ||
Line 166: | Line 257: | ||
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE | iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE | ||
- | | + | |
+ | ===== Running openvpn server as a service ===== | ||
+ | |||
+ | Debian 12 ships with systemd units for this. The way to run it is to first make sure the server configuration file is located in /// | ||
+ | |||
+ | systemctl enable --now openvpn-server@myvpnserver | ||
+ | |||
+ | Check logs with | ||
+ | journalctl -xefu openvpn-server@server.service | ||
====== Tested on ====== | ====== Tested on ====== | ||
* Debian 12 Bookworw | * Debian 12 Bookworw | ||
Line 173: | Line 273: | ||
====== See also ====== | ====== See also ====== | ||
* [[wiki: | * [[wiki: | ||
+ | * [[wiki: | ||
====== References ====== | ====== References ====== | ||
* https:// | * https:// | ||
Line 178: | Line 279: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * [[https:// | ||
wiki/openvpn_installation.1712671173.txt.gz · Last modified: 2024/04/09 15:59 by antisa