PPTP 服务器
点对点隧道协议 (PPTP) 是一种实现虚拟专用网络的方法。PPTP 使用 TCP 上的控制通道和 GRE 隧道来封装 PPP 数据包。
本条目将向您展示如何在 Arch 中创建 PPTP 服务器。
安装
配置
/usr/share/doc/pptpd
目录中找到。一个典型的配置可能如下所示
/etc/pptpd.conf
# Read man pptpd.conf, see samples in /usr/share/doc/pptpd # and write your pptpd configuration here # pppd options file. By default, /etc/ppp/options is used option /etc/ppp/options.pptpd # Server IP in local network localip 192.168.1.2 # IP address ranges used to assign IPs to new connecting clients # Here we define two ranges for our 192.168.1.* subnet: 234-238 and 245 remoteip 192.168.1.234-238,192.168.1.245
现在创建 pppd 选项文件,在本例中是 /etc/ppp/options.pptpd
/etc/ppp/options.pptpd
# Read man pppd to see the full list of available options # The name of the local system for authentication purposes name pptpd # Refuse PAP, CHAP or MS-CHAP connections but accept connections with # MS-CHAPv2 or MPPE with 128-bit encryption refuse-pap refuse-chap refuse-mschap require-mschap-v2 require-mppe-128 # Add entry to the ARP system table proxyarp # For the serial device to ensure exclusive access to the device lock # Disable BSD-Compress and Van Jacobson TCP/IP header compression nobsdcomp novj novjccomp # Disable file logging nolog # DNS servers for Microsoft Windows clients. Using Google's public servers here ms-dns 8.8.8.8 ms-dns 8.8.4.4
现在创建凭据文件以验证用户身份
/etc/ppp/chap-secrets
# Secrets for authentication using CHAP # client server secret IP addresses user2 pptpd 123 *
现在您可以使用 user2 作为用户名和 123 作为密码进行身份验证。
创建一个 sysctl 配置文件 /etc/sysctl.d/30-ipforward.conf
并启用内核数据包转发,以允许连接的客户端访问您的子网(另请参阅 Internet Share#启用数据包转发)
/etc/sysctl.d/30-ipforward.conf
net.ipv4.ip_forward=1
现在应用更改以使 sysctl 配置生效
# sysctl --system
iptables 防火墙配置
配置您的 iptables 设置以启用 PPTP 客户端的访问
# Accept all packets via ppp* interfaces (for example, ppp0) iptables -A INPUT -i ppp+ -j ACCEPT iptables -A OUTPUT -o ppp+ -j ACCEPT # Accept incoming connections to port 1723 (PPTP) iptables -A INPUT -p tcp --dport 1723 -j ACCEPT # Accept GRE packets iptables -A INPUT -p 47 -j ACCEPT iptables -A OUTPUT -p 47 -j ACCEPT # Enable IP forwarding iptables -F FORWARD iptables -A FORWARD -j ACCEPT # Enable NAT for eth0 on ppp* interfaces iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE iptables -A POSTROUTING -t nat -o ppp+ -j MASQUERADE
现在使用以下命令保存新的 iptables 规则
# iptables-save > /etc/iptables/iptables.rules
要在启动后自动加载 /etc/iptables/iptables.rules,启用 iptables.service
单元。
阅读 Iptables 以获取更多信息。
UFW 防火墙配置
配置您的 ufw 设置以启用 PPTP 客户端的访问。
您必须在 /etc/default/ufw
中更改默认转发策略
/etc/default/ufw
DEFAULT_FORWARD_POLICY="ACCEPT"
现在更改 /etc/ufw/before.rules
,在标头之后和 *filter 行之前添加以下代码
/etc/ufw/before.rules
# nat Table rules *nat :POSTROUTING ACCEPT [0:0] # Allow traffic from clients to eth0 -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE # commit to apply changes COMMIT
在 /etc/ufw/before.rules
中允许 GRE 数据包(协议 47),找到包含以下内容的行:# drop INVALID packets
并添加规则
/etc/ufw/before.rules
# drop INVALID packets (logs these in loglevel medium and higher) -A ufw-before-input -p 47 -i $iface -j ACCEPT -A ufw-before-input -m conntrack --ctstate INVALID -j ufw-logging-deny -A ufw-before-input -m conntrack --ctstate INVALID -j DROP
打开 pptp 端口 1723
ufw allow 1723
重启 ufw 以确保生效
ufw disable ufw enable
启动服务器
现在您可以使用 pptpd.service
启动和启用 您的 PPTP 服务器。
故障排除
与任何服务一样,请参阅 Systemd#故障排除 以调查错误。
客户端错误 619
在 /etc/pptpd.conf
中搜索 logwtmp
选项并注释掉它。启用此选项后,wtmp 将用于记录客户端连接和断开连接。
#logwtmp
pptpd[xxxxx]: Long config file line ignored
在 /etc/pptpd.conf
的末尾添加一个空行。 [1]
ppp0: ppp: compressor dropped pkt
如果在客户端连接到服务器时出现此错误,请将以下脚本添加到 /etc/ppp/ip-up.d/mppefixmtu.sh
#!/bin/sh CURRENT_MTU="`ip link show $1 | grep -Po '(?<=mtu )([0-9]+)'`" FIXED_MTU="`expr $CURRENT_MTU + 4`" ip link set $1 mtu $FIXED_MTU
使脚本 可执行。
另请参阅:[2]