首页 » Linux » 正文

CentOS 7 搭建 pptp 环境

名称版本
操作系统CentOS 7.8.2003
pptpd1.4.0
ppp2.4.5

1、检查系统是否支持pptp

###输出信息要如以下内容才表明支持pptp安装
[root@test-server-7 ~]# modprobe ppp-compress-18 && echo support
support
[root@test-server-7 ~]# LANG=en_US.UTF-8
[root@test-server-7 ~]# cat /dev/net/tun
cat: /dev/net/tun: File descriptor in bad state
[root@test-server-7 ~]# cat /dev/ppp
cat: /dev/ppp: No such device or address

2、安装软件包

rpm -ql epel-release >> /dev/null||yum install epel-release -y
yum install ppp pptpd kernel-devel -y

3、修改相应配置文件

###配置本地隧道网卡地址,及客户端地址池,需要同一网段
###修改/etc/pptpd.conf文件,在文件末尾添加如下内容,或者直接修改对应行
localip 192.168.0.1
remoteip 192.168.0.2-254
###修改后结果如下
[root@test-server-7 ~]# cat /etc/pptpd.conf |grep "^[^#]"
option /etc/ppp/options.pptpd
logwtmp
localip 192.168.0.1
remoteip 192.168.0.2-254

###配置隧道dns,修改/etc/ppp/options.pptpd文件,在文件末尾添加如下内容,或者直接修改对应行
ms-dns 114.114.114.114
###修改后结果如下
[root@test-server-7 ~]# cat /etc/ppp/options.pptpd |grep "^[^#]"
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
proxyarp
lock
nobsdcomp
novj
novjccomp
nologfd
ms-dns 114.114.114.114

###添加pptp vpn账号与密码,格式:用户名 pptpd 密码 ip地址
###修改/etc/ppp/chap-secrets文件,在文件末添加如下内容,多个账号按照类似规则添加即可
test pptpd 123456 *
###其中*表示所有IP地址均可访问,为了安全可以限定IP地址

4、开启系统路由转发

[root@test-server-7 ~]# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
[root@test-server-7 ~]# sysctl -p
net.ipv4.ip_forward = 1

5、查看网卡名,可以执行以下命令直接获取

[root@test-server-7 ~]# [root@test-server-7 ~]# cat `ls /etc/sysconfig/network-scripts/ifcfg-*|grep -v lo`|grep NAME
NAME=ens32

6、添加防火墙规则

firewall-cmd --permanent --zone=public --add-port=1723/tcp
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p gre -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 0 -p gre -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i ppp+ -o ens32 -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i ens32 -o ppp+ -j ACCEPT
firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTROUTING -o ens32 -j MASQUERADE -s 192.168.0.0/24
firewall-cmd --reload

7、启动pptpd

[root@test-server-7 ~]# systemctl enable --now pptpd
Created symlink from /etc/systemd/system/multi-user.target.wants/pptpd.service to /usr/lib/systemd/system/pptpd.service.

[root@test-server-7 ~]# ss -nlp|grep 1723
tcp    LISTEN     0      3         *:1723                  *:*                   users:(("pptpd",pid=17550,fd=6))

###之后就可以在Windows下直接连接了

8、解决部分网页打不开的问题

root@Linux191 ~]# netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0             1500    21034      0      0 0         14942      0      0      0 BMRU
eth0:0           1500      - no statistics available -                        BMRU
lo              65536    23469      0      0 0         23469      0      0      0 LRU
ppp0             1396     4522      0      0 0          4829      0      0      0 MOPRU

### firewalld 防火墙配置工具
###参考链接 https://github.com/firewalld/firewalld/issues/493
firewall-cmd --permanent --direct --add-passthrough ipv4 -t mangle -I FORWARD -p tcp --syn -j TCPMSS --clamp-mss-to-pmtu
firewall-cmd --reload

发表评论