Home How to Build own OpenVPN server by using raspberry Pi (Part2/2)

Build own OpenVPN server by using raspberry Pi (Part2/2)

by admin

Build own OpenVPN server by using raspberry Pi (Part2/2)

See network diagram above describing our scenario

See network diagram above describing our scenario

1. Traffic is encrypted on the way to OpenVPN server
2. Traffic is initiated from OpenVPN server on behalf of client (mobile, laptop)

Introduction

Welcome to the second part of our article where we will finish our setup on client side. In our scenario I will use smartphone as end-device. At the end we will be able to establish VPN tunnel between smartphone and raspberry Pi, so it does not matter where you are connected, you will be fully redirected to the VPN and using Internet connectivity as you should be sitting at home. Exactly the same procedure with any small differences can be used also for your laptop, table or any other device which is able to install OpenVPN application. 

In case you have some troubles or need to review your server config again, feel free to check our first post:

Build own OpenVPN server by using Raspberry Pi (Part1/2) – server configuration (Raspberry Pi)

Preparing configuration file

 Open (create) new config file so we will edit it according to our requirements:

vi /etc/openvpn/Client1.conf

Now put following content to the file:

client
dev tun
proto udp
remote <YOUR PUBLIC IP OR DYNDNS HOSTNAME> 1194
resolv-retry infinite
nobind
persist-key
persist-tun
mute-replay-warnings
ns-cert-type server
key-direction 1
cipher AES-256-CBC
comp-lzo
verb 1
mute 20
<ca>
-----BEGIN CERTIFICATE-----
MIIE6DCCA9CgAwIB94fjldnIFhelx9kZMA0GCSqGSIb3DQEBCwUAMIGoMQswCQYD
VQQGEwJTSzELMAkGA1UECBMCQ0ExETAPBgNVBAcTCFNsb3Zha2lhMRIwEAYDVQQK
FAlrYWxrb19ycGkxFjAUBgNVBAsUDWthbGtvX3JwaV9WUE4xFTATBgNVBAMUDGth
bGtvX3JwaV9DQTETMBEGA1UEKRQKa2Fsa29fcnBpMTEhMB8GCSqGSIb3DQEJARYS
bWVAbXlob3N0Lm15ZG9tYWluMB4XDTE3MDIyMTEzMTcwNFoXDTI3MDIxOTEzMTcw
NFowgagxCzAJBgNVBAYTAlNLMQswCQYDVQQIEwJDQTERMA8GA1UEBxMIU2xvdmFr
aWExEjAQBgNVBAoUCWthbGtvX3JwaTEWMBQGA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Ur5+9riRcSruU4f6vE9DnBpNBcQE3dTlVDWqs9caMApdJSCIO
KC9rYFN1F+rsbthfVw3J3uJVeS66FPtDIILqdtTchcMLqPZh17DZTkh+tEi8O6gm
+YftPRdPrqYemeF6TRN6Wox0kI1JKhvD0z/c04vat2oWFyJyIMjvk7o2c2blWeCE
DXpkatLk0EPWVyQDxlIagSIReh0tRu5cfUKINpvYnjE0E9yZPw6R72KpiyQuiPV1
Yt/YUJLXOmaWhH7aexQihYqzakkbpZaGcX+a0bCweAL+vuoCS2PZLOo2XnWe1YQe
LBOJ2cGJrih1Lk3yPs2p4JNGksc/9pcq9J+qevkeSY5v7Hx+rpyNjuYhrg3qKGsE
6yruFzG0Id4tEAqUT8JJKsOf1kzfrPtmUY8aEzBATdSnNSb+qJhzwQ/qkxVHgi1B
pcVaFtVuvm7/7cwtanqjoHBAiuyK5VKzZKZCxsdzZ6eYkdH3FEL/EF5hJQGO5Pqj
ipNyLt0skpwotcNl4hduHD81bPB1qcANhUVIzhvhTVEpt9nn12xJ9wjInA+0rAmp
dUxfAUEGghJzmfYFYAL1eFGd5VQGikgzMnNTCYZjdplKJML1GHktzJGn61C6W8Z3
-----END RSA PRIVATE KEY-----
</key>
<tls-auth>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
0fe00c09a3716d9deb7dc82d97e97eee
0a845ebc99ab3e2dfe2afc968f45a2fc
661ab2674570a4fb4d0b7f88784e52d6
03129226690d546f8d1d9c1f420c8a22
9f8aa8dd05a6d3cfff71b9b5f98d5122
bcf1624a621bb95da5a3097969bc7c8b
43b88070fdf855a9b794dcd933b56be7
ec2253030392c93c91201df444db0815
34a11fe37c92711512a65ec723321766
b01a79d181f785a84f57693add25ae34
93cad70a4341a6b5a5ff32b853eb3e07
1d5e8df34de82caade714c3d0be26df8
84862fe81f9668952afdc8c4acab302f
eef0c896674e5892b7539b3bac17c6ab
412c6a9b3756cebc083e5dd865f5bdea
efeae4c1020eb199a9fc8fe89a6731b8
-----END OpenVPN Static key V1-----
</tls-auth>

