Difference between revisions of "OpenVPN: Instalasi di Ubuntu 18.04"

From OnnoWiki
Jump to navigation Jump to search
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
Berikut adalah catatan Instalasi OpenVPN Server di Ubuntu 18.04. Catatan ini hanya akan mencatat hal yang terpenting saja, berbagai detail parameter yang harus diisi bisa di lihat di [[OpenVPN: Instalasi di Ubuntu 16.04]]
+
Sumber: https://www.cyberciti.biz/faq/ubuntu-18-04-lts-set-up-openvpn-server-in-5-minutes/
  
  
==Step 1: Install OpenVPN==
+
==Step 1 – Update system==
  
Instalasi aplikasi yang dibutuhkan
+
Run,
 +
 
 +
sudo apt update
 +
sudo apt upgrade
 +
 
 +
==Step 2 – Cek IP address==
 +
 
 +
Pakai perintah,
 +
 
 +
ip a
 +
ip a show eth0
 +
ip a show enp0s3
 +
 
 +
==Step 3 – Download & run openvpn-install.sh script==
 +
 
 +
Pastikan tidak ada yang menggunakan repository ubuntu,
 +
 
 +
sudo rm -Rf /var/lib/dpkg/lock
 +
 
 +
Sebagai '''User Biasa''', Download,
 +
 
 +
sudo chmod 777 /usr/local/src
 +
cd /usr/local/src/
 +
wget https://git.io/vpn -O openvpn-install.sh
 +
chmod +x openvpn-install.sh
 +
 
 +
Run,
 +
 
 +
sudo ./openvpn-install.sh
 +
 
 +
Akan keluar beberapa pertanyaan, tekan [ENTER].
 +
Selesai instalasi, contoh sertifikat ~/client.ovpn akan di keluarkan.
 +
 
 +
Hack sedikit
  
 
  sudo su
 
  sudo su
  apt update
