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

From OnnoWiki
Jump to navigation Jump to search
 
(19 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
  
 +
==Step 1 – Update system==
  
 +
Run,
  
Procedure: Ubuntu 18.04 LTS Set Up OpenVPN Server In 5 Minutes
+
sudo apt update
 +
sudo apt upgrade
  
The steps are as follows:
+
==Step 2 Cek IP address==
Step 1 Update your system
 
  
Run the apt command/apt-get command:
+
Pakai perintah,
$ sudo apt update
 
$ sudo apt upgrade
 
Step 2 – Find and note down your IP address
 
  
Use the ip command as follows:
+
ip a
$ ip a
+
ip a show eth0
$ ip a show eth0
+
ip a show enp0s3
  
ip command get my IP address on Ubuntu Linux 18.04 LTS
+
==Step 3 – Download & run openvpn-install.sh script==
Another option is to run the following dig command/host command to find out your public IP address from Linux command line:
 
$ dig +short myip.opendns.com @resolver1.opendns.com
 
  
OR
+
Pastikan tidak ada yang menggunakan repository ubuntu,
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
 
  
Find out my public IP address using the CLI
+
sudo rm -Rf /var/lib/dpkg/lock
A note about IP address
 
  
Most cloud servers have two types of IP address:
+
Sebagai '''User Biasa''', Download,
  
    Public static IP address directly assigned to your box and routed from the Internet. For example, Linode, Digital Ocean, and others gives you direct public IP address.
+
sudo chmod 777 /usr/local/src
    Private static IP address directly attached to your server and your server is behind NAT with public IP address. For example, AWS EC2/Lightsail give you this kind of NAT public IP address.
+
cd /usr/local/src/
 +
wget https://git.io/vpn -O openvpn-install.sh
 +
chmod +x openvpn-install.sh
  
The script will automatically detect your networking setup. All you have to do is provide correct IP address when asked for it.
+
Run,
Step 3 – Download and run openvpn-install.sh script
 
  
I am going to use the wget command:
+
sudo ./openvpn-install.sh
$ wget https://git.io/vpn -O openvpn-install.sh
 
  
Download openvpn-install.sh script to setup OpenVPN server in 5 minutes on Ubuntu
+
Akan keluar beberapa pertanyaan, tekan [ENTER].
Setup permissions using the chmod command
+
Selesai instalasi, contoh sertifikat ~/client.ovpn akan di keluarkan.
$ chmod +x openvpn-install.sh
 
  
One can view the script using a text editor such as nano/vim:
+
Hack sedikit
$ vim openvpn-install.sh
 
Run openvpn-install.sh to install OpenVPN server
 
  
Now all you have to do is:
+
sudo su
$ sudo ./openvpn-install.sh
+
cp -Rf /etc/openvpn/server/* /etc/openvpn/
  
Sample session from AWS/Lightsail where my cloud server is behind NAT:
+
Run OpenVPN,
Ubuntu 18.04 LTS Setup OpenVPN Server In 5 Minutes
 
Sample session from Linode/DO server where cloud server has direct public IPv4 address:
 
How To Setup OpenVPN Server In 5 Minutes on Ubuntu Linux
 
To avoid problem always choose DNS as 1.1.1.1 or Google DNS. Those are fast DNS server and reached from anywhere on the Internet.
 
How do I start/stop/restart OpenVPN server on Ubuntu 18.04 LTS?
 
  
$ sudo systemctl stop openvpn@server # <--- stop server
+
sudo systemctl stop openvpn@server   # <--- stop server
$ sudo systemctl start openvpn@server # <--- start server
+
sudo systemctl start openvpn@server   # <--- start server
$ sudo systemctl restart openvpn@server # <--- restart server
+
sudo systemctl restart openvpn@server # <--- restart server
$ sudo systemctl status openvpn@server # <--- get server status
+
sudo systemctl status openvpn@server # <--- get server status
Step 4 – Connect an OpenVPN server using IOS/Android/Linux/Windows client
 
  
On server your will find a client configuration file called ~/desktop.ovpn. All you have to do is copy this file to your local desktop using the scp command:
+
==Step 4 – Connect an OpenVPN server using IOS/Android/Linux/Windows client==
$ scp vivek@104.20.187.5:~/deskcop.ovpn .
 
  
Next, provide this file to your OpenVPN client to connect:
+
Copykan file sertifikat client.ovpn ke client, misalnya menggunakan perintah,
  
    Apple iOS client
+
scp vivek@104.20.187.5:~/client.ovpn .
    Android client
 
    Apple MacOS (OS X) client
 
    Windows 8/10 client
 
  
Linux Desktop: OpenVPN client configuration
+
===Linux Desktop: OpenVPN client configuration===
  
First, install the openvpn client for your desktop, enter:
+
Install,
$ sudo yum install openvpn
 
  
OR
+
sudo apt -y install openvpn
$ sudo apt install openvpn
+
sudo cp client.ovpn /etc/openvpn/client.ovpn
  
Next, copy desktop.ovpn as follows:
+
Coba sambungan dari sisi client
$ sudo cp desktop.ovpn /etc/openvpn/client.conf
 
  
Test connectivity from the CLI:
+
sudo openvpn --client --config /etc/openvpn/client.ovpn
$ sudo openvpn --client --config /etc/openvpn/desktop.conf
 
  
Your Linux system will automatically connect when computer restart using openvpn script/service:
+
Linux akan secara automatis tersambung ke computer dengan openvpn script
$ sudo systemctl start openvpn@client # <--- start client service
+
 
Step 5 - Verify/test the connectivity
+
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:
 
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
 
A note about trouble shooting OpenVPN server and client issues
 
  
Check OpenVPN server for errors:
+
ping 10.8.0.1      # Ping to the OpenVPN server gateway
$ journalctl --identifier ovpn-server
+
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:
  
OpenVPN server log files and error
+
journalctl --identifier ovpn-server
Click to enlarge image
 
  
Is firewall rule setup correctly on your server? Use the cat command to see rules:
+
Cek Filewall Rules
$ cat /etc/rc.local
 
  
#!/bin/sh -e
+
cat /etc/rc.local
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
 
  
Another option is to run iptables command and sysctl command commands to verify NAT rule setup on your server:
+
#!/bin/sh -e
$ sudo iptables -t nat -L -n -v
+
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to 172.26.6.74
$ sysctl net.ipv4.ip_forward
+
exit 0
  
NAT Firewall OpenVPN Rules Verification
+
Alternatif lain, run iptables command & sysctl command untuk verifikasi NAT rule setup
Insert the rules if not inserted from /etc/rc.local
+
 
$ sudo sh /etc/rc.local
+
sudo iptables -t nat -L -n -v
$ sudo sysctl -w net.ipv4.ip_forward=1
+
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:
 
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 ##
+
$ netstat -tulpn | grep :1194 ## 1194 is the openvpn server port ##
$ ps aux | grep openvpn ## is the openvpn server running? ##
+
$ ss -tulpn | grep :1194 ## 1194 is the openvpn server port ##
$ ps -C openvpn ## is the openvpn server running? ##
+
$ ps aux | grep openvpn ## is the openvpn server running? ##
$ pidof openvpn ## find the openvpn server PID ##
+
$ 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
 
Verify that OpenVPN server runnign and Port is Open on ubuntu Linux
 
If not running, restart the OpenVPN server:
 
If not running, restart the OpenVPN server:
$ sudo systemctl restart openvpn@server
+
$ sudo systemctl restart openvpn@server
  
 
Look out for errors:
 
Look out for errors:
$ sudo systemctl status openvpn@server
+
$ 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:
 
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
+
$ nc -vu 104.20.187.5 1194
 
Connection to 104.20.187.5 1194 port [udp/openvpn] succeeded!
 
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.
 
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
+
 
 +
==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.
 
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==
 +
 +
* [https://youtu.be/qb07-Lpd71M YOUTUBE: Membuat Sambungan Server - OpenVPN - Cloud - Mikrotik - Kali]
  
  
Line 149: Line 137:
  
 
==Pranala Menarik==
 
==Pranala Menarik==
 +
 +
* [[OpenVPN: IPv4 /32 single client]]
 +
* [[OpenVPN: IPv4 /32 multi-client]]
 +
* [[OpenVPN: IPv4 routed LAN]]
 +
* [[OpenVPN: IPv4 routed 2 LAN]]
 +
* [[OpenVPN: IPv6 /128 single client]]
 +
* [[OpenVPN: IPv6 routed LAN]]
 +
* [[OpenVPN: IPv6 routed 2 LAN]]
 +
 +
* [[IPv6: OpenVPN: Ubuntu roadwarrior]]
 +
* [[OpenVPN: Simple Server using Script]]
 +
* [[OpenVPN: Free VPN untuk Ubuntu]]
 +
* [[Instalasi OpenVPN]]
 +
* [[Instalasi OpenVPN Client di Linux]]
 +
* [[Capture Screen Proses Instalasi OpenVPN di Windows]]
 +
* [[Instalasi OpenVPN di Windows]]
 +
* [[WNDW: OpenVPN]]
 +
* [[OpenVPN: Instalasi di Ubuntu 16.04]]
 +
* [[OpenVPN: Instalasi di Ubuntu 18.04]]
 +
* [[OpenVPN: Briding dan Routing]]

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