一、Anylink是什么?
AnyLink 基于 ietf-openconnect 协议开发,并且借鉴了 ocserv 的开发思路,使其可以同时兼容 AnyConnect 客户端.这一点和 Openconnect VPN 是使用相同的协议和客户端.
二、使用步骤
安装教程源自官网
环境:
AnyLink 服务端仅在 CentOS 7、Ubuntu 18.04 测试通过,如需要安装在其他系统,需要服务端支持 tun/tap 功能、ip 设置命令。
软件
AnyLink Release包 官方下载:https://github.com/bjdgyc/anylink
HTTPS 证书,暂时不支持私有证书
首次使用,请在浏览器访问 https://域名:443,浏览器提示安全后,在客户端输入 【域名:443】 即可。
1.官方服务端(这里使用tun模式,推荐)
官方下AnyLink Release 包之后 解压缩到 /usr/local/anylink-deploy 路径下
[root@localhost anylink-deploy]# ls
anylink bridge-init.sh conf LICENSE log systemd
# 生成后台密码, 123456 自行修改
[root@localhost anylink-deploy]#./anylink tool -p 123456
"$2a$10$UQ7C.EoPifDeJh6d8.31TeSPQU7hM/NOM2nixmBucJpAuXDQNqNke"
# 生成jwt密钥
[root@localhost anylink-deploy]#./anylink tool -s
"abcdef.0123456789.abcdef"
修改 conf/server.toml配置文件
这里使用 默认数据库,HTTPS 证书需要事先申请
修改
issuer = “XX公司VPN”
admin_user = “admin”
admin_pass = "$2a10 1010UQ7C.E
jwt_secret = "abcdef
ipv4_master = “eth0”
请根据服务器内网ens160 网卡 替换 eth0,其他可以默认
# 查看网卡
[root@localhost anylink-deploy]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:8e:61:92 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.11/24 brd 10.0.0.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::b628:c58b:6675:9d21/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost anylink-deploy]# vim conf/server.toml
#示例配置信息
#其他配置文件,可以使用绝对路径
#或者相对于 anylink 二进制文件的路径
#数据文件
db_type = "sqlite3"
db_source = "./conf/anylink.db"
#证书文件 使用跟nginx一样的证书即可
cert_file = "./conf/vpn_cert.crt"
cert_key = "./conf/vpn_cert.key"
files_path = "./conf/files"
profile = "./conf/profile.xml"
#日志目录,为空写入标准输出
#log_path = "./log"
log_path = ""
log_level = "debug"
pprof = false
#系统名称
issuer = "XX公司VPN"
#后台管理用户
admin_user = "admin"
#pass 123456
admin_pass = "$2a$10$UQ7C.EoPifDeJh6d8.31TeSPQU7hM/NOM2nixmBucJpAuXDQNqNke"
jwt_secret = "abcdef.0123456789.abcdef"
#服务监听地址
server_addr = ":443"
#开启 DTLS, 默认关闭
server_dtls = false
server_dtls_addr = ":4433"
#后台服务监听地址
admin_addr = ":8800"
#开启tcp proxy protocol协议
proxy_protocol = false
link_mode = "tun"
#客户端分配的ip地址池
ipv4_master = "eth0"
ipv4_cidr = "192.168.10.0/24"
ipv4_gateway = "192.168.10.1"
ipv4_start = "192.168.10.100"
ipv4_end = "192.168.10.200"
#最大客户端数量
max_client = 100
#单个用户同时在线数量
max_user_client = 3
#IP租期(秒)
ip_lease = 1209600
#默认选择的组
default_group = "one"
#客户端失效检测时间(秒) dpd > keepalive
cstp_keepalive = 20
cstp_dpd = 30
mobile_keepalive = 40
mobile_dpd = 50
#设置最大传输单元
mtu = 1460
#session过期时间,用于断线重连,0永不过期
session_timeout = 3600
auth_timeout = 0
audit_interval = -1
服务器设置(tun设置)
开启服务器转发
# [root@localhost anylink-deploy]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
# 执行如下命令
[root@localhost anylink-deploy]# sysctl -w net.ipv4.ip_forward=1
# 查看设置是否生效
[root@localhost anylink-deploy]# cat /proc/sys/net/ipv4/ip_forward
设置 nat 转发规则
[root@localhost anylink-deploy]# systemctl stop firewalld.service
[root@localhost anylink-deploy]# systemctl disable firewalld.service
# 查看网卡
[root@localhost anylink-deploy]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:8e:61:92 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.11/24 brd 10.0.0.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::b628:c58b:6675:9d21/64 scope link noprefixroute
valid_lft forever preferred_lft forever
# 请根据服务器内网ens160 网卡 替换 eth0
[root@localhost anylink-deploy]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j MASQUERADE
# 如果执行第一个命令不生效,可以继续执行下面的命令
# iptables -A FORWARD -i eth0 -s 192.168.10.0/24 -j ACCEPT
# 查看设置是否生效
iptables -nL -t nat
最后 使用 AnyConnect 客户端连接即可
配置开机启动
# 目录结构
[root@localhost anylink-deploy]# ls
anylink bridge-init.sh conf LICENSE log systemd
# anylink 程序目录 /usr/local/anylink-deploy
[root@localhost anylink-deploy]# pwd
/usr/local/anylink-deploy
# 将 systemd/anylink.service 脚本放入:
# centos:
[root@localhost anylink-deploy]# cp systemd/anylink.service /usr/lib/systemd/system/
# ubuntu:
[root@localhost anylink-deploy]# cp systemd/anylink.service /lib/systemd/system/
启动: systemctl start anylink
停止: systemctl stop anylink
开机自启: systemctl enable anylink
评论区