centos pptp搭建,windows网关配置

本文详细介绍了如何在Linux系统中安装、配置并运行PPTP服务器,包括设置iptables防火墙、限速以及解决常见问题。同时,提供了Windows客户端的网关设置和自动化脚本,确保远程连接和网络访问的顺畅。
摘要由CSDN通过智能技术生成

目录

一、安装

二、配置

三、运行 

四、防火墙

五、限速

六、常见问题

七、windows网关设置


一、安装

yum install ppp pptpd -y
#需要防火墙转发,如不想使用iptables可使用其他防火墙 
yum install iptables iptables-services

二、配置

vim /etc/pptpd.conf

debug #打开日志 /var/log/message
ppp /usr/sbin/pppd
option /etc/ppp/options.pptpd
localip 192.168.0.1
remoteip 192.168.1.234-238,192.168.2.245

vim /etc/ppp/options.pptpd
ms-dns 114.114.114.114
ms-dns 8.8.8.8

vim /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
# 用户名 协议名称(可为*) 密码 LAN地址(*为自动分配)
'test'  pptpd   "123456" *

vim /etc/sysctl.conf
#支持网络转发
net.ipv4.ip_forward=1

#指令
sysctl -p

三、运行 

#运行
systemctl start iptables
systemctl start pptpd

#开机启动
systemctl enable iptables
systemctl enable pptpd

#此时已全部安装运行完成,添加防火墙nat转换后即可进行pptp拨号
/sbin/iptables -t nat -I POSTROUTING -s 192.168.31.0/24 -o em1 -j MASQUERADE

四、防火墙

#pptpd需要打开 gre协议,1723、47端口 以及nat地址转换
#mtu值正常情况是 1356 也可能是1472
/sbin/iptables -I INPUT -p gre -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 1723 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 47 -j ACCEPT
/sbin/iptables -t nat -I POSTROUTING -s 192.168.0.0/24 -o em1 -j MASQUERADE
/sbin/iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356

五、限速

# 通过tc进行限速 /etc/ppp/ip-up 不存在的话直接创建一个
yum install /sbin/tc
modprobe sch_htb
echo "modprobe sch_htb" >> /etc/rc.local
vim /etc/ppp/ip-up

echo ppp connect Start_Time: `date -d today +%F_%T` >> /var/log/message
down=80kbps
upload=80kbps
iprange=192.168.32.0/24
#down
/sbin/tc qdisc del dev $1 root
/sbin/tc qdisc add dev $1 root handle 2:0 htb
/sbin/tc class add dev $1 parent 2:1 classid 2:10 htb rate $down
/sbin/tc class add dev $1 parent 2:2 classid 2:11 htb rate 1024kbps
/sbin/tc qdisc add dev $1 parent 2:10 handle 1: sfq perturb 1
/sbin/tc filter add dev $1 protocol ip parent 2:0 u32 match ip dst \
         $iprange flowid 2:10
#upload
/sbin/tc qdisc add dev $1 handle ffff: ingress
/sbin/tc filter add dev $1 parent ffff: protocol ip u32 match ip dst \
         $iprange police rate $upload burst 100k drop flowid 2:11

六、常见问题

# LCP: timeout sending Config-Requests
# GRE: read(fd=6,buffer=564b0e55e480,len=8196) from PTY failed: status = -1 error = Input/output error, usually caused by unexpected termination of pppd, check option syntax and pppd logs
# CTRL: PTY read or GRE write failed

此为网络转发gre问题,确认gre 端口是否打开,若服务器gre正常,则检查客户端路由器以及上层节点是否打开了gre


# pptpd可以连接但是无法访问https

检查mtu值,pptpd默认mtu是1396,去除tcp协议包头40个字节,iptables设置mss为1356
其他mtu值需要自行尝试了

七、windows网关设置

关闭pptp适配器的【在远程网络上使用默认网关】

 手动配置windows的route路由表

#管理员权限运行
# route -p add [target_ip] mask [net_mask] [pptp_lan]
# -p 永久新增路由 没有该参数时,重启电脑会失效 建议不加该参数,每次连接pptp时手动运行
route add 222.186.61.212 mask 255.255.255.255 192.168.31.240

bat自动化脚本

rem 批量新增route路由bat脚本
@echo off
chcp 65001
net.exe session 1>NUL 2>NUL || (
	echo 请以管理员权限运行
    goto end
)

for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr "192.168.31"') do (
	set pptp_lan=%%i
	goto out
)
echo 未查询到pptp的lanip
goto end

:: 标签
:out
echo Get pptp_lan IP: %pptp_lan%

rem route -p add [target_ip] mask [net_mask] [pptp_lan]
rem -p 永久新增路由 没有该参数时,重启电脑会失效 建议不加该参数,每次连接pptp时手动运行
rem route add ip mask 255.255.255.255 %pptp_lan%

route add 180.101.49.11 mask 255.255.255.255 %pptp_lan%

echo route %pptp_lan% list
route print | findstr %pptp_lan%

pause
exit 0

:end
echo end
pause
rem 批量删除route路由脚本
@echo off
chcp 65001
net.exe session 1>NUL 2>NUL || (
	echo 请以管理员权限运行
    goto end
)

for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr "192.168.31"') do (
	set pptp_lan=%%i
	goto out
)
echo 未查询到pptp的lanip
goto end

:: 标签
:out
echo Get pptp_lan IP: %pptp_lan%

rem route -p add [target_ip] mask [net_mask] [pptp_lan]
rem -p 永久新增路由 没有该参数时,重启电脑会失效 建议不加该参数,每次连接pptp时手动运行
rem route add 222.186.61.212 mask 255.255.255.255 %pptp_lan%

route delete xx.xx.xx.xx

echo route %pptp_lan% list
route print | findstr %pptp_lan%

pause
exit 0

:end
echo end
pause

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值