GNU/Linux >> Belajar Linux >  >> Panels >> OpenVPN

OpenVPN - Amankan administrasi server Anda dengan koneksi VPN multiplatform

OpenVPN adalah VPN SSL berfitur lengkap yang mengimplementasikan ekstensi jaringan aman lapisan 2 atau 3 OSI dengan menggunakan protokol SSL/TLS standar industri. Ini mendukung metode otentikasi klien yang fleksibel berdasarkan sertifikat, kartu pintar, dan/atau kredensial nama pengguna/kata sandi, dan memungkinkan kebijakan kontrol akses khusus pengguna atau grup menggunakan aturan firewall yang diterapkan pada antarmuka virtual VPN. OpenVPN bukan proxy aplikasi web dan tidak beroperasi melalui browser web.

Persiapan server

Untuk tutorial ini, kita akan menggunakan server Debian atau Ubuntu. Anda dapat menggunakan server apa pun yang sudah Anda miliki dalam produksi.

Instalasi OpenVPN

Semua distro server Linux dan UNIX yang dikenal memiliki OpenVPN di repositorinya. Instalasi semudah menjalankan:

apt-get install openvpn

Konfigurasi firewall

Port mendengarkan default untuk OpenVPN adalah 1194. Aman untuk menggunakan port default. OpenVPN menggunakan protokol UDP secara default. Ada alasan sederhana untuk ini:

OpenVPN menggunakan Layer 2 dan 3

  • Layer 2 adalah lapisan Data Link yang menyediakan transfer frame data tanpa kesalahan melalui lapisan fisik, yang berarti lapisan ini menggunakan perangkat jaringan TUN/TAP miliknya sendiri.
  • Lapisan 3 adalah lapisan Jaringan yang menyediakan perutean.

dan ini berarti Layer 4 (Lapisan transport memastikan pengiriman paket) dikelola oleh OS dan aplikasi itu sendiri. Sederhananya, setiap kontrol lalu lintas dan kontrol pengiriman paket dibuat oleh OS, oleh karena itu tidak perlu melakukannya dua kali oleh OpenVPN itu sendiri. Tentu saja, ada opsi untuk menggunakan TCP untuk OpenVPN yang berarti Anda mendapatkan lebih banyak sumber daya yang terbuang, tetapi untuk beberapa lingkungan khusus, ini mungkin berguna.

Singkatnya, membuka port 1194 untuk UDP sudah cukup untuk memungkinkan koneksi VPN. Tidak diperlukan pemfilteran karena OpenVPN memiliki verifikasi dan kontrolnya sendiri yang diterapkan (lihat di bagian selanjutnya). Tambahkan pernyataan berikut ke dalam konfigurasi firewall Anda.

-A INPUT -p udp -m udp --dport 1194 -j ACCEPT

Konfigurasi server

Setelah instalasi OpenVPN berhasil, Anda dapat menemukan semua file konfigurasi OpenVPN di folder /etc/openvpn. Mari buka file server.conf di editor kita dan edit.

nano /etc/openvpn/server.conf

Periksa dan edit bagian berikut:

# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key).

ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/server.crt
key /etc/openvpn/easy-rsa/keys/server.key # This file should be kept secret

# Diffie hellman parameters.
dh /etc/openvpn/easy-rsa/keys/dh2048.pem

# Configure server mode and supply a VPN subnet
server 10.9.8.0 255.255.255.0

# Push routes to the client
push "route 10.9.8.0 255.255.255.0"

# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
tls-auth /etc/openvpn/easy-rsa/keys/ta.key 0 # This file is secret

# Select a cryptographic cipher.
cipher AES-128-CBC # AES

# Enable compression on the VPN link.
comp-lzo

# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
user vpn
group vpn

Karena kami memilih subnet 10.9.8.0/24 sebagai subnet internal, klien Anda akan mendapatkan alamat IP dari subnet ini setelah tersambung. Sebagai default, 10.9.8.1 dicadangkan untuk server itu sendiri.

Membuat sertifikat

Pertama, kita harus mengedit vars mengajukan. Isi parameter KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, dan KEY_EMAIL. Nilai ini akan digunakan setiap kali Anda membuat sertifikat baru.

Untuk memuat file vars, jalankan:

./vars

Setelah memuatnya, kita dapat membuat otoritas sertifikat:

./clean-all
./build-ca

Ketika CA telah dibuat, lanjutkan dengan membuat sertifikat server:

./build-key-server server

Dan satu lagi sertifikat untuk klien:

./build-key client

Bagaimanapun, kita harus membuat params DH:

./build-dh

Keamanan lebih

Untuk memastikan kami telah mengamankan server OpenVPN kami, kami akan menggunakan tls-auth. Ini memastikan kami tidak akan mengirim sertifikat kami ke server yang disusupi.

openvpn –genkey –secret ta.key

File ta.key ini harus disertakan sekarang dalam bundel sertifikat setiap klien.

Konfigurasi klien

 ##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
##############################################

# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun

# Windows needs the TAP-Windows adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or
# UDP server? Use the same setting as
# on the server.
;proto tcp
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote <your-server-ip> 1194
;remote my-server-2 1194

# Choose a random host from the remote
# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random

# Keep trying indefinitely to resolve the
# host name of the OpenVPN server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite

# Most clients don't need to bind to
# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nobody

# Try to preserve some state across restarts.
persist-key
persist-tun

# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt
cert client.crt
key client.key

# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server". This is an
# important precaution to protect against
# a potential attack discussed here:
# http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server". The build-key-server
# script in the easy-rsa folder will do this.
;ns-cert-type server

# If a tls-auth key is used on the server
# then every client must also have the key.
tls-auth ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
cipher AES-128-CBC

# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo

# Set log file verbosity.
verb 3

# Silence repeating messages
mute 20 

Simpan sebagai file client.ovpn dan sertakan ta.key, ca.crt, client.crt, client.key ke satu folder.

Setelah menginstal klien openvpn ke komputer Anda dan menjalankan file konfigurasi client.ovpn, Anda seharusnya dapat terhubung ke server VPN Anda. Setelah itu Anda mendapatkan alamat IP dari rentang 10.9.8.0/24 yang Anda tetapkan dan bekerja sama dengan server Anda secara pribadi.


OpenVPN
  1. Cara Mengatur Server OpenVPN di Debian 9

  2. Instal server Wireguard VPN dengan Docker

  3. Siapkan Server VPN IPSec dengan Libreswan di CentOS 8

  1. Siapkan Server VPN Linux menggunakan OpenVPN – Panduan Langkah-demi-Langkah

  2. Cara Mengamankan Server Email Dari Hacking dengan VPN (Debian/Ubuntu)

  3. Cara Mengamankan Server Email Dari Peretasan dengan VPN (CentOS/RHEL)

  1. Menyiapkan server OpenVPN dengan CentOS dan Viscosity

  2. Menyiapkan server OpenVPN dengan DD-WRT dan Viskositas

  3. Menyiapkan server OpenVPN dengan Netgear dan Viscosity