PPTP (Point to Point Tunneling Protocol) 点对点隧道协议,与PPPoE, L2TP 均属于 PPP(Point to Point Protocol) 点对点协议。这篇来记录下PPTP server的安装和配置过程。

install DHCP server

除了PPPoE外,PPTP 与 L2TP 都无法直接给client分配IP,需要使用dhcp server分配。所以在安装PPTP的同时,也要保证DHCP server也已安装。具体方法参考 Setup dhcpd/dhcpdv6 server.

需要注意的是,在Ubuntu 20.10 版本中,网卡的静态IP管理模式与以往有所不同。在以往版本中,是修改 /etc/network/interfaces 文件,但是在最新Ubuntu确不一样,最新版提出了一个叫 netplan 的概念,修改的文件是:

  • /etc/netplan/01-network-manager-all.yaml

yaml 文件存储配置信息,我们将配置dhcp 对应接口的静态IP为 10.0.0.138/24, 对应配置文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
ethernets:
enp0s8:
dhcp4: no
dhcp6: no
addresses: [10.0.0.138/24]
gateway4: 10.0.0.138
nameservers:
addresses: [10.0.0.138]

其中 enp0s8 为 interface 名称,从 ifconfig 可以获得。让该配置生效的方式为:

1
sudo netplan apply

重新执行 ifconfig 查看已生效的静态IP.

install PPTP server

PPTP Server 的安装其实很简单,就一个指令。

1
sudo apt install pptpd

对 pptpd 的操作与大多数服务一样。

1
sudo service pptpd [force-reload|restart|start|status|stop]

主要是配置稍微复杂些,某些配置与PPPoE, L2TP是共用的,比如密码信息等。

common config

PPPoE, PPTP, L2TP 共用以下文件

  • /etc/ppp/chap-secrets
  • /etc/ppp/options

其中 /etc/ppp/chap-secrets 用于存储密码信息。

1
2
3
# Secrets for authentication using CHAP
# client server secret IP addresses
"test123" * "123456" *

以上 "test123" 为PPTP拨号时的用户名, "123456" 为拨号密码。可以添加多行,代表多个账户。

/etc/ppp/options也是共用的,是大部分常用配置的基地。我们通常只需要修改以下部分参数。

1
2
3
4
5
6
7
8
9
10
11
12
13
# Require the peer to authenticate itself before allowing network
auth

# Require the peer to authenticate itself using CHAP
+chap

# Send an LCP echo-request frame to the peer every n seconds
lcp-echo-interval 30
# Retry to send LCP echo -request max n times if not receive echo-response
lcp-echo-failure 4

# Disable the IPXCP and IPX protocols
noipx

以上配置主要是使能密码认证,并启用echo包监听client状态,在无消息响应情况下自动断开连接。

pptpd config

针对pptp server也有对应的特定配置文件,

  • /etc/ppp/pptpd-options
  • /etc/pptpd.conf

/etc/ppp/pptpd-options 文件内容较多,但基本不需要修改,只需要添加dns信息即可

1
ms-dns 10.0.0.138

/etc/pptpd.conf 文件是配置IP网段的,pptp拨号成功后,会在特定interface (如ppp0) 分配IP,通常是192.168.*网段。

配置该文件时,只需要在文件末尾添加以下信息即可:

1
2
localip 192.168.0.1
remoteip 192.168.0.10-200

localip 代表本地IP,用于与 remote client 通信,remoteip 自然就是需要拨号上网的client对应ip了。

到此就基本配置完成了。

install DNS server

想要 PPTP server 完全正常工作,除了dhcp server和以上配置外,还少不了 DNS server 提供 DNS 解析服务。

安装同样很简单,一步到位。

1
sudo apt install dnsmasq

操作与 pptpd 类似,

1
sudo service dnsmasq [dump-stats|force-reload|restart|start|status|stop]

config dnsmasq

dns server 的配置文件主要有:

  1. /etc/dnsmasq.conf
  2. /etc/default/dnsmasq
  3. /etc/dnsmasq/dnsmasq.resolv
  4. /etc/dnsmasq/dnsmasq.hosts

第 3,4 个是自己手动创建的,也不是必须的,但是创建后更方便管理。

以上配置文件中,/etc/dnsmasq.conf是基础,主要用于指定 resolvhosts 文件, 以及监听地址。

1
2
3
resolv-file=/etc/dnsmasq/dnsmasq.resolv
listen-address=127.0.0.1, 10.0.0.138
addn-hosts=/etc/dnsmasq/dnsmasq.hosts

/etc/dnsmasq/dnsmasq.resolv用于存储 DNS server IP

1
2
nameserver 127.0.0.1
nameserver 10.0.0.138

/etc/dnsmasq/dnsmasq.hosts用于存储hosts信息,与Windows的hosts是一样的,Ubuntu默认路径是 /etc/hosts.

1
2
10.0.0.138 netgear.com
1.2.3.4 baidu.com

start dnsmasq

上面讲dns配置好了,使用 sudo service dnsmasq start 可以启动服务。

但是我在这一步出现了问题,提示53端口已经被占用。解决方案如下:

1
2
sudo systemctl stop systemd-resolved.service
sudo systemctl disable systemd-resolved.service

config sysctl.conf

ubuntu 系统作为server,还需要开启IP转发功能,所以需要修改以下文件:

  • /etc/sysctl.conf
1
net.ipv4.ip_forward=1

然后使用 sudo sysctl -p 使其生效。

summary

总结下,在Ubuntu安装PPTP server,共安装了

  • dhcp server
  • pptp server
  • dns server

此外,添加了对应的接口信息,静态IP,分配IP网段,启用IP转发功能。不同的操作系统安装可能略有不同,但流程大同小异。

如果在使用多个虚拟网卡的虚拟机中使用,可能还需要添加默认路由。

reference