May 25, 2011

setup vpn server on Amazon EC2

My environment: Amazon free EC2, Ubuntu 10.04 64bit

You should modify some hard code.

server side

  • $ cat
    # install pptpd
    apt-get install -y pptpd
    # config pptpd
    echo "localip" >> /etc/pptpd.conf
    echo "remoteip" >> /etc/pptpd.conf
    echo "ms-dns" >> /etc/ppp/options.pptpd
    echo "ms-dns" >> /etc/ppp/options.pptpd
    # generate user's password
    passwd=`openssl rand 10 -base64`
    if [ "$1" != "" ]
    then passwd=$1
    # setup authenticated user
    echo "user pptpd $passwd *" >> /etc/ppp/chap-secrets
    # for ipv4 forwarding
    sed -i 's/^#net.ipv4.ip_forward = 1/net.ipv4.ip_forward = 1/' \
    sysctl -p
    # use iptabes to get the net forward
    iptables -t nat -A POSTROUTING -s -j SNAT \
     --to-source $(ifconfig  | grep 'inet addr:'| \
     grep -v '' | cut -d: -f2 \
     | awk 'NR==1 { print $1}')
    iptables -A FORWARD -p tcp --syn -s \
     -j TCPMSS --set-mss 1356
    service iptables save
    # make the iptables and pptpd auto start
    chkconfig iptables on
    chkconfig pptpd on
    service iptables start
    service pptpd start
    echo "VPN service is installed"
    echo "VPN username is user,VPN password is $passwd"

client side

$ cat

apt-get install -y pptp-linux

# modify those variable for your environment

echo "pty \"pptp $vpn_server --nolaunchpppd\"
name $user
remotename pptpd 
file /etc/ppp/options.pptp
ipparam pptpd" > /etc/ppp/peers/pptpd

echo "$user pptpd $passwd *" >> /etc/ppp/chap-secrets

echo "setup vpn client done."
echo -e "now, you shoule run:"
echo -e "\t$ pon pptpd # start pptpd"
echo -e "\t$ pon pptpd debug dump logfd 2 nodetach # debugging"
echo -e "\t$ poff pptpd # stop pptpd"
echo -e "\t$ ifconfig # check network config"

No comments:

Post a Comment