麦子花开

阿里云服务器配置VPN详解

  • QQ空间
  • 微博

我的操作环境:阿里云香港节点云服务,操作系统:CentOS 6.3 64位

名词解释:pptp是VPN服务器类型之一,PPP是一种数据链路层协议,iptables是IP信息包过滤系统。

【正文】

1 服务器端安装软件

1.1 首先安装ppp,命令:

Bash / Shell
yum install -y ppp iptables

提示Complete! ,安装成功;

1.2安装pptp,由于pptp没有存放在CentOS的源中,所以用yum命令安装返回的是找不到安装包的,需要从下载  pptpd-1.3.4-2.el6.x86_64,安装命令如下:

Bash / Shell
rpm -ivh pptpd-1.3.4-2.el6.x86_64.rpm

2 配置pptp

2.1编辑/etc/pptpd.conf,命令如下

Bash / Shell
vi /etc/pptpd.conf

Bash / Shell
#localip 192.168.0.1
#remoteip 192.168.0.234-238,192.168.0.245

修改成

Bash / Shell
localip 192.168.0.1
remoteip 192.168.0.234-238,192.168.0.245

即将这两行第一个字符“#”去掉,保存退出

(Vi 命令补充:如需查找abc则输入”:/abc”,修改文本输入i,退出修改按esc,保存并退出输入”:/wq”)

2.2编辑/etc/ppp/options.pptpd,命令如下

Bash / Shell
vi /etc/ppp/options.pptpd

Bash / Shell
#ms-dns 10.0.0.1
#ms-dns 10.0.0.2

改成

Bash / Shell
ms-dns 8.8.8.8
ms-dns 8.8.4.4

即将这两行第一个字符“#”去掉,而后修改DNS的IP。

2.3设置使用pptp的用户名和密码

命令:

Bash / Shell
vi /etc/ppp/chap-secrets

打开后只有两行,而且一个账号都没有

Bash / Shell
# Secrets for authentication using CHAP
# client server secret IP addresses

根据您的需要添加账号,每行一个。按照:“用户名 pptpd 密码 ip地址”的格式输入,每一项之间用空格分开。

例如:

Bash / Shell
kuro pptpd 123456 *             (*表示所有IP)

保存并退出。

3、修改内核设置,使其支持转发

命令:

Bash / Shell
vi /etc/sysctl.conf

Bash / Shell
net.ipv4.ip_forward=0
net.ipv4.tcp_syncookies= 1

改成

Bash / Shell
net.ipv4.ip_forward=1
#net.ipv4.tcp_syncookies= 1

保存并退出

执行以下命令使修改后的内核生效

Bash / Shell
sysctl -p

4、添加iptables转发规则

Bash / Shell
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -jMASQUERADE

(注意:由于阿里云是双网卡,内网eth0,外网eth1,请根据自己的服务器实际情况配置)

添加好转发规则后保存一下并重启iptables

Bash / Shell
/etc/init.d/iptables save
/etc/init.d/iptables restart

5、重启pptp服务

Bash / Shell
/etc/init.d/pptpd restart

这里要注意一下,其实此时pptp还没运行起来。所以使用restart重启,会显示Shutting down pptp [FAILED]。还会有一个警告,可以忽略。如不放心可以再用以上命令重启一下pptp就非常顺利的运行了。

6、设置pptp和iptables随系统启动

Bash / Shell
chkconfig pptpd on
chkconfig iptables on

至此,pptp服务端安装结束。

在PC端的“网络和共享中心”,设置新的连接或网络,即可访问VPN。

试了下脸书,原来长这样子:

注:本文转自阿里云论坛。原帖地址:http://bbs.aliyun.com/read/162297.html

最后修改:2024 年 9 月 18 日

休对故人思故国,且将新火试新茶。诗酒趁年华!

查看评论

查看评论
  • 匿名

    回复

    这句详细点呢?在PC端的“网络和共享中心”,设置新的连接或网络,即可访问VPN。


  • 11

    回复

    /etc/pptpd.conf
    我里面怎么没有ip