+
  cp -Rf /etc/openvpn/server/* /etc/openvpn/
  apt -y install openvpn easy-rsa
+
 
 +
Run OpenVPN,
 +
 
 +
sudo systemctl stop openvpn@server    # <--- stop server
 +
sudo systemctl start openvpn@server  # <--- start server
 +
sudo systemctl restart openvpn@server # <--- restart server
 +
sudo systemctl status openvpn@server  # <--- get server status
 +
 
 +
==Step 4 – Connect an OpenVPN server using IOS/Android/Linux/Windows client==
 +
 
 +
Copykan file sertifikat client.ovpn ke client, misalnya menggunakan perintah,
 +
 
 +
scp vivek@104.20.187.5:~/client.ovpn .
 +
 
 +
===Linux Desktop: OpenVPN client configuration===
 +
 
 +
Install,
 +
 
 +
  sudo apt -y install openvpn
 +
sudo cp client.ovpn /etc/openvpn/client.ovpn
 +
 
 +
Coba sambungan dari sisi client
 +
 
 +
sudo openvpn --client --config /etc/openvpn/client.ovpn
 +
 
 +
Linux akan secara automatis tersambung ke computer dengan openvpn script
 +
 
 +
sudo systemctl start openvpn@client # <--- start client service
 +
 
 +
==Step 5 - Verify/test the connectivity==
 +
 
 +
Execute the following commands after connecting to OpenVPN server from your Linux desktop:
 +
 
 +
ping 10.8.0.1      # Ping to the OpenVPN server gateway
 +
ip route            # Make sure routing setup working
 +
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com #Must return public IP address of OpenVPN server
 +
 
 +
Beberapa catatan troubleshooting OpenVPN & Client
  
paket easy-rsa dibutuhkan untuk membantu kita dalam men-setup internal CA (certificate authority)
+
Cek OpenVPN server for errors:
  
 +
journalctl --identifier ovpn-server
  
==Step 2: Set Up CA Directory==
+
Cek Filewall Rules
  
Sebagai user biasa, copy template directory easy-rsa ke home directory,
+
cat /etc/rc.local
  
  make-cadir ~/openvpn-ca
+
  #!/bin/sh -e
 +
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to 172.26.6.74
 +
exit 0
  
Pindah ke directory CA,
+
Alternatif lain, run iptables command & sysctl command untuk verifikasi NAT rule setup
  
  cd ~/openvpn-ca
+
  sudo iptables -t nat -L -n -v
 +
sysctl net.ipv4.ip_forward
  
 +
Insert rules ke /etc/rc.local (kalau belum di insert)
 +
 +
sudo sh /etc/rc.local
 +
sudo sysctl -w net.ipv4.ip_forward=1
  
==Step 3: Konfigurasi variabel CA==
+
Is OpenVPN server running and port is open? Use the ss command or netstat command and pidof command/ps command:
  
Edit parameter CA,
+
$ netstat -tulpn | grep :1194 ## 1194 is the openvpn server port ##
 +
$ ss -tulpn | grep :1194 ## 1194 is the openvpn server port ##
 +
$ ps aux | grep openvpn ## is the openvpn server running? ##
 +
$ ps -C openvpn ## is the openvpn server running? ##
 +
$ pidof openvpn ## find the openvpn server PID ##
  
  cd ~/openvpn-ca
+
Verify that OpenVPN server runnign and Port is Open on ubuntu Linux
nano vars
+
If not running, restart the OpenVPN server:
 +
  $ sudo systemctl restart openvpn@server
  
 +
Look out for errors:
 +
$ sudo systemctl status openvpn@server
  
==Step 4: Build Certificate Authority==
+
Can the Linux desktop client connect to the OpenVPN server machine? First you need to run a simple test to see if the OpenVPN server port (UDP 1194) accepts connections:
 +
$ nc -vu 104.20.187.5 1194
 +
Connection to 104.20.187.5 1194 port [udp/openvpn] succeeded!
  
Cek vars
+
If not connected it means either a Linux desktop firewall or your router is blocking access to server. Make sure both client and server using same protocol and port, e.g. UDP port 1194.
  
cd ~/openvpn-ca
+
==Conclusion==
source ./vars
 
  
Jalankan
+
Congratulations. You successfully set up an OpenVPN server on Ubuntu Linux 18.04 LTS server running in the cloud. See the OpenVPN website here and Ubuntu page here for additional information.
  
cd ~/openvpn-ca
+
==Youtube==
./clean-all
 
  
Clear all,
+
* [https://youtu.be/qb07-Lpd71M YOUTUBE: Membuat Sambungan Server - OpenVPN - Cloud - Mikrotik - Kali]
  
cd ~/openvpn-ca
 
./clean-all
 
  
Build CA,
+
==Referensi==
  
cd ~/openvpn-ca
+
* https://www.cyberciti.biz/faq/ubuntu-18-04-lts-set-up-openvpn-server-in-5-minutes/
./build-ca
 
  
 
==Pranala Menarik==
 
==Pranala Menarik==

Latest revision as of 08:02, 31 March 2020

Sumber: https://www.cyberciti.biz/faq/ubuntu-18-04-lts-set-up-openvpn-server-in-5-minutes/


Step 1 – Update system

Run,

sudo apt update
sudo apt upgrade

Step 2 – Cek IP address

Pakai perintah,

ip a
ip a show eth0
ip a show enp0s3

Step 3 – Download & run openvpn-install.sh script

Pastikan tidak ada yang menggunakan repository ubuntu,

sudo rm -Rf /var/lib/dpkg/lock

Sebagai User Biasa, Download,

sudo chmod 777 /usr/local/src
cd /usr/local/src/
wget https://git.io/vpn -O openvpn-install.sh
chmod +x openvpn-install.sh

Run,

sudo ./openvpn-install.sh

Akan keluar beberapa pertanyaan, tekan [ENTER]. Selesai instalasi, contoh sertifikat ~/client.ovpn akan di keluarkan.

Hack sedikit

sudo su
cp -Rf /etc/openvpn/server/* /etc/openvpn/

Run OpenVPN,

sudo systemctl stop openvpn@server    # <--- stop server
sudo systemctl start openvpn@server   # <--- start server
sudo systemctl restart openvpn@server # <--- restart server
sudo systemctl status openvpn@server  # <--- get server status

Step 4 – Connect an OpenVPN server using IOS/Android/Linux/Windows client

Copykan file sertifikat client.ovpn ke client, misalnya menggunakan perintah,

scp vivek@104.20.187.5:~/client.ovpn .

Linux Desktop: OpenVPN client configuration

Install,

sudo apt -y install openvpn
sudo cp client.ovpn /etc/openvpn/client.ovpn

Coba sambungan dari sisi client

sudo openvpn --client --config /etc/openvpn/client.ovpn

Linux akan secara automatis tersambung ke computer dengan openvpn script

sudo systemctl start openvpn@client # <--- start client service

Step 5 - Verify/test the connectivity

Execute the following commands after connecting to OpenVPN server from your Linux desktop:

ping 10.8.0.1       # Ping to the OpenVPN server gateway
ip route            # Make sure routing setup working
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com #Must return public IP address of OpenVPN server

Beberapa catatan troubleshooting OpenVPN & Client

Cek OpenVPN server for errors:

journalctl --identifier ovpn-server

Cek Filewall Rules

cat /etc/rc.local
#!/bin/sh -e
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to 172.26.6.74
exit 0

Alternatif lain, run iptables command & sysctl command untuk verifikasi NAT rule setup

sudo iptables -t nat -L -n -v
sysctl net.ipv4.ip_forward

Insert rules ke /etc/rc.local (kalau belum di insert)

sudo sh /etc/rc.local
sudo sysctl -w net.ipv4.ip_forward=1

Is OpenVPN server running and port is open? Use the ss command or netstat command and pidof command/ps command:

$ netstat -tulpn | grep :1194 ## 1194 is the openvpn server port ##
$ ss -tulpn | grep :1194 ## 1194 is the openvpn server port ##
$ ps aux | grep openvpn ## is the openvpn server running? ##
$ ps -C openvpn ## is the openvpn server running? ##
$ pidof openvpn ## find the openvpn server PID ##

Verify that OpenVPN server runnign and Port is Open on ubuntu Linux If not running, restart the OpenVPN server:

$ sudo systemctl restart openvpn@server

Look out for errors:

$ sudo systemctl status openvpn@server

Can the Linux desktop client connect to the OpenVPN server machine? First you need to run a simple test to see if the OpenVPN server port (UDP 1194) accepts connections:

$ nc -vu 104.20.187.5 1194

Connection to 104.20.187.5 1194 port [udp/openvpn] succeeded!

If not connected it means either a Linux desktop firewall or your router is blocking access to server. Make sure both client and server using same protocol and port, e.g. UDP port 1194.

Conclusion

Congratulations. You successfully set up an OpenVPN server on Ubuntu Linux 18.04 LTS server running in the cloud. See the OpenVPN website here and Ubuntu page here for additional information.

Youtube


Referensi

Pranala Menarik