可以使用pptpd来使用vpn服务。

1
sudo yum install pptpd

修改配置文件

vim /etc/pptpd.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
##配置文件路径
option /etc/ppp/options.pptpd 

##日志
logwtmp 

## 填写vpn主机的外网地址。(我的是在内网,做了nat映射。所以本机ip就等于公网地址)
localip 192.168.12.57    

## 自己给一个×××远程主机的IP地址范围。
remoteip 192.168.80.1-50 

vim /etc/ppp/options.pptpd

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
name pptpd

refuse-pap

refuse-chap

refuse-mschap

require-mschap-v2

require-mppe-128

proxyarp

lock

nobsdcomp

novj

novjccomp

nologfd

idle 2592000

ms-dns 8.8.8.8   ##修改远程主机DNS地址

ms-dns 8.8.4.4   ##备用地址

vim /etc/ppp/chap-secrets

1
2
3
4
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
liwenbo         *       123456                 *
hanzhu          *       123456                 *

设置内核转发,vim /etc/sysctl.conf

1
net.ipv4.ip_forward = 1

修改完成后使用sysctl -p命令进行强制刷新。

日志查看

可以使用 tail -f /var/log/messages 命令来查看连接的日志信息,例如下面这样的

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Aug 31 15:34:02 VM_0_12_centos pptpd[15537]: GRE: read(fd=6,buffer=560525502480,len=8196) from PTY failed: status = -1 error = Input/output error, usually caused by unexpected termination of pppd, check option syntax and pppd logs
Aug 31 15:34:02 VM_0_12_centos pptpd[15537]: CTRL: PTY read or GRE write failed (pty,gre)=(6,7)
Aug 31 15:34:02 VM_0_12_centos pptpd[15537]: CTRL: Client xxx.xxx.xxx.xxx control connection finished
Aug 31 15:34:05 VM_0_12_centos pptpd[15582]: CTRL: Client xxx.xxx.xxx.xxx control connection started
Aug 31 15:34:06 VM_0_12_centos pptpd[15582]: CTRL: Starting call (launching pppd, opening GRE)
Aug 31 15:34:06 VM_0_12_centos pppd[15584]: Plugin /usr/lib64/pptpd/pptpd-logwtmp.so loaded.
Aug 31 15:34:06 VM_0_12_centos pppd[15584]: pppd 2.4.5 started by root, uid 0
Aug 31 15:34:06 VM_0_12_centos pppd[15584]: Using interface ppp0
Aug 31 15:34:06 VM_0_12_centos pppd[15584]: Connect: ppp0 <--> /dev/pts/1
Aug 31 15:34:06 VM_0_12_centos pppd[15584]: peer from calling number 220.113.124.135 authorized
Aug 31 15:34:09 VM_0_12_centos pppd[15584]: MPPE required but peer refused
Aug 31 15:34:10 VM_0_12_centos pppd[15584]: Connection terminated.
Aug 31 15:34:10 VM_0_12_centos pppd[15584]: Connect time 0.1 minutes.
Aug 31 15:34:10 VM_0_12_centos pppd[15584]: Sent 28 bytes, received 70 bytes.
Aug 31 15:34:10 VM_0_12_centos pppd[15584]: Exit.
Aug 31 15:34:10 VM_0_12_centos pptpd[15582]: GRE: read(fd=6,buffer=557a834dc480,len=8196) from PTY failed: status = -1 error = Input/output error, usually caused by unexpected termination of pppd, check option syntax and pppd logs
Aug 31 15:34:10 VM_0_12_centos pptpd[15582]: CTRL: PTY read or GRE write failed (pty,gre)=(6,7)
Aug 31 15:34:10 VM_0_12_centos pptpd[15582]: CTRL: Client xxx.xxx.xxx.xxx control connection finished
Aug 31 15:34:13 VM_0_12_centos pptpd[15607]: CTRL: Client xxx.xxx.xxx.xxx control connection started
Aug 31 15:34:14 VM_0_12_centos pptpd[15607]: CTRL: Starting call (launching pppd, opening GRE)
Aug 31 15:34:14 VM_0_12_centos pppd[15608]: Plugin /usr/lib64/pptpd/pptpd-logwtmp.so loaded.
Aug 31 15:34:14 VM_0_12_centos pppd[15608]: pppd 2.4.5 started by root, uid 0
Aug 31 15:34:14 VM_0_12_centos pppd[15608]: Using interface ppp0