Aerosol Posted March 23, 2015 Report Posted March 23, 2015 Hello all,Today we will install a OpenVPN server. For this copy/paste this script (edit email, vpn dns name and client certificate name as you need). After this run command chmod +x openvpn.sh && ./openvpn.sh and run all steps showed from 1 to 16 because 17 is for quit. To run each step when apear #? pres 1, after done press 2 and so on until 16.Enjoy #!/bin/bash#title :openvpn.sh#author :razvan1@hy#date :20141209#usage : Put in to /root directory and bash -X openvpn.sh#==============================================================================SELECTION="update-os test-tun install-ovpn add-vars import-vars delete-old-certs generate-ca generate-cert generate-dh generate-client generate-hmac place-certs conf-ovpn-server forwarding set-iptables restart-ovpn quit"select options in $SELECTION; doif [ "$options" = "update-os" ]; then echo "Updating OS!" apt-get clean && apt-get update && apt-get upgrade -y && apt-get dist-upgrade -yelif [ "$options" = "test-tun" ]; then echo "Test if it supports TUN!" test ! -c /dev/net/tun && echo openvpn requires tun support || echo tun is availableelif [ "$options" = "install-ovpn" ]; then echo "Install OpenVPN" apt-get install openvpn -y && cp -prv /usr/share/doc/openvpn/examples/easy-rsa/2.0 /root/easy-rsa && cd /root/easy-rsa && cp vars{,.orig}elif [ "$options" = "add-vars" ]; then echo "export KEY_COUNTRY="RO"export KEY_PROVINCE="B"export KEY_CITY="Bucuresti"export KEY_ORG="ORG_name"export KEY_EMAIL="user@mail.ro"export KEY_EMAIL=user@mail.roexport KEY_CN=vpn.domain.roexport KEY_NAME=vpn.domain.roexport KEY_OU=IT#export PKCS11_MODULE_PATH=changeme#export PKCS11_PIN=1234" > /root/easy-rsa/varselif [ "$options" = "import-vars" ]; then echo "Import vars" cd /root/easy-rsa/ && source ./varselif [ "$options" = "delete-old-certs" ]; then echo "delete previously created certs" cd /root/easy-rsa/ && ./clean-allelif [ "$options" = "generate-ca" ]; then echo "generate the CA certificate" cd /root/easy-rsa/ && ./build-caelif [ "$options" = "generate-cert" ]; then echo "generate VPN server certificate" cd /root/easy-rsa/ && ./build-key-server SERVERelif [ "$options" = "generate-dh" ]; then echo "generate the Diffie-Hellman PEM certificate" cd /root/easy-rsa/ && ./build-dhelif [ "$options" = "generate-client" ]; then echo "generate client certificate" cd /root/easy-rsa/ && ./build-key razvan1elif [ "$options" = "generate-hmac" ]; then echo "generate secret Hash-based Message Authentication Code (HMAC)" /usr/sbin/openvpn --genkey --secret /root/easy-rsa/keys/ta.keyelif [ "$options" = "place-certs" ]; then echo "place the certificates and keys on the server in the /etc/openvpn/certs directory" mkdir -p /etc/openvpn/certs && cp -pv /root/easy-rsa/keys/{ca.{crt,key},SERVER.{crt,key},ta.key,dh2048.pem} /etc/openvpn/certs/elif [ "$options" = "conf-ovpn-server" ]; then echo "set-up OpenVPN server configuration file in /etc/openvpn/server.conf" touch /etc/openvpn/server.conf && echo "port 1194proto udpdev tunca /etc/openvpn/certs/ca.crtcert /etc/openvpn/certs/SERVER.crtkey /etc/openvpn/certs/SERVER.keydh /etc/openvpn/certs/dh1024.pemtls-auth /etc/openvpn/certs/ta.key 0server 10.0.0.0 255.255.255.0ifconfig-pool-persist ipp.txtpush "redirect-gateway def1 bypass-dhcp"push "dhcp-option DNS 8.8.8.8"push "dhcp-option DNS 8.8.4.4"client-to-clientkeepalive 20 120client-config-dir ccdcipher DES-EDE3-CBCcomp-lzomax-clients 10user nobodygroup nogrouppersist-keypersist-tunlog /var/log/openvpn.logstatus /var/log/openvpn-status.logverb 5mute 20" > /etc/openvpn/server.conf && mkdir /etc/openvpn/ccdelif [ "$options" = "forwarding" ]; then echo "enable network forwarding" echo 1 > /proc/sys/net/ipv4/ip_forward && sysctl -pelif [ "$options" = "set-iptables" ]; then echo "set-up the following iptables rules" /sbin/iptables -A INPUT -p udp -m state --state NEW -m udp --dport 1194 -j ACCEPT /sbin/iptables -A FORWARD -s 10.0.0.0/24 -j ACCEPT /sbin/iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT /sbin/iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o eth0 -j MASQUERADEelif [ "$options" = "restart-ovpn" ]; then echo "start the OpenVPN server and add enable it to run on system's start-up" service openvpn restart && update-rc.d -f openvpn defaultselif [ "$options" = "quit" ]; then echo "You have selected $options" exitelse clear; echo "please select some options"fidoneCredit's to:razvan1@hy Quote