由于学校的校园网络没有提供公网/教育网的IP地址,想要从校外(比如家中)访问校园网络必须通过学校的RVPN。而学校的RVPN是由深信服提供的SSL VPN,虽然它的客户端在Windows和Mac OS下运行尚可,但却没有提供Linux客户端,并且无论是桌面版本还是移动版本的客户端都或多或少存在一些bug,比如部分站点无法访问、部分端口或服务被禁用之类的,都为使用带来不少麻烦。为了解决这一情况,可以使用虚拟专用网络来解决。
由于只是想要连接家和学校,暂时并不需要IKEv2和IPSec之类的东西。简单地说,有L2TP本体就行了,PPTP也可以,而这都可以在OpenWRT上非常简单地实现。
安装xl2tpd
1 2 |
opkg update opkg install xl2tpd |
配置L2TP服务端vi /etc/xl2tpd/xl2tpd.conf
在末尾加上
1 2 3 4 5 6 7 8 |
[lns default] ip range = 192.168.244.100-192.168.244.199 local ip = 192.168.244.1 refuse pap = no require authentication = yes ppp debug = yes pppoptfile = /etc/ppp/options.xl2tpd length bit = yes |
配置PPPvi /etc/ppp/options.xl2tpd
1 2 3 4 5 6 7 8 9 10 11 12 |
ms-dns 8.8.8.8 ms-dns 8.8.4.4 auth mtu 1200 mru 1000 crtscts hide-password modem name l2tpd proxyarp lcp-echo-interval 30 lcp-echo-failure 4 |
配置拨号用户信息vi /etc/ppp/chat-secrets
1 2 3 |
# Secrets for authentication using CHAP # client server secret IP addresses 用户名 * 密码 * |
配置开启数据转发(一般情况下已经开启)vi /etc/sysctl.conf
1 2 3 |
net.ipv4.ip_forward=1 :wq sysctl -p |
添加NAT规则
1 |
iptables -t nat -A POSTROUTING -j MASQUERADE |
服务端配置到此结束,接下来只需要配置客户端即可,由于实际上是将服务端放置在有公网IP的家中,客户端放在校园网络中,而实际的访问需求是通过这个L2TP通道访问校园网络,因此在客户端连接配置的时候不要设置L2TP Client的默认网关(或者把端口的跃点数调到足够大),在服务端上添加一条路由记录
1 2 |
Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.0 客户端L2TP IP 255.0.0.0 UG 0 0 0 ppp[d+] |
完成!
Comments