CentOS 5.8 - Set up an OpenVPN Server

Introduction

This tutorial will show you how to set up an openvpn server on Centos 5.8 (may work the same way on 6.x). Alternatively, you may want to follow my other tutorial on how to set up on Ubuntu Server 12.04 LTS instead.

Steps

    rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
    yum install openvpn
    cp -R /usr/share/doc/openvpn/examples/ /home/openvpn
    cd /home/openvpn/easy-rsa/2.0/
    This is an optional step that may save you time. You can edit the variables in the vars file to set defaults so that you don't have to keep typing in values later. These variables are at the bottom of the file.
    vi vars
    source vars
    Clear out any keys that are already set.
    ./clean-all
    ./build-ca
    Set up the server variables.
    ./build-key-server server
    Set the client variables.
    ./build-key client1
    If you get an error after running the previous command, it is probably because you entered the exact same details as you did with the server for every field. One of the fields needs to be different.
    Generate the keys.
    ./build-dh
    Copy the files you just generated to the directory that actually runs the openvpn service.
    cd /home/openvpn/easy-rsa/2.0/keys
    cp ca.crt ca.key dh1024.pem server.crt server.key /etc/openvpn
    Copy the sample server configuration file to the directory that will run it. We will edit it later.
    cd /usr/share/doc/openvpn/examples/sample-config-files
    cp server.conf /etc/openvpn/
    Copy the sample client configuration as we did with the server. We will edit it later.
    cp client.conf /etc/openvpn/
    cd /etc/openvpn/
    vi client.conf



    vi /etc/openvpn/server.conf

    vi /etc/sysctl.conf
    uncomment the following line
    net.ipv4.ip_forward=1
    echo 1 > /proc/sys/net/ipv4/ip_forward
    Next issue the following commands to configure Iptables one by one:
    iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT
    iptables -A FORWARD -j REJECT
    iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT –to-source YourVPSIP
    /etc/init.d/openvpn restart
    copy ca.crt client.conf client1.crt and client1.key to your client computer.
    Run this command on your client computer:
    sudo openvpn --config /location/of/your/copied/files/client.conf

Source

TipUpdate How To Install OpenVPN on Ubuntu VPS

No comments:

Post a Comment