安装必要的包

1
$ sudo apt install pptp-linux

查看一下命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ pptpsetup --help
pptpsetup --create <TUNNEL> --server <SERVER> [--domain <DOMAIN>]
--username <USERNAME> [--password <PASSWORD>]
[--encrypt] [--start]

pptpsetup --delete <TUNNEL>
Options:
* the name you wish to use to refer to the tunnel (you choose it),
* the IP address or host name of the server,
* the authentication domain name (optional),
* the username you are to use,
* the password you are to use,
* whether encryption is required,
* whether to start the connection after configuration.

开始连接

1
2
3
4
5
6
7
$ sudo pptpsetup --create pptpvpn --server servername --username name --password pass --encrypt --start
Using interface ppp0
Connect: ppp0 <--> /dev/pts/2
CHAP authentication succeeded
MPPE 128-bit stateless compression enabled
local IP address 192.168.253.225
remote IP address 192.168.253.2

此时VPN虽然已经连接,但是并没有使用,可以使用traceroute看看第一跳是不是remote IP address。
如果不是,需要做接下来的工作。

配置路由

在/etc/ppp/ip-up.d/下新建一个文件,并输入

1
2
3
#!/bin/bash
/sbin/ip route del default #删除默认路由
/sbin/ip route add default dev ppp0 #使用pptp,可以用ifconfig看到dev的name,可能会有不同

在/etc/ppp/ip-down.d/下新建一个文件,并输入

1
2
#!/bin/bash
/sbin/ip route add default via 192.168.1.1 #192.168.1.1应该设置成在不开启pptp的情况下,traceroute的第一跳地址,一般是路由器地址

关闭PPTP链接

1
2
3
4
$ sudo poff pptpvpn
# 再打开
$ sudo pon pptpvpn
# 使用traceroute应该就能看到第一跳变为建立VPN时显示的remote IP了