Last active
October 12, 2018 02:45
-
-
Save lattice0/7cf88c66a96eb4dbfe7943a933320008 to your computer and use it in GitHub Desktop.
open vpn zainco configurations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script will extract the certificate and key from an .ovpn file | |
# into their own files, which makes it possible to use them to configure | |
# the VPN using Ubuntu's network manager | |
# Usage example: | |
# >> ovpnconvert username.dev.ovpn | |
# You can keep following these instructions here: | |
# https://naveensnayak.wordpress.com/2013/03/04/ubuntu-openvpn-with-ovpn-file/ | |
sed '1,/<ca>/d;/<\/ca>/,$d' $1 > $1.ca.crt | |
sed '1,/<cert>/d;/<\/cert>/,$d' $1 > $1.client.crt | |
sed '1,/<key>/d;/<\/key>/,$d' $1 > $1.client.key | |
sed '1,/<tls-auth>/d;/<\/tls-auth>/,$d' $1 > $1.ta.key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The right way to do: | |
sudo openvpn --config /home/pi/zainco_ovpn.conf | |
If you want to ignore all routes and do your own (that is, no routes are specified in the conf file) | |
#sudo openvpn --config /home/pi/zainco_ovpn.conf --pull-filter ignore redirect-gateway --route-noexec | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Install openvpn: | |
sudo apt install -y openvpn | |
#Disable if you want to. We're going to write our own start script. | |
sudo service openvpn disable | |
#I had to do the following masquerade thing | |
#Enable ipv4 forwarding | |
sudo sysctl -w net.ipv4.ip_forward=1 | |
#Add a masquerade for outbound traffic on tun0: | |
sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE | |
#Save the iptables rule. | |
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" | |
#Edit /etc/rc.local and add this just above "exit 0" to install these rules on boot. | |
iptables-restore < /etc/iptables.ipv4.nat | |
#Install dnsmasq to serve dhcp on eth0 | |
sudo apt-get install dnsmasq | |
#Since the configuration files are not ready yet, turn the new software off as follows: | |
sudo systemctl stop dnsmasq | |
#Now let's configure dnsmasq | |
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig | |
sudo nano /etc/dnsmasq.conf | |
#Type or copy the following information into the dnsmasq configuration file and save it: | |
interface=wlan0 # Use the require wireless interface - usually wlan0 | |
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h | |
#We must give an IP address for eth0 that is not in the subnet of the things that will be acessed through eth0, in this case the cameras | |
#To configure the static IP address, edit the dhcpcd configuration file with: | |
sudo nano /etc/dhcpcd.conf | |
#Go to the end of the file and edit it so that it looks like the following: | |
interface eth0 | |
static ip_address=192.168.2.1/24 | |
#Now restart the dhcpcd daemon and set up the new wlan0 configuration: | |
sudo service dhcpcd restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################## | |
# 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 | |
route-nopull | |
route 192.168.0.101 255.255.255.255 | |
route 192.168.0.102 255.255.255.255 | |
route 192.168.0.103 255.255.255.255 | |
route 192.168.0.104 255.255.255.255 | |
route 192.168.0.105 255.255.255.255 | |
route 192.168.0.106 255.255.255.255 | |
route 192.168.0.107 255.255.255.255 | |
route 192.168.0.108 255.255.255.255 | |
route 192.168.0.109 255.255.255.255 | |
route 192.168.0.110 255.255.255.255 | |
route 192.168.0.111 255.255.255.255 | |
#route 192.168.2.0 255.255.255.0 | |
route-metric 0 | |
#route-nopull | |
#script-security 2 | |
# run /etc/openvpn/up.sh when the connection is set up | |
#up "sysctl -w net.ipv4.ip_forward=1 && iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE && sh -c \"iptables-save > /etc/iptables.ipv4.nat\"" | |
script-security 2 | |
# run /etc/openvpn/up.sh when the connection is set up | |
#up ls | |
up masquerade.sh | |
# 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 tun0 | |
# 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 cilinho.dyndns.org 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 cilinho.ovpn.ca.crt | |
cert cilinho.ovpn.client.crt | |
key cilinho.ovpn.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 cilinho.ovpn.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 2.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 | |
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client | |
route-nopull | |
route 192.168.0.101 255.255.255.255 | |
route 192.168.0.102 255.255.255.255 | |
route 192.168.0.103 255.255.255.255 | |
route 192.168.0.104 255.255.255.255 | |
route 192.168.0.105 255.255.255.255 | |
route 192.168.0.106 255.255.255.255 | |
route 192.168.0.107 255.255.255.255 | |
route 192.168.0.108 255.255.255.255 | |
route 192.168.0.109 255.255.255.255 | |
route 192.168.0.110 255.255.255.255 | |
route 192.168.0.111 255.255.255.255 | |
#route 192.168.2.0 255.255.255.0 | |
route-metric 0 | |
#route-nopull | |
#script-security 2 | |
#up masquerade.sh | |
dev tun0 | |
proto udp | |
remote cilinho.dyndns.org 1194 | |
resolv-retry infinite | |
nobind | |
persist-key | |
persist-tun | |
ca cilinho.ovpn.ca.crt | |
cert cilinho.ovpn.client.crt | |
key cilinho.ovpn.client.key | |
remote-cert-tls server | |
tls-auth cilinho.ovpn.ta.key 1 | |
cipher AES-256-CBC | |
verb 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment