Centos 6.x 64bit : Script Install Basic OpenVPN 100% Success

OpenVPN tutorials ranging from configuration to hacks to compilation will be posted here.
Post Reply
OpenVpn Newbie
Posts: 1
Joined: Mon Nov 10, 2014 3:42 pm

Centos 6.x 64bit : Script Install Basic OpenVPN 100% Success

Post by ntycle » Mon Nov 10, 2014 3:48 pm


I just a newbie so I lost 2 days to setup Openvpn, Now i write and share a script for install faster ( about 3-5 minutes ).

Code: Select all

#Setup OpenVPN auto

yum install openvpn easy-rsa -y
mkdir -p /etc/openvpn/easy-rsa/keys
cp -R /usr/share/easy-rsa/2.0/ /etc/openvpn/easy-rsa/
cd /etc/openvpn/easy-rsa/2.0/
sed -i 's|export KEY_CONFIG=`$EASY_RSA/whichopensslcnf $EASY_RSA`|export KEY_CONFIG=/etc/openvpn/easy-rsa/2.0/openssl-1.0.0.cnf|' vars
chmod 0755 *
. ./vars

#Run 1 line at time.
./build-ca # In common name should be name [b]server[/b]
./build-key-server server 
./build-key thanhhuy #Create Client

# Set the server configuration
cp /usr/share/doc/openvpn-2.3.2/sample/sample-config-files/server.conf /etc/openvpn/
cd /etc/openvpn/
sed -i 's|;duplicate-cn|duplicate-cn|' server.conf
sed -i 's|;log         openvpn.log|log         openvpn.log|' server.conf
sed -i 's|;user nobody|user nobody|' server.conf
sed -i 's|;group nobody|group nobody|' server.conf
sed -i 's|dh dh1024.pem|dh /etc/openvpn/easy-rsa/2.0/keys/dh2048.pem|' server.conf
sed -i 's|;push "redirect-gateway def1 bypass-dhcp"|push "redirect-gateway def1 bypass-dhcp"|' server.conf
sed -i 's|ca ca.crt|ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt|' server.conf
sed -i 's|cert server.crt|cert /etc/openvpn/easy-rsa/2.0/keys/server.crt|' server.conf
sed -i 's|key server.key|key /etc/openvpn/easy-rsa/2.0/keys/server.key|' server.conf
sed -i 's|;push "dhcp-option DNS"|push "dhcp-option DNS"|' server.conf
sed -i 's|;push "dhcp-option DNS"|push "dhcp-option DNS"|' server.conf
sed -i 's|net.ipv4.ip_forward = 0|net.ipv4.ip_forward = 1|' /etc/sysctl.conf
sysctl -p
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -v -F
iptables -F -t mangle
iptables -F -t nat
iptables -v -A INPUT -i lo -j ACCEPT
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE
service iptables save
service iptables restart
chkconfig --add openvpn
chkconfig openvpn on
service openvpn start

I haved tested with VPS at Vultr Centos 6.x 64 bit ( Not work with Centos 7 )

Hope help anyone else,
Last edited by debbie10t on Mon Nov 10, 2014 4:38 pm, edited 2 times in total.
Reason: Title Clarity

Post Reply