0%

Amazon EC2配置VPN服务

本文介绍如何在Amazon ec2的Instance中建立vpn服务,我的Instance是Amazon Linux AMI的64位系统。本文是基于你已经有一个AWS账号并运行了Instance并已经会用SSH远程登陆进去运行命令。如果前面步骤有疑问请自行google。
我是在前人的基础上实现的,参考文章是:

Amazon EC2上一键安装配置PPTP VPN服务
Automaticlly install pptpd on Amazon EC2 Amazon Linux

毕竟是2010年的文章,按照步骤做了一次,毫无疑问是失败的。
显示错误提示如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
error: open of ../rpmbuild/RPMS/i386/pptpd-1.3.4-1.amzn1.i386.rpm failed: No such file or directory
sed: can't read /etc/pptpd.conf: No such file or directory
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
error reading information on service pptpd: No such file or directory
pptpd: unrecognized service

error: File not found by glob: ../rpmbuild/RPMS/i386/pptpd-1.3.4-1.*.i386.rpm

看了文章后面的评论发现问题在于64位要使用不同的RPM,但是还是出现上一行的error: File not found by globe的提示,我就觉得应该是运行脚步路径出了问题。打开脚步文件,发现运行完rpmbuild --rebuild pptpd-1.3.4-1.amzn1.src.rpm,终端的路径会进入

1
2
3
+ cd /root/rpmbuild/BUILD
+ rm -rf pptpd-1.3.4
+ exit 0

这当然不能运行
rpm -i ../rpmbuild/RPMS/i386/pptpd-1.3.4-1.*.i386.rpm
而且路径错了,文件名也错了,应该改为
rpm -i ~/rpmbuild/RPMS/x86_64/pptpd-1.3.4-1.amzn1.x86_64.rpm
但是运行上一行的命令是可以找到文件,不过还提示
warning: /etc/pptpd.conf created as /etc/pptpd.conf.rpmnew
所以脚本文件要加一行
cp /etc/pptpd.conf.rpmnew /etc/pptpd.conf


这是分割线,如果你比较懒,以上的全部都是废话,配置VPN只需要两行命令,以下是我已经修改好的脚本。 进入EC2系统终端后,输入下面的代码:

1
2
wget https://raw.github.com/kesuki/Amazon-linux-ami/master/pptpd.sh
sudo sh pptpd.sh

然后安装配置完成后会高亮提示vpn用户名和密码,如果出现以下两个OK,表明你已经成功了:

1
2
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
Starting pptpd: [ OK ]

搞定,收工。