Добавить новость на сайт
RSS
Читать нас в RSS
Статистика сайта
Наши правила
Поиск по сайту
Добро пожаловать на Информационный портал Vectormm.net! У нас вы можете найти инструкции по настройке популярных беспроводных роутеров, а так же тонкости и хитрости по работе с операционными системами Windows и Linux. Так же, вы можете общаться на нашем форуме.

Вы успешно авторизовались!
Навигация
 
Сегодня
Панель управления
 

Установка OpenVPN на Ubuntu/Debian
Раздел: Linux

Если требуется организовать защищенный канал связи между несколькими удаленными узлами - кроссплатформенный OpenVPN подходит как нельзя лучше.

Будем устанавливать OpenVPN на сервер с 1 сетевым интерфейсом, без локальной сети.

Есть еще вариант с бриджеванием физического и виртуального интерфейсов, но мы сетевые настройки трогать не будем (кому надо - инструкцию найдете).

 

Приступим.

 

1. Устанавливаем OpenVPN

 

 

sudo apt-get install openvpn
Server Certificates
Now that the openvpn package is installed, the certificates for the VPN server need to be created.
First, copy the easy-rsa directory to /etc/openvpn. This will ensure that any changes to the scripts will not be lost when the package is updated. You will also need to adjust permissions in the easy-rsa directory to allow the current user permission to create files. From a terminal enter:
sudo mkdir /etc/openvpn/easy-rsa/
sudo cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
sudo chown -R $USER /etc/openvpn/easy-rsa/
Next, edit /etc/openvpn/easy-rsa/vars adjusting the following to your environment:
export KEY_COUNTRY="US"
export KEY_PROVINCE="NC"
export KEY_CITY="Winston-Salem"
export KEY_ORG="Example Company"
export KEY_EMAIL="steve@example.com"
Enter the following to create the server certificates:
cd /etc/openvpn/easy-rsa/
source vars
./clean-all
./build-dh
./pkitool --initca
./pkitool --server server
cd keys
openvpn --genkey --secret ta.key
sudo cp server.crt server.key ca.crt dh1024.pem ta.key /etc/openvpn/
Client Certificates
The VPN client will also need a certificate to authenticate itself to the server. To create the certificate, enter the following in a terminal:
cd /etc/openvpn/easy-rsa/
source vars
./pkitool hostname
Replace hostname with the actual hostname of the machine connecting to the VPN.
Copy the following files to the client:
/etc/openvpn/ca.crt
/etc/openvpn/easy-rsa/keys/hostname.crt
/etc/openvpn/easy-rsa/keys/hostname.key
/etc/openvpn/ta.key
Configuration
Server Configuration
Now configure the openvpn server by creating /etc/openvpn/server.conf from the example file. In a terminal enter:
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
sudo gzip -d /etc/openvpn/server.conf.gz
Edit /etc/openvpn/server.conf changing the following options to:
local 172.18.100.101
dev tap0
up "/etc/openvpn/up.sh br0"
down "/etc/openvpn/down.sh br0"
;server 10.8.0.0 255.255.255.0
server-bridge 172.18.100.101 255.255.255.0 172.18.100.105 172.18.100.200
push "route 172.18.100.1 255.255.255.0"
push "dhcp-option DNS 172.18.100.20"
push "dhcp-option DOMAIN example.com"
tls-auth ta.key 0 # This file is secret
user nobody
group nogroup
local: is the IP address of the bridge interface.
server-bridge: needed when the configuration uses bridging. The 172.18.100.101 255.255.255.0 portion is the bridge interface and mask. The IP range 172.18.100.105 172.18.100.200 is the range of IP addresses that will be assigned to clients.
push: are directives to add networking options for clients.
user and group: configure which user and group the openvpn daemon executes as.
Replace all IP addresses and domain names above with those of your network.
After configuring the server, restart openvpn by entering:
sudo /etc/init.d/openvpn restart
Now edit /etc/openvpn/client.conf changing the following options:
dev tap
remote vpn.example.com 1194
cert hostname.crt
key hostname.key
tls-auth ta.key 1
Replace vpn.example.com with the hostname of your VPN server, and hostname.* with the actual certificate and key filenames.
sudo apt-get install openvpn
2. Генерируем сертификаты
Серверные
sudo mkdir /etc/openvpn/easy-rsa/
sudo cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
sudo chown -R $USER /etc/openvpn/easy-rsa/
Редактируем /etc/openvpn/easy-rsa/vars, указывая свои данные:
 
export KEY_COUNTRY="RU"
export KEY_PROVINCE="MO"
export KEY_CITY="Moscow"
export KEY_ORG="Super Company"
export KEY_EMAIL="security@supercom.ru"
 
Генерируем сертификаты
cd /etc/openvpn/easy-rsa/
source vars
./clean-all
./build-dh
./pkitool --initca
./pkitool --server server
cd keys
openvpn --genkey --secret ta.key
sudo cp server.crt server.key ca.crt dh1024.pem ta.key /etc/openvpn/
 
Клиентские

cd /etc/openvpn/easy-rsa/
source vars
./pkitool hostname

Вместо hostname указываем идентификатор клиента (имя компьютера, логин пользователя, и т.п.).

В папку OpenVPN/config/ на клиенте копируем следующие файлики:
/etc/openvpn/ca.crt
/etc/openvpn/easy-rsa/keys/hostname.crt
/etc/openvpn/easy-rsa/keys/hostname.key
/etc/openvpn/ta.key

Редактируем конфигурацию сервера:
 
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
sudo gzip -d /etc/openvpn/server.conf.gz
 
Редактируем /etc/openvpn/server.conf, изменяя нужные строчки:
local 372.516.254.137 #если привязываемся к определенному интерфейсу (указанный тут IP не может быть использован, специально написан нереальный)
dev tun # для использования в bridge режиме - dev tap
server 172.16.0.0 255.255.255.0 #здесь указываем внутренний адрес, не используемый в локальных сетях клиентов, чтобы не было перечечения
#server-bridge 172.16.0.1 255.255.255.0 172.16.0.5 172.16.0.20 #указываем адрес сервера, и диапазон выдаваемых адресов для bridge режима
push "route 172.16.0.1 255.255.255.0"
push "dhcp-option DNS 172.16.0.1"
push "dhcp-option DOMAIN supercom.ru"
tls-auth ta.key 0
user nobody
group nogroup

Перезапускаем сервис:
sudo /etc/init.d/openvpn restart
 
Редактируем клиентский конфигурационный файл (client.conf или client.ovpn в зависимости от версии клиента):
#dev tap #интерфейс должен совпадать с интерфейсом сервера
dev tun
remote vpn.supercom.ru 1194
cert hostname.crt
key hostname.key
tls-auth ta.key 1
Не забываем прописать свои названия сервера и сертификатов. 
 
 (голосов: 2)
 
 
НаверхНаверх
 
Наверх