您当前的位置:首页 > 学海无涯 > 应用搭建网站首页应用搭建
Ocserv搭建
发布时间:2021-01-13作者:♂逸風★淩軒
二、常用命令:
创建用户
ocpasswd -c /etc/ocserv/ocpasswd user
删除用户\
ocpasswd -c /etc/ocserv/ocpasswd -d user
启动服务\
service ocserv start
关闭服务器
service ocserv stop
重启服务
service ocserv restart
重加载非引导性配置
occtl reload
查看用户连接
occtl show users
json形式返回
occtl --json show users
查看帮助
occtl -h
三、使用AD域登录VPN:
加入域服务器/离开域服务器
yum install realmd sssd oddjob oddjob-mkhomedir samba-common-tools -y
加入域:realm join 52aiops.cn 离开域:realm leave 52aiops.cn
启用认证
修改认证账户限制
vim /etc/sssd/sssd.conf
参考配置
[sssd] domains = 52aiops.cn config_file_version = 2 services = nss, pam [domain/52aiops.cn] ad_domain = 52aiops.cn krb5_realm = 52AIOPS.CN realmd_tags = manages-system joined-with-samba cache_credentials = True id_provider = ad krb5_store_password_if_offline = True default_shell = /bin/bash ldap_id_mapping = True #用户不需用带域名就可以被识别 use_fully_qualified_names = False fallback_homedir = /home/%u@%d #允许Active Directory 用户模式 #access_provider = ad #限制用户 access_provider = simple #允许的组 simple_allow_groups = vpn-group #允许的用户 #simple_allow_users = #禁止的用户 #simple_deny_users = #禁止的组 #simple_deny_groups =
重启生效
systemctl enable sssd && systemctl restart sssd
四、客户端:
windows:OpenConnect-GUI VPN client
下载地址:
https://gitlab.com/openconnect/openconnect-gui/-/releases
安卓:AnyConnect
下载地址:
https://software.cisco.com/download/home/286281283/type/282364313/release/4.10.01075?i=!pp
IOS:AnyConnect
AppStore直接搜索Cisco AnyConnect
linux:
yum install openconnect -y openconnect
五、国家封锁
设置connect-script = /usr/bin/ocserv-country-blocker在ocserv.conf.
使用以下代码创建一个文件/usr/bin/ocserv-country-blocker:
#!/bin/sh ALLOW_COUNTRY_CODES="CN" # Make sure Ocserv passes IP_REAL if [ "x${IP_REAL}" = "x" ]; then exit 1 fi GEOIP_STRING=$(curl -s https://freegeoip.live/csv/$IP_REAL) # Alternatively, in Fedora 23 or higher, the following would also provide the # country code variable using the local geoip database: # COUNTRY_CODE=$(ipcalc -g ${IP_REAL} | grep CODE | cut -d'=' -f2) COUNTRY_CODE=$(echo $GEOIP_STRING | cut -d ',' -f2) # Handle instances where COUNTRY_CODE is empty (e.g. RFC 1918 addresses) if [ "x${COUNTRY_CODE}" = "x" ]; then # Fail open exit 0 # Fail closed # exit 1 fi for c in $ALLOW_COUNTRY_CODES; do if [ "${c}" = "${COUNTRY_CODE}" ]; then exit 0 fi done # If we made it here, then COUNTRY_CODE was not found in ALLOW_COUNTRY_CODES exit 1
请务必设置ALLOW_COUNTRY_CODES为您希望将 VPN 访问列入白名单的国家/地区列表。
如果 FreeGeoIP 不返回国家/地区代码,您还应该决定您希望脚本表现出的行为。目前,脚本“打开失败”意味着如果由于某种原因 FreeGeoIP 没有返回国家/地区代码,它将允许客户端连接继续。
将可执行位设置为 /usr/bin/ocserv-country-blocker
重启 Ocserv
限制:
FreeGeoIP 对每个 API 客户端源 IP 强制执行每小时 10000 个 API 调用的 API 限制。
ALLOW_COUNTRY_CODES 显然会影响所有 VPN 客户端。如果您需要一个解决方案来允许来自不同国家/地区的客户端进行连接,那么如果不进行一些修改,此解决方案可能不适合您的用例。
六、开机自动启动挂载
vim /etc/systemd/system/openconnect.service
[Unit] Description=OpenConnect VPN Client After=network-online.target Wants=network-online.target [Service] Type=simple ExecStart=/bin/bash -c '/bin/echo -n 密码| /usr/sbin/openconnect -u 用户名--passwd-on-stdin' ExecStop=/usr/bin/pkill openconnect Restart=always RestartSec=2 [Install] WantedBy=multi-user.target
service openconnect start chkconfig openconnect on
七、参考文档
官方文档:https://ocserv.gitlab.io/www/manual.html
关键字词:vpn,ssl vpn,开源,AD域,ocserv,OpenConnect,AnyConnect

上一篇:Maven编译使用harbor
相关文章
-
无相关信息