fedora 搭建pptp vpn server

来源:互联网 发布:为什么贫穷 知乎 编辑:程序博客网 时间:2024/05/16 01:56
1 首先去sourceforge上下载pptpd的源码
http://sourceforge.net/projects/poptop/files/?source=navbar

2 对源码进行编译
./configure && make && make install

3 将源码目录下的配置文件模版拷贝到系统指定位置

3.1 拷贝samples/chap-secrets和samples/options.pptp到/etc/ppp目录下
cp ./chap-secrets ./options.pptp /etc/ppp

3.2 拷贝samples/pptpd.conf到/etc目录下
cp ./pptpd.conf /etc

4 对配置文件进行修改

4.1 修改/etc/pptpd.conf
    将pptpd.conf最下面的localip和remoteip的配置修改为如下,
localip 222.201.139.156 # 本地机器物理IP地址,可以通过ifconfig获取
remoteip 192.168.0.234-238,192.168.0.245 # 分配给远程连接过来的机器分配的IP地址空间
    

4.2 修改/etc/ppp/chap-secrets,是远程连接时的用户名和密码,有了配置模版,一看就明白如何添加
# Secrets for authentication using CHAP
# client        server  secret          IP addresses
#username       pptpd   password        *
ethanshan pptpd 111111 *

4.3 修改/etc/ppp/options.pptpd
    在Netwok and Routing这个配置项的下面找到ms-dns这个选项,默认是被注释掉的,将其修改为如下配置,
ms-dns 222.201.130.30
ms-dns 222.201.130.33
    ms-dns后面的domain name system的IP地址可以通过查看/etc/resolv.conf文件获取。

4.4 修改/etc/sysctl.conf中packet forward配置项
    打开文件找到net.ipv4.ip_forward修改为=1
    
# Kernel sysctl configuration file
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
# Default this conf is 0, I use pptpd, so edit it to 1
net.ipv4.ip_forward = 1

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1

# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
    然后运行如下命令使其立即生效,

sysctl -p

4.5 修改/etc/ppp/ip-up配置文件中的mtu值
    打开配置文件,在最后的exit命令前加如下命令
ifconfig $1 mtu 1400


5 如果开启了iptables防火墙,需要对其添加pptpd的配置,执行如下几条命令
iptables -A INPUT -i eth0 -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -i eth0 -p gre -j ACCEPT
iptables -A FORWARD -i ppp+ -o p3p1 -j ACCEPT
iptables -A FORWARD -i eth0 -o ppp+ -j ACCEPT
iptables -A OUTPUT -p tcp --dport 1723 -j ACCEPT
iptables -A OUTPUT -p gre -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

6 运行pptpd,通过如下命令使pptpd在前台运行
pptpd -f

7 pptpd运行错误
    当Client连接是可能pptpd输出pptpd-logwtmp.so无法找到,解决方法就是在编译pptpd的目录下的plugin目录下的对应.so文件复制到/usr/lib/pptpd目录下。
    这样可能会提示版本不对,可以修改plugin目录下的patch.level.h文件,将其中的version改为错误输出中寻找的后,再make以下,将新生成的.so文件覆盖/usr/lib/pptpd目录下的文件,这样重新运行pptpd就没有问题了。

8 Windows 链接配置
    我配置时候,链接总是失败,通过在网上查阅,发现需要将Data encryption这个选项设置为Optional encryption就可以了。



9 限制账号连接数量

linux系统上提供的pptp vpn服务默认采用的是chap认证方式。这种认证方式比较简单,只要用户名和密码正确即可进行连接,不能对一个账户的连接数目,流量,速度进行限制。如 果要实现这众多的限制,可以采用freeradius认证方式。但是我个人感觉配置freeradius可不是一般的繁琐啊,花了某个晚上的几个小时后我 最终放弃了…

不过如果仅仅只是对同一个账户的连接数目进行限制,倒是有一个简单的办法。这里提供的方法改自某个英文网站。当用中文搜索不到自己想要的东西时,用英文搜下说不定能有新发现呢。

实现方法很简单。只要在/etc/ppp文件夹下面建立一个名为auth-up的文件。在里面写入如下内容即可:

Click to closeBASH CODE
#!/bin/sh# get the username/ppp line number from the parameters  REALDEVICE=$1  USER=$2# create the directory to keep pid files per user  mkdir -p /var/run/pptpd-users# if there is a session already for this user, terminate the old one  if [ -f /var/run/pptpd-users/$USER ]; then    kill -HUP `cat /var/run/pptpd-users/$USER`  fi# copy the pid file of current user to /var/run/pptpd-users  cp "/var/run/$REALDEVICE.pid" /var/run/pptpd-users/$USER

这样只要一个帐号进行了连接,就在/var/run/pptpd-users目录下记录下来了。而一旦这个帐号在他处再次登录,旧有的连接就被杀掉了。所以后面的连接具有优先权。


有道笔记连接: http://note.youdao.com/share/?id=fc97d357e5852a6f15cefb14a99f06d1&type=note
原创粉丝点击