How to build a VPN in Amazon cloud space

Source: Internet
Author: User
Tags flush iptables


The script content is very simple, uses the Yum to install the software, and has made the configuration, but, because I use the Ubuntu image, is apt, therefore needs to make some changes.
Here's my modified script:

#!/bin/bash

# automaticlly Install pptpd on Amazon EC2 Amazon Linux (Ubuntu)
#
#我用的是ubuntu的镜像, the main is to install VPN needs software, set iptables, configure PPP and VPN
#记得添加自定义规则: TCP port 1723, for VPN use
#
#
# Authors:kime (cidy0106#gmail.com)
# version:0.0.1
#
#安装不要软件ppp和pptpd
Apt-get Install PPPTD PPP

#下面是注释掉的, I don't know exactly what the effect is, keep
Sed-i ' s/^logwtmp/#logwtmp/g '/etc/pptpd.conf

#启用转发
Sed-i ' S/^net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g '/etc/sysctl.conf
Sed-i ' s/^net.ipv4.ip_forward=0/net.ipv4.ip_forward=1/g '/etc/sysctl.conf
Sysctl-p

#分配ip, I use 192.168.222 network segment, I can modify, remember the iptable part of the following also need to modify
echo "Localip 192.168.222.1" >>/etc/pptpd.conf
echo "Remoteip 192.168.222.2-100" >>/etc/pptpd.conf

#设置dns, like my VPN server, remember to change it to your own, or it's probably not going to be on the web.
#原文是设置/etc/ppp/options.pptpd file, but I'm not/etc/ppp/pptpd-options, specifically see/etc/pptpd.conf's description

Mydns= ' cat/etc/resolv.conf |grep nameserver | awk ' {print $} '
echo "Ms-dns $mydns" >>/etc/ppp/pptpd-options
echo "Ms-dns 8.8.8.8" >>/etc/ppp/pptpd-options

#iptables--flush postrouting--table NAT
#iptables--flush FORWARD

#下面会生成个默认的密码, change yourself into something easy to remember.
#pass = "Kimeismyhero"

pass= ' OpenSSL rand 8-base64 '
If ["!="]
Then pass=$1
Fi

echo "VPN pptpd ${pass} *" >>/etc/ppp/chap-secrets

Iptables-t nat-a postrouting-s 192.168.222.0/24-j SNAT--to-source ' ifconfig | grep ' inet addr: ' | Grep-v ' 127.0.0.1 ' | Cut-d:-f2 | awk ' nr==1 {print $} '
Iptables-a forward-p TCP--syn-s 192.168.222.0/24-j TCPMSS--SET-MSS 1356

#service iptables Save
#chkconfig iptables on
#chkconfig pptpd on
#service iptables Start

Service pptpd Restart

ECHO-E "VPN service is installed, your VPN username are \033[1mvpn\033[0m, VPN password is \033[1m${pass}\033[1m"
Copy the above script to the cloud space, execute it, it should be
The next step is to add a VPN account on the client you need to use VPN (android,window,linux, etc.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.