Now let me put some words here. First of all, above published keys/certificates are randomly generated and not used in production (security reasons). I have just pasted it here to be sure that you know exactly how content of your config file should look like and what format should be used. You will have to make some adjustments to the config above:

  1. Replace segment <YOUR PUBLIC IP OR DYNDNS HOSTNAME> with your static public IP or dynamic dns record. It has to point to the public IP (dns record) behind which your openVPN server is sitting on. Beware that usually is also needed to make port-forwarding on your router: <any_public_ip>:1194 —-> <local_IP_of_your_raspberry>:1194 Please follow official guideline of your router how to proceed here.

  2.  We used inline references to the keys and certificates as opposed to packaging them up together. Copy and paste each in the appropriate area. Be sure to paste it completely without any  additional spaces or characters.
<ca>
-----BEGIN CERTIFICATE-----
# insert base64 blog from file ca.crt
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
# insert base64 blog from file Client1.crt
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN PRIVATE KEY-----
# insert base64 blog from file Client1.aes256.key
-----END PRIVATE KEY-----
</key>

Once your config file is ready, rename it to the extension .ovpn which is used by OpenVPN application:

mv client1.conf client1.ovpn

Email the Config File to Yourself, or Use Dropbox/Google Drive, etc. Please use secure way to transfer file as it is containing also your private key.

READ ALSO:  10 most dangerous linux commands you should never run

OpenVPN application and import

Just follow screenshots below to install application and import configuration file on client side (in our case android smartphone).

Install OpenVPN application on smartphone

Install OpenVPN application

Import configuration file

Import configuration file

Import Client1.ovpn file from SDcard

Import Client1.ovpn file from SDcard

Insert pass-phrase you've entered during creation

Insert pass-phrase you’ve entered during creation

OVPN profile has been successfully imported

OVPN profile has been successfully imported

VPN connection successfully established

VPN connection successfully established

Final testing

In order to test VPN implementation, you can try to find out what is your current public IP before VPN activation and what is after. If everything is working correctly you will be able to see different IPs. Once you are connected to the VPN tunnel you will see exactly the same public IP as you have at home. For simple testing, you can use website: https://www.whatismyip.com/

During any troubles, you can check logs on server side:

less /var/log/openvpn.log

If you need to check logs on client side, use “Show log file” option directly in OpenVPN application.

Conclusion

Congratulations! Now you have successfully finished openVPN configuration on server and client side. In case of any questions, do not hesitate to leave comment below.

source: openvpn.com

You may also like

2 comments

kenny May 21, 2017 - 10:21 pm

Great tutorial, worked like a charm after others failed. Using tunnelblick on mac. Only had to identify and make one correction.. where you say “# insert base64 blog from file Client1.key” it should be “# insert base64 blog from file Client1.aes256.key” noting the aes256, as both Client1.key and Client1.aes256.key exist based on setup.

Reply
admin July 4, 2017 - 3:29 pm

Thank you Kenny, it has been fixed 😉

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept

Privacy & Cookies Policy