Quick install and config OpenVPN for Internet Access on Debian Squeeze

Valic —  August 22, 2011 — 1 Comment

This bash script was cread for you to help you to set up a VPN that will let you do many things.

This bash script is based primarily on another tutorials, but I have updated and I added some more infos.

This is the script:

#!/bin/bash
# OpenVPN install script
# Tested on Debian Squeeze
# Please submit feedback and questions at [email protected]

ip=`grep address /etc/network/interfaces | grep -v 127.0.0.1 | awk ‘{print $2}’`
apt-get update
apt-get install openvpn libssl-dev openssl
cd /etc/openvpn/
cp -R /usr/share/doc/openvpn/examples/easy-rsa/ /etc/openvpn/
cd /etc/openvpn/easy-rsa/2.0/
chmod +rwx *
. ./vars
./clean-all
source ./vars

echo -e “\n\n\n\n\n\n\n” | ./build-ca
clear

./build-key-server server
./build-dh
cp keys/{ca.crt,ca.key,server.crt,server.key,dh1024.pem} /etc/openvpn/

clear

./build-key client1

cd keys/

#Creating the client config files
client=”
remote $ip 4141
dev tun
client
proto tcp
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
comp-lzo
verb 3″

echo “$client” > $HOSTNAME.ovpn

tar czf keys.tgz ca.crt ca.key client1.crt client1.csr client1.key $HOSTNAME.ovpn
mv keys.tgz /root

#creating the openvpn server config file
opvpn=’
dev tun
proto tcp
port 4141
user nobody
group nogroup
server 10.8.0.0 255.255.255.0
persist-key
persist-tun
status /var/log/openvpn-status.log
verb 3
client-to-client
push “redirect-gateway def1″
#set the dns servers
# optional you can use the google dns server.
#push “dhcp-option DNS 8.8.8.8″
#push “dhcp-option DNS 8.8.4.4″
log-append /var/log/openvpn
comp-lzo
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
keepalive 10 120″
echo “$opvpn” > /etc/openvpn/openvpn.conf

#Start the internet forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
#Restarting the openvpn daemon
/etc/init.d/openvpn restart
clear

echo “OpenVPN has been installed
Download /root/keys.tgz using winscp or other sftp/scp client
Create a directory named vpn at C:\Program Files\OpenVPN\config\ and untar the content of keys.tgz there
Start openvpn-gui, right click the tray icon go to vpn and click connect
Enjoy your connection

You can also download the script directly from HERE

Allow me now to explain to you some point from the script:

  1. We are using the TCP protocol because UDP it’s giving  you better performance, but, I had to configure TCP because UDP was blocked by the Internet provider firewall. You can change ti udp if you wish.
  2. I put the port to 4141. The default port is 1194. I made this change because some firewalls do not allow connections to different port numbers. You can use any port.
  3. You can change the two lines in which you set the DNS servers if desired. These should be the access servers to resolve names in the VPN. Those in the configuration file are public DNS servers Google.

Enjoy!

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

Trackbacks and Pingbacks:

  1. Quick install and config OpenVPN for Internet Access on Debian … | Linux Blog - August 22, 2011

    [...] let you do many things. This bash script is based primarily on another tutorials, Visit link: Quick install and config OpenVPN for Internet Access on Debian … This entry was posted in Uncategorized and tagged another-tutorials, bash-script, tutorials, vpn [...]

Leave a Reply