Ubuntu官方帮助文档:
pptp: https://help.ubuntu.com/community/PPTPServer
l2tp: https://help.ubuntu.com/community/L2TPServer
官方文档已经写的很详细了我这里再补充下
搭建pptp:
apt install pptpd (安装pptp服务端)
在 /etc/pptpd.conf 中添加如下配置
localip 192.168.4.51 (客户端登录后服务端会自动创建一个虚拟网卡)
remoteip 192.168.4.201-210 (分配给客户端的ip池)


在 /etc/ppp/pptpd-options 中添加如下配置
ms-dns 114.114.114.114
ms-dns 8.8.8.8 (顾名思义, 这是在配置dns, 如果不配置也能登录但是网络异常)

在 /etc/ppp/chap-secrets 中添加如下配置
# Secrets for authentication using CHAP
# client server secret IP addresses
yzh * yzhYYDS *

systemctl restart pptpd (重启pptp服务端)
查看 /etc/sysctl.conf 中是否有配置 net.ipv4.ip_forward = 1 .我的自动配置了, 安装docker自动配置的???
cat /etc/sysctl.conf | grep net.ipv4.ip_forward
如果没有就添加, 添加完成后执行下
sysctl -p

然后就可以用手机或电脑进行登录了, 但是不一定有网.
此时, 如果"remoteip 192.168.4.201-210"中配置的ip段和机顶盒的ip在同一个网段有网.
如果不是需要通过ipconfig查看自己网卡的名称,然后输入如下命令:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE (eth0 为当前网络所用的网卡名称)

连接pptp服务端:
pc端:




此时是自动选择协议的状态可能存在无法连接成功的情况, 点击跳过. 然后进入网络连接>属性>安全>修改类型为pptp既可以.


手机端:

搭建l2tp:
apt install xl2tpd (安装l2tp服务端)
在 /etc/xl2tpd/xl2tpd.conf 中添加如下配置:
[global]
ipsec saref = no
[lns default]
local ip = 192.168.4.52
ip range = 192.168.4.211-192.168.4.220
require chap = yes
refuse pap = yes
require authentication = yes
;pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes
rx bps = 10000000000
tx bps = 10000000000

在 /etc/ppp/chap-secrets 中配置账号和密码:(同pptp, 如果pptp配置了跳过)
# Secrets for authentication using CHAP
# client server secret IP addresses
yzh * yzhYYDS *
查看 /etc/sysctl.conf 中是否有配置 net.ipv4.ip_forward = 1 (同pptp, 如果pptp配置了跳过)
cat /etc/sysctl.conf | grep net.ipv4.ip_forward
如果没有就添加, 添加完成后执行下
sysctl -p
systemctl restart xl2tpd (重启xl2tp服务端)
此时, 无论"ip range = 192.168.4.211-192.168.4.220"中配置的啥一定都没有网(与pptp的不同之处).需要通过ipconfig查看自己网卡的名称,然后输入如下命令:(同pptp, 如果pptp配置了跳过)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE (eth0 为当前网络所用的网卡名称)
连接pptp服务端:
pc端:
同pptp配置, 不同之处: 网络连接>属性>安全:
- 修改类型为l2tp
- 数据加密选择可选加密

手机端:
l2tp模式下无法截图, 选择L2TP即可,上面配置的ipsec saref = no. l2tp密匙不用填,只填个服务端ip和名称(随便写)就行了

注意:
- pptp服务端监听的是tcp 1723端口, l2tp服务端监听的是udp 1701端口.
- pptp和l2tp都只支持ipv4, 所以在使用时需要一个外网ipv4的ip, 但是一般人都没有.好在有外网ipv6的ip, 下一篇文章将分享利用ipv6实现异地登录l2tp.
网友评论