Centos搭建VPN PPTP

  1. 安装ppp协议, iptables防火墙, pptpd服务器
    yum install ppp pptpd iptables -y
  2. 配置pptp
    vi /etc/pptpd.conf 去掉前面#号

     #localip 192.168.0.1
     #remoteip 192.168.0.234-238,192.168.0.245
  3. 配置ppp DNS
    vi /etc/ppp/options.pptpd 去掉前面#号,修改为8.8.8.8 8.8.4.4

     #ms-dns 10.0.0.1
     #ms-dns 10.0.0.2
    
  4. 设置pptp的用户名和密码
    vi /etc/ppp/chap-secrets

     # 用户    服务器    密码    IP地址
     test    pptpd    test    *
     # 注: pptpd为服务名称, 可以在/etc/ppp/options.pptpd文件中修改(第18行)
    
  5. 修改内核设置,使其支持转发
    vi /etc/sysctl.conf.

     # 把0改成1
     net.ipv4.ip_forward=0 
    

注意, 腾讯云服务器, /etc/sysctl.conf此配置文件为空, 文件在/etc/sysctl.conf.first中

     1). 要么修改sysctl.conf.first, 然后 重新启动系统
     2). 要么把文件内容复制至/etc/sysctl.conf文件中,  然后运行 sysctl -p 使内核生效
  1. 让内核生效(根据上一步是否需要)
    sysctl -p
  2. 设置iptables转发规则(无公网接口,以为不可以, 亲测可以)
    # 确保设置的网卡接口为公网eth0, 192.168.0.0/24 根据第二步来. -s 192.168.0.0/24也可以省略.
    # iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j MASQUERADE
    或# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

    # 以防万一最好添加下21, 22, 80, 1723(pptp端口)常用端口
    # iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
    # iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
    # iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    # iptables -A INPUT -p tcp -m tcp --dport 1723 -j ACCEPT

    # 保存, 重启防火墙
    # /etc/init.d/iptables save
    # /etc/init.d/iptables restart

  3. 重启pptp服务
    /etc/init.d/pptpd restart
  4. 设置pptp, iptables自启
    chkconfig pptpd on
    chkconfig iptables on
  5. 如果是拨号能拨上, 不能打开网页, 有可能是 iptables, sysctl.conf, MTU 的问题
    # MTU 默认为1500
    # /sbin/iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1300
  6. 检测端口
    # netstat -tan |grep 1723

     tcp        0      0 0.0.0.0:1723                0.0.0.0:*                   LISTEN