====== Пакет OpenVPN ======
* [[http://openvpn.net/index.php/open-source/documentation/howto.html|OpenVPN HOWTO]]
===== Установка сервиса =====
==== Debian/Ubuntu ====
# apt install openvpn
==== CentOS 7 ====
[[http://serveradmin.ru/nastroyka-openvpn-na-centos-7/|Установка openvpn на CentOS 7]]
===== Настройка client/server конфигурации =====
==== Настройка с использованием клиентских сертификатов ====
* [[Пакет OpenSSL#Создание параметра DH]]
* [[Пакет OpenSSL#Создание центра сертификации]]
* [[Пакет OpenSSL#Создание сертификата сервиса, подписанного CA]]
=== Настройка сервера ===
# cp ca.* /etc/ssl/certs/
# cp gate.crt /etc/ssl/certs/
# cp gate.key /etc/ssl/private/
gate# cat /etc/openvpn/openvpn1.conf
dev tun
# port 1194
# proto udp
keepalive 10 120
server 192.168.200+X.0 255.255.255.0
push "route 192.168.100+X.0 255.255.255.0"
#push "route 192.168.X.0 255.255.255.0"
#push "dhcp-option DNS 192.168.X.10"
#push "block-outside-dns"
#push "dhcp-option DOMAIN corpX.un"
dh /etc/openvpn/dh2048.pem
ca /etc/ssl/certs/ca.crt
crl-verify /etc/ssl/certs/ca.crl
cert /etc/ssl/certs/gate.crt
key /etc/ssl/private/gate.key
status /var/log/openvpn1-status.log
=== Тестирование конфигурации ===
# openvpn --config /etc/openvpn/openvpn1.conf
# timeout 5 openvpn --port 65500 --config /etc/openvpn/openvpn1.conf; test $? -eq 124 && echo OK
=== Включение и запуск ===
# systemctl enable openvpn@openvpn1
# systemctl start openvpn@openvpn1
==== Настройка клиента ====
=== Windows ===
* [[https://mail.bmstu.ru/~postmaster/openvpn-install-2.4.0-I601.exe]]
* [[https://openvpn.net/community-downloads/|OpenVPN community downloads]]
* Начиная с Windows 7 необходимо запускать OpenVPN с правами администратора
* [[Пакет OpenSSL#Создание пользовательского сертификата, подписанного CA]]
Start OpenVPN GUI
C:\>notepad C:\Users\student\OpenVPN\config\user1.ovpn
dev tun
# port 1194
# proto udp
client
remote 172.16.1.X
ca ca.crt
cert user1.crt
key user1.key
=== Linux ===
debian:~# apt install openvpn resolvconf wget
debian:~# openvpn --script-security 2 --up /etc/openvpn/update-resolv-conf --down /etc/openvpn/update-resolv-conf --config user1.ovpn
==== Индивидуальная настройка параметров клиентов ====
* [[https://serverfault.com/questions/1048592/openvpn-routing-from-server-to-client|OpenVPN routing from server to client]]
* базируется на атрибуте CN
gate# cat /etc/openvpn/openvpn1.conf
...
client-config-dir ccd
#route 192.168.100+Y.0 255.255.255.0
...
gate# cat /etc/openvpn/ccd/userN
ifconfig-push 192.168.200+X.4*N+2 192.168.200+X.4*N+1
#iroute 192.168.100+Y.0 255.255.255.0
==== Использование PAM аутентификации ====
* [[https://www.linuxsysadmintutorials.com/setup-pam-authentication-with-openvpns-auth-pam-module|Setup PAM authentication with OpenVPN's auth-pam module]]
* [[https://github.com/OpenVPN/openvpn/tree/master/src/plugins/auth-pam|openvpn/src/plugins/auth-pam/]]
* [[https://openvpn.net/community-resources/using-alternative-authentication-methods/|OpenVPN Using alternative authentication methods]]
* [[Пакет OpenSSL#Создание самоподписанного сертификата]]
gate# less /etc/pam.d/login
gate# cat /etc/openvpn/openvpn1.conf
...
#### crl-verify ...
ca /etc/ssl/certs/server.crt
cert /etc/ssl/certs/server.crt
...
plugin /usr/lib/x86_64-linux-gnu/openvpn/plugins/openvpn-plugin-auth-pam.so login
verify-client-cert none
username-as-common-name
#duplicate-cn #несколько подключений под одной учетной записью
cmd run as admin C:\>notepad C:\Program Files\OpenVPN\config\client.ovpn
...
auth-user-pass
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
==== Использование RADIUS аутентификации и учета ====
* [[http://itinrussian.ru/freeradius-openvpn-%D0%BD%D0%B0-debian-8/|Freeradius + openvpn]]
===== Настройка peer2peer конфигурации =====
* В новых версиях (с Debian12) теперь так: [[https://wiki.gentoo.org/wiki/OpenVPN/fingerprint-authentication|OpenVPN/fingerprint-authentication]]
==== Debian/Ubuntu/FreeBSD ====
gate.corpX.un# cd /etc/openvpn/
gate.corpX.un# openvpn --genkey --secret static.key
gate.corpX.un# scp static.key gate.corpY.un:/etc/openvpn/
gate.corpX.un# cat connect_to_Y.conf
dev tun
remote 172.16.1.Y
port 1195
# proto udp
keepalive 10 120
ifconfig 192.168.X+Y.X 192.168.X+Y.Y
route 192.168.100+Y.0 255.255.255.0
secret /etc/openvpn/static.key
==== FreeBSD ====
# cd /usr/local/etc/rc.d/
# ln -s openvpn connect_to_Y
# cat /etc/rc.conf
...
connect_to_Y_enable=yes
===== Мониторинг сервиса =====
gate# cat /var/log/openvpn1-status.log
gate# tail -f /var/log/syslog
gate# cat /etc/openvpn/openvpn1.conf
...
management localhost 7505
# management 0.0.0.0 7505
...
gate# telnet localhost 7505
status
kill user1