Selamat datang di artikel kami tentang cara menginstal OpenVPN server di Ubuntu 20.04 di HuaweiCloud! OpenVPN adalah salah satu teknologi VPN open source yang paling populer di dunia. Dengan menginstal OpenVPN server, Anda dapat mengamankan koneksi internet Anda dan mengakses konten yang dibatasi di seluruh dunia.
Di dalam artikel ini, kami akan memberikan panduan langkah demi langkah tentang cara menginstal OpenVPN server di Ubuntu 20.04 di HuaweiCloud. Kami akan menjelaskan semua hal yang perlu Anda ketahui, mulai dari pengaturan server hingga konfigurasi klien.
Kami juga akan memperkenalkan beberapa fitur keamanan dan keuntungan yang dimiliki oleh OpenVPN, sehingga Anda dapat memahami mengapa teknologi ini menjadi begitu populer. Jadi, jika Anda siap untuk memulai, mari kita lanjutkan dan mulai menginstal OpenVPN server di Ubuntu 20.04 di HuaweiCloud.
Keuntungan OpenVPN Server
- Keamanan: OpenVPN server menyediakan koneksi internet yang aman dan terenkripsi. Hal ini membuat data dan informasi yang dikirim melalui koneksi tersebut menjadi lebih aman dan tidak mudah disadap oleh pihak yang tidak berwenang.
- Kemudahan penggunaan: OpenVPN server mudah digunakan dan dikonfigurasi, sehingga dapat diakses oleh pengguna yang tidak memiliki keahlian teknis yang tinggi.
- Kecepatan: OpenVPN server dapat meningkatkan kecepatan koneksi internet karena menggunakan teknologi kompresi dan caching data.
- Kebebasan: OpenVPN server dapat digunakan untuk membuka akses internet yang dibatasi oleh ISP atau pemerintah. Dengan menghubungkan ke OpenVPN server yang terletak di luar wilayah yang dibatasi, pengguna dapat mengakses konten yang sebelumnya tidak bisa diakses.
- Ketersediaan: OpenVPN server tersedia dalam berbagai platform dan sistem operasi, sehingga dapat diakses dari berbagai perangkat dan lokasi.
Persyaratan Install OpenVPN server
- Server dengan OS Ubuntu 20.04 untuk install CA
- Server dengan OS ubuntu 20.04 untuk install OpenVPN server
- User non root untuk masuk ke server dengan sudo privilaged
Membuat user baru non root dengan privileged sudo
Masuk ke server / VM dengan root, kemudian masukan perintah berikut
adduser vpn
usermod -aG sudo vpn
Perintah diatas akan membuat user baru bernama “vpn” dengan privileged sudo, disini saya buat user vpn untuk VM yang akan di install openvpn server sedangkan VM yang akan di install CA saya akan buat user bernama ca.
Saya asumsikan kalian juga sudah mengikuti telah membuat user bernama vpn pada server yang akan diinstall openvpn server dan user bernama ca pada vm yang akan diinstall CA.
Install CA (Easy RSA)
masuk ke VM yang akan diinstall CA
sudo apt update sudo apt install easy-rsa
mkdir ~/easy-rsa ln -s /usr/share/easy-rsa/* ~/easy-rsa/ chmod 700 /home/sammy/easy-rsa
Perintah diatas akan membuat folder baru bernama easy-rsa kemudian perintah dibawah ini akan mengarahkan kita masuk ke folder easy-rsa dan menjalankan init-pki
cd ~/easy-rsa ./easyrsa init-pki
JIka benar seharusnya respon output yang keluar seperti berikut
Outputinit-pki complete; you may now create a CA or requests. Your newly created PKI dir is: /home/ca/easy-rsa/pki
Selanjutnya jalankan perintah berikut untuk membuat variable
cd ~/easy-rsa nano vars
Isi variable berikut pada file vars yang sudah terbuka
set_var EASYRSA_REQ_COUNTRY "ID" set_var EASYRSA_REQ_PROVINCE "Jakarta" set_var EASYRSA_REQ_CITY "Jakarta Utara" set_var EASYRSA_REQ_ORG "ApaAja" set_var EASYRSA_REQ_EMAIL "admin@bebas.com" set_var EASYRSA_REQ_OU "Community" set_var EASYRSA_ALGO "ec" set_var EASYRSA_DIGEST "sha512"
Selanjutnya jalankan perintah ini untuk membuat ca, tapi ga usah kasih password biar enak, tapi kalo mau kasih password silakan hapus perintah nopass
./easyrsa build-ca nopass
untuk melihat hasil dari ca nya bisa gunakan perintah berikut
cat ~/easy-rsa/pki/ca.crt
Jika berhasil seharusnya akan tampak seperti berikut.
—–BEGIN CERTIFICATE—–
MIIDSzCCAjOgAwIBAgIUcR9Crsv3FBEujrPZnZnU4nSb5TMwDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAwwLRWFzeS1SU0EgQ0EwHhcNMjAwMzE4MDMxNjI2WhcNMzAw
. . .
. . .
—–END CERTIFICATE—–
nano /tmp/ca.crt
Setelah menjalankan code diatas, pastekan certificate tadi.
Selanjutnya kita masuk ke VM yang akan diinstall OpenVPN server.
Install OpenVPN Server
Sebelumnya jangan lupa untuk masuk dengan user vpn jangan pakai root
sudo apt update sudo apt install openvpn easy-rsa
mkdir ~/easy-rsa ln -s /usr/share/easy-rsa/* ~/easy-rsa/
sudo chown vpn ~/easy-rsa chmod 700 ~/easy-rsa
Tahap diatas merupakan instalasi dan pembuatan folder easy-rsa, tidak perlu saya jelaskan ya tinggal jalankan aja dan kalian harusnya ngerti sendiri. selanjutnya kita akan melakukan konfigurasi.
cd ~/easy-rsa nano vars
Isi file vars dengan variable berikut
set_var EASYRSA_ALGO "ec" set_var EASYRSA_DIGEST "sha512"
kemudian save dengan ctrl+x dan jalankan perintah berikut.
./easyrsa init-pki
Selanjutnya kita masuk lagi ke folder easy-rsa
cd ~/easy-rsa
Namanya server aja jangan diubah yang lain biar konfigurasinya sama ke bawahnya. dan saya ga mau pakai password biar lebih mudah.
./easyrsa gen-req server nopass
Selanjutnya copy server.key nya ke folder etc/openvpn/server
sudo cp /home/vpn/easy-rsa/pki/private/server.key /etc/openvpn/server/
Selanjutnya file server.req kita copy ke vm tempat CA diisntall jadi disini perlu remote ke vm lain, gunakan ip public server ca, karena saya sebelumnya coba pakai ip private nya dan hasilnya gagal. tapi mungkin kalian bisa.
ca_server_ip ubah ke ip public vm yang diinstall CA
scp /home/vpn/easy-rsa/pki/reqs/server.req ca@ca_server_ip:/tmp
Selanjutnya masuk lagi ke VM CA
cd ~/easy-rsa ./easyrsa import-req /tmp/server.req server
jika berhasil maka akan tampil output berikut
The request has been successfully imported with a short name of: server
You may now use this name to perform signing operations on this request.
./easyrsa sign-req server server
Jika diminta untuk mengkonfirmasi silakan ketik yes kemudian enter
You are about to sign the following certificate.
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.
Request subject, to be signed as a server certificate for 3650 days:
subject=
commonName = server
Type the word ‘yes’ to continue, or any other input to abort.
Confirm request details: yes
. . .
Certificate created at: /home/ca/easy-rsa/pki/issued/server.crt
Selanjutnya copy file server.crt dan ca.crt dari VM CA ke VM VPN
scp pki/issued/server.crt vpn@vpn_server_ip:/tmp scp pki/ca.crt vpn@vpn_server_ip:/tmp
Selanjutnya masuk lagi ke VM yang diinstall OpenVPN
copy file yang tadi dikirim dari VM CA ke folder /etc/openvpn/server
sudo cp /tmp/{server.crt,ca.crt} /etc/openvpn/server
Lanjutkan untuk perintah-perintah berikut
cd ~/easy-rsa openvpn --genkey --secret ta.key
sudo cp ta.key /etc/openvpn/server
Membuat sertifikat untuk Client dan Key nya
Ikuti aja langsung perintah-perintah CLI berikut
mkdir -p ~/client-configs/keys
chmod -R 700 ~/client-configs
cd ~/easy-rsa ./easyrsa gen-req client1 nopass
cp pki/private/client1.key ~/client-configs/keys/
dan yang terakhir kita kasih file client1.req nya ke VM CA
scp pki/reqs/client1.req ca@ca_server_ip:/tmp
Masuk ke VM CA lagi buat setting certificat client
ikuti perintah-perintah berikut tanpa perlu tanya-tanya.
cd ~/easy-rsa ./easyrsa import-req /tmp/client1.req client1
./easyrsa sign-req client client1
Kalo berhasil akan tampak output seperti berikut
Type the word ‘yes’ to continue, or any other input to abort.
Confirm request details:
Ketik aja ‘yes’ tanpa tanda petik ya, selanjutnya copy file client1.crt ke VM vpn
scp pki/issued/client1.crt vpn@vpn_server_ip:/tmp
Masuk ke VM yang diinstall openvpn lagi
cp /tmp/client1.crt ~/client-configs/keys/
cp ~/easy-rsa/ta.key ~/client-configs/keys/ sudo cp /etc/openvpn/server/ca.crt ~/client-configs/keys/ sudo chown vpn.vpn ~/client-configs/keys/*
Konfigurasi OpenVPN
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/server/ sudo gunzip /etc/openvpn/server/server.conf.gz
sudo nano /etc/openvpn/server/server.conf
Biar cepet ubah semua isinya dengan code dibawah ini.
################################################# # Sample OpenVPN 2.0 config file for # # multi-client server. # # # # This file is for the server side # # of a many-clients <-> one-server # # OpenVPN configuration. # # # # OpenVPN also supports # # single-machine <-> single-machine # # configurations (See the Examples page # # on the web site for more info). # # # # This config should work on Windows # # or Linux/BSD systems. Remember on # # Windows to quote pathnames and use # # double backslashes, e.g.: # # "C:\\Program Files\\OpenVPN\\config\\foo.key" # # # # Comments are preceded with '#' or ';' # ################################################# # Which local IP address should OpenVPN # listen on? (optional) ;local a.b.c.d # Which TCP/UDP port should OpenVPN listen on? # If you want to run multiple OpenVPN instances # on the same machine, use a different port # number for each one. You will need to # open up this port on your firewall. port 1194 # TCP or UDP server? ;proto tcp proto udp # "dev tun" will create a routed IP tunnel, # "dev tap" will create an ethernet tunnel. # Use "dev tap0" if you are ethernet bridging # and have precreated a tap0 virtual interface # and bridged it with your ethernet interface. # If you want to control access policies # over the VPN, you must create firewall # rules for the the TUN/TAP interface. # On non-Windows systems, you can give # an explicit unit number, such as tun0. # On Windows, use "dev-node" for this. # 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-Win32 adapter name # from the Network Connections panel if you # have more than one. On XP SP2 or higher, # you may need to selectively disable the # Windows firewall for the TAP adapter. # Non-Windows systems usually don't need this. ;dev-node MyTap # SSL/TLS root certificate (ca), certificate # (cert), and private key (key). Each client # and the server must have their own cert and # key file. The server and all clients will # use the same ca file. # # See the "easy-rsa" directory for a series # of scripts for generating RSA certificates # and private keys. Remember to use # a unique Common Name for the server # and each of the client certificates. # # Any X509 key management system can be used. # OpenVPN can also use a PKCS #12 formatted key file # (see "pkcs12" directive in man page). ca ca.crt cert server.crt key server.key # This file should be kept secret # Diffie hellman parameters. # Generate your own with: # openssl dhparam -out dh2048.pem 2048 ;dh dh2048.pem dh none # Network topology # Should be subnet (addressing via IP) # unless Windows clients v2.0.9 and lower have to # be supported (then net30, i.e. a /30 per client) # Defaults to net30 (not recommended) ;topology subnet # Configure server mode and supply a VPN subnet # for OpenVPN to draw client addresses from. # The server will take 10.8.0.1 for itself, # the rest will be made available to clients. # Each client will be able to reach the server # on 10.8.0.1. Comment this line out if you are # ethernet bridging. See the man page for more info. server 10.8.0.0 255.255.255.0 # Maintain a record of client <-> virtual IP address # associations in this file. If OpenVPN goes down or # is restarted, reconnecting clients can be assigned # the same virtual IP address from the pool that was # previously assigned. ifconfig-pool-persist /var/log/openvpn/ipp.txt # Configure server mode for ethernet bridging. # You must first use your OS's bridging capability # to bridge the TAP interface with the ethernet # NIC interface. Then you must manually set the # IP/netmask on the bridge interface, here we # assume 10.8.0.4/255.255.255.0. Finally we # must set aside an IP range in this subnet # (start=10.8.0.50 end=10.8.0.100) to allocate # to connecting clients. Leave this line commented # out unless you are ethernet bridging. ;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100 # Configure server mode for ethernet bridging # using a DHCP-proxy, where clients talk # to the OpenVPN server-side DHCP server # to receive their IP address allocation # and DNS server addresses. You must first use # your OS's bridging capability to bridge the TAP # interface with the ethernet NIC interface. # Note: this mode only works on clients (such as # Windows), where the client-side TAP adapter is # bound to a DHCP client. ;server-bridge # Push routes to the client to allow it # to reach other private subnets behind # the server. Remember that these # private subnets will also need # to know to route the OpenVPN client # address pool (10.8.0.0/255.255.255.0) # back to the OpenVPN server. ;push "route 192.168.10.0 255.255.255.0" ;push "route 192.168.20.0 255.255.255.0" # To assign specific IP addresses to specific # clients or if a connecting client has a private # subnet behind it that should also have VPN access, # use the subdirectory "ccd" for client-specific # configuration files (see man page for more info). # EXAMPLE: Suppose the client # having the certificate common name "Thelonious" # also has a small subnet behind his connecting # machine, such as 192.168.40.128/255.255.255.248. # First, uncomment out these lines: ;client-config-dir ccd ;route 192.168.40.128 255.255.255.248 # Then create a file ccd/Thelonious with this line: # iroute 192.168.40.128 255.255.255.248 # This will allow Thelonious' private subnet to # access the VPN. This example will only work # if you are routing, not bridging, i.e. you are # using "dev tun" and "server" directives. # EXAMPLE: Suppose you want to give # Thelonious a fixed VPN IP address of 10.9.0.1. # First uncomment out these lines: ;client-config-dir ccd ;route 10.9.0.0 255.255.255.252 # Then add this line to ccd/Thelonious: # ifconfig-push 10.9.0.1 10.9.0.2 # Suppose that you want to enable different # firewall access policies for different groups # of clients. There are two methods: # (1) Run multiple OpenVPN daemons, one for each # group, and firewall the TUN/TAP interface # for each group/daemon appropriately. # (2) (Advanced) Create a script to dynamically # modify the firewall in response to access # from different clients. See man # page for more info on learn-address script. ;learn-address ./script # If enabled, this directive will configure # all clients to redirect their default # network gateway through the VPN, causing # all IP traffic such as web browsing and # and DNS lookups to go through the VPN # (The OpenVPN server machine may need to NAT # or bridge the TUN/TAP interface to the internet # in order for this to work properly). push "redirect-gateway def1 bypass-dhcp" # Certain Windows-specific network settings # can be pushed to clients, such as DNS # or WINS server addresses. CAVEAT: # http://openvpn.net/faq.html#dhcpcaveats # The addresses below refer to the public # DNS servers provided by opendns.com. push "dhcp-option DNS 208.67.222.222" push "dhcp-option DNS 208.67.220.220" # Uncomment this directive to allow different # clients to be able to "see" each other. # By default, clients will only see the server. # To force clients to only see the server, you # will also need to appropriately firewall the # server's TUN/TAP interface. ;client-to-client # Uncomment this directive if multiple clients # might connect with the same certificate/key # files or common names. This is recommended # only for testing purposes. For production use, # each client should have its own certificate/key # pair. # # IF YOU HAVE NOT GENERATED INDIVIDUAL # CERTIFICATE/KEY PAIRS FOR EACH CLIENT, # EACH HAVING ITS OWN UNIQUE "COMMON NAME", # UNCOMMENT THIS LINE OUT. ;duplicate-cn # The keepalive directive causes ping-like # messages to be sent back and forth over # the link so that each side knows when # the other side has gone down. # Ping every 10 seconds, assume that remote # peer is down if no ping received during # a 120 second time period. keepalive 10 120 # For extra security beyond that provided # by SSL/TLS, create an "HMAC firewall" # to help block DoS attacks and UDP port flooding. # # Generate with: # openvpn --genkey --secret ta.key # # The server and each client must have # a copy of this key. # The second parameter should be '0' # on the server and '1' on the clients. ;tls-auth ta.key 0 # This file is secret tls-crypt ta.key # Select a cryptographic cipher. # This config item must be copied to # the client config file as well. # Note that v2.4 client/server will automatically # negotiate AES-256-GCM in TLS mode. # See also the ncp-cipher option in the manpage ;cipher AES-256-CBC cipher AES-256-GCM auth SHA256 # Enable compression on the VPN link and push the # option to the client (v2.4+ only, for earlier # versions see below) ;compress lz4-v2 ;push "compress lz4-v2" # For compression compatible with older clients use comp-lzo # If you enable it here, you must also # enable it in the client config file. ;comp-lzo # The maximum number of concurrently connected # clients we want to allow. ;max-clients 100 # It's a good idea to reduce the OpenVPN # daemon's privileges after initialization. # # You can uncomment this out on # non-Windows systems. user nobody group nogroup # The persist options will try to avoid # accessing certain resources on restart # that may no longer be accessible because # of the privilege downgrade. persist-key persist-tun # Output a short status file showing # current connections, truncated # and rewritten every minute. status /var/log/openvpn/openvpn-status.log # By default, log messages will go to the syslog (or # on Windows, if running as a service, they will go to # the "\Program Files\OpenVPN\log" directory). # Use log or log-append to override this default. # "log" will truncate the log file on OpenVPN startup, # while "log-append" will append to it. Use one # or the other (but not both). ;log /var/log/openvpn/openvpn.log ;log-append /var/log/openvpn/openvpn.log # Set the appropriate level of log # file verbosity. # # 0 is silent, except for fatal errors # 4 is reasonable for general usage # 5 and 6 can help to debug connection problems # 9 is extremely verbose verb 3 # Silence repeating messages. At most 20 # sequential messages of the same message # category will be output to the log. ;mute 20 # Notify the client that when the server restarts so it # can automatically reconnect. explicit-exit-notify 1
Lanjutkan lagi, berikut perintah selanjutnya
sudo nano /etc/sysctl.conf
tambahkan file itu dengan code berikut
net.ipv4.ip_forward = 1
Kemudian jalankan dengan perintah
sudo sysctl -p
Konfigurasi firewall
ip route list default
di sini keluarnya seperti ini
default via 10.1.2.1 dev eth0 proto dhcp metric 100
Sekarang ubah berfore rule di ufw
sudo nano /etc/ufw/before.rules
biar gampang ubah semua isinya dengan ini.
# # rules.before # # Rules that should be run before the ufw command line added rules. Custom # rules should be added to one of these chains: # ufw-before-input # ufw-before-output # ufw-before-forward # # START OPENVPN RULES # NAT table rules *nat :POSTROUTING ACCEPT [0:0] # Allow traffic from OpenVPN client to eth0 (change to the interface you discovered!) -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE COMMIT # END OPENVPN RULES # Don't delete these required lines, otherwise there will be errors *filter :ufw-before-input - [0:0] :ufw-before-output - [0:0] :ufw-before-forward - [0:0] :ufw-not-local - [0:0] # End required lines # allow all on loopback -A ufw-before-input -i lo -j ACCEPT -A ufw-before-output -o lo -j ACCEPT # quickly process packets for which we already have a connection -A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw-before-output -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A ufw-before-forward -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # drop INVALID packets (logs these in loglevel medium and higher) -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny -A ufw-before-input -m conntrack --ctstate INVALID -j DROP # ok icmp codes for INPUT -A ufw-before-input -p icmp --icmp-type destination-unreachable -j ACCEPT -A ufw-before-input -p icmp --icmp-type time-exceeded -j ACCEPT -A ufw-before-input -p icmp --icmp-type parameter-problem -j ACCEPT -A ufw-before-input -p icmp --icmp-type echo-request -j ACCEPT # ok icmp code for FORWARD -A ufw-before-forward -p icmp --icmp-type destination-unreachable -j ACCEPT -A ufw-before-forward -p icmp --icmp-type time-exceeded -j ACCEPT -A ufw-before-forward -p icmp --icmp-type parameter-problem -j ACCEPT -A ufw-before-forward -p icmp --icmp-type echo-request -j ACCEPT # allow dhcp client to work -A ufw-before-input -p udp --sport 67 --dport 68 -j ACCEPT # # ufw-not-local # -A ufw-before-input -j ufw-not-local # if LOCAL, RETURN -A ufw-not-local -m addrtype --dst-type LOCAL -j RETURN # if MULTICAST, RETURN -A ufw-not-local -m addrtype --dst-type MULTICAST -j RETURN # if BROADCAST, RETURN -A ufw-not-local -m addrtype --dst-type BROADCAST -j RETURN # all other non-local packets are dropped -A ufw-not-local -m limit --limit 3/min --limit-burst 10 -j ufw-logging-deny -A ufw-not-local -j DROP # allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above # is uncommented) -A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT # allow MULTICAST UPnP for service discovery (be sure the MULTICAST line above # is uncommented) -A ufw-before-input -p udp -d 239.255.255.250 --dport 1900 -j ACCEPT # don't delete the 'COMMIT' line or these rules won't be processed COMMIT
Selanjutnya file ufw nya yang ada perubahan
sudo nano /etc/default/ufw
Ubah
DEFAULT_FORWARD_POLICY="DROP"
menjadi
DEFAULT_FORWARD_POLICY="ACCEPT"
Berikan izin untuk port 1194/udp dan openssh
sudo ufw allow 1194/udp sudo ufw allow OpenSSH
Jalankan firewall nya.
sudo ufw disable sudo ufw enable
Jalankan OpenVPN service Ubuntu 20.04
sudo systemctl -f enable openvpn-server@server.service sudo systemctl start openvpn-server@server.service sudo systemctl status openvpn-server@server.service
Jika berhasil kurang lebih outputnya seperti berikut
● openvpn-server@server.service – OpenVPN service for server
Loaded: loaded (/lib/systemd/system/openvpn-server@.service; enabled; vend>
Active: active (running) since Wed 2023-05-10 13:02:31 CST; 3h 14min ago
Docs: man:openvpn(8)
https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
https://community.openvpn.net/openvpn/wiki/HOWTO
Main PID: 66778 (openvpn)
Status: “Initialization Sequence Completed”
Tasks: 1 (limit: 1066)
Memory: 1.3M
CGroup: /system.slice/system-openvpn\x2dserver.slice/openvpn-server@server>
└─66778 /usr/sbin/openvpn –status /run/openvpn-server/status-serv>May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 peer i>
May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 peer i>
May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 peer i>
May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 peer i>
May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 peer i>
May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 Outgoi>
May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 Incomi>
May 10 16:06:01 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 Contro>
May 10 16:11:15 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 [clien>
May 10 16:11:15 ecs-openvps-2 openvpn[66778]: client1/36.77.225.69:46244 SIGUSR>
lines 1-23
Sekarang kita buat konfigurasi untuk client sehingga terbuat satu file config buat client terhubung ke server OpenVPN
mkdir -p ~/client-configs/files
cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/client-configs/base.conf
nano ~/client-configs/base.conf
Langsung aja ubah semua isinya dengan code berikut, tapi inget bagian ini remote IP_Server_OpenVPN 1194 ubah dengan IP server vpn kalian sendiri.
############################################## # 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-Win32 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 IP_Server_OpenVPN 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 nogroup # 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 correct key usage set. # 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 keyUsage set to # digitalSignature, keyEncipherment # and the extendedKeyUsage to # serverAuth # EasyRSA can do this for you. remote-cert-tls 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. # Note that v2.4 client/server will automatically # negotiate AES-256-GCM in TLS mode. # See also the ncp-cipher option in the manpage ;cipher AES-256-CBC cipher AES-256-GCM auth SHA256 # 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 key-direction 1 ; script-security 2 ; up /etc/openvpn/update-resolv-conf ; down /etc/openvpn/update-resolv-conf ; script-security 2 ; up /etc/openvpn/update-systemd-resolved ; down /etc/openvpn/update-systemd-resolved ; down-pre ; dhcp-option DOMAIN-ROUTE .
Oke lanjut lagi, sekarang buat file make_config.sh
nano ~/client-configs/make_config.sh
di dalam nya silakan isi code berikut
#!/bin/bash # First argument: Client identifier KEY_DIR=~/client-configs/keys OUTPUT_DIR=~/client-configs/files BASE_CONFIG=~/client-configs/base.conf cat ${BASE_CONFIG} \ <(echo -e '<ca>') \ ${KEY_DIR}/ca.crt \ <(echo -e '</ca>\n<cert>') \ ${KEY_DIR}/${1}.crt \ <(echo -e '</cert>\n<key>') \ ${KEY_DIR}/${1}.key \ <(echo -e '</key>\n<tls-crypt>') \ ${KEY_DIR}/ta.key \ <(echo -e '</tls-crypt>') \ > ${OUTPUT_DIR}/${1}.ovpn
chmod 700 ~/client-configs/make_config.sh
cd ~/client-configs ./make_config.sh client1
ls ~/client-configs/files
Jika berhasil maka akan tampil
client1.ovpn
Hubungkan Komputer Lokal Ke OpenVPN server
File itu yang akan diperlukan untuk menghubungkan ke vpn server, jadi dari komputer atau laptop local kita jika mau terhubung ke vpn server, harus pakai file client1.ovpn
Copy File client1.ovpn dengan perintah berikut
scp -r vpn@110.239.68.166:client-configs/files/client1.ovpn ~/
Selanjutnya koneksikan ke vpn server dengan perintah berikut
sudo openvpn --config client1.ovpn
jika berhasil akan tampak seperti ini