在CentOS 6.5上配置Cisco AnyConnect VPN
在CentOS 6.5上配置Cisco AnyConnect VPN AnyConnect是思科的安全远程接入解决方案,之前只有思科的设备才支持。 ocserv(OpenConnect server)是一个OpenConnect SSL VPN协议服务端,0.3.0版后兼容使用AnyConnect SSL VPN协议的终端。 官方主页:http://www.infradead.org/ocserv/ 在iOS下推荐使用AnyConnect,目前iOS使用VPN存在以下问题: 1、待机会断开 2、不能控制路由表 iOS使用APN存在以下问题: 1、不稳定,有时打不开页面 2、需要墙内墙外均部署服务器 AnyConnect相比有以下优势: 1、待机不会断开 2、能够下发路由表给客户端(未测试) 3、稳定 4、相比APN,只需要1台机器 经测试,从晚上2点多,待机到早上9点多,iPhone电量从18%掉到13%,AnyConnect还保持连接。 环境:CentOS 6.5 x64 ocserv需要3.1版以上的gnutls,gnutls需要2.7版以上的nettle 这两个在repo仓库里均没有,所以我们自己编译 首先保证系统里已安装openssl、gcc、make等常用软件 BTW:Ubuntu上好像可以用apt-get -t wheezy-backports从backports安装这些新版本(未测试) 1、编译nettle 安装gmp yum install gmp-devel gmp wget http://ftp.gnu.org/gnu/nettle/nettle-2.7.1.tar.gz tar zxf nettle-2.7.1.tar.gz && cd nettle-2.7.1 ./configure –prefix=/usr && make make install && chmod -v 755 /usr/lib/libhogweed.so.2.5 /usr/lib/libnettle.so.4.7 && install -v -m755 -d /usr/share/doc/nettle-2.7.1 && install -v -m644 nettle.html /usr/share/doc/nettle-2.7.1 2、编译unbound 安装expat-devel yum install expat-devel wget http://unbound.nlnetlabs.nl/downloads/unbound-1.4.22.tar.gz tar zxf unbound-1.4.22.tar.gz && cd unbound-1.4.22 ./configure && make && make install mkdir -p /etc/unbound && unbound-anchor -a “/etc/unbound/root.key” 3、编译gnutls wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.2/gnutls-3.2.12.1.tar.xz xz -c -d gnutls-3.2.12.1.tar.xz tar x cd gnutls-3.2.12 ./configure –prefix=/usr && make && make install 4、编译ocserv wget ftp://ftp.infradead.org/pub/ocserv/ocserv-0.3.2.tar.xz xz -c -d ocserv-0.3.2.tar.xz tar x cd ocserv-0.3.2 ./configure && make && make install 如果nettle和gnutls安装在/usr/local目录,需要运行以下命令设置系统变量,再运行./configure。同时要把这些命令加进系统启动里。 32bit export LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/lib64/ NETTLE_CFLAGS=”-I/usr/local/include/” NETTLE_LIBS=”-L/usr/local/lib64/ -lnettle” HOGWEED_CFLAGS=”-I/usr/local/include” HOGWEED_LIBS=”-L/usr/local/lib64/ -lhogweed” export LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/lib64/ LIBGNUTLS_CFLAGS=”-I/usr/local/include/” LIBGNUTLS_LIBS=”-L/usr/local/lib/ -lgnutls” LIBNL3_CFLAGS=”-I/usr/local/include” LIBNL3_LIBS=”-L/usr/local/lib/ -lnl-3 -lnl-route-3″ 64bit export LD_LIBRARY_PATH=/usr/lib/:/usr/lib64/ NETTLE_CFLAGS=”-I/usr/include/” NETTLE_LIBS=”-L/usr/lib64/ -lnettle” HOGWEED_CFLAGS=”-I/usr/include” HOGWEED_LIBS=”-L/usr/lib64/ -lhogweed” export LD_LIBRARY_PATH=/usr/lib/:/usr/lib64/ LIBGNUTLS_CFLAGS=”-I/usr/include/” LIBGNUTLS_LIBS=”-L/usr/lib/ -lgnutls” LIBNL3_CFLAGS=”-I/usr/include” LIBNL3_LIBS=”-L/usr/lib/ -lnl-3 -lnl-route-3″ 5、配置ocserv 创建ca证书和服务器证书(参考http://www.infradead.org/ocserv/manual.html#heading5) certtool –generate-privkey –outfile ca-key.pem cat < < _EOF_ >ca.tmpl cn = “stunnel.info VPN” organization = “stunnel.info” serial = 1 expiration_days = 365 ca signing_key cert_signing_key crl_signing_key _EOF_ certtool –generate-self-signed –load-privkey ca-key.pem –template ca.tmpl –outfile ca-cert.pem certtool –generate-privkey –outfile server-key.pem cat < < _EOF_ >server.tmpl cn = “stunnel.info VPN” o = “stunnel” serial = 2 expiration_days = 365 signing_key encryption_key #only if the generated key is an RSA one tls_www_server _EOF_ certtool –generate-certificate –load-privkey server-key.pem –load-ca-certificate ca-cert.pem –load-ca-privkey ca-key.pem –template server.tmpl –outfile server-cert.pem 把证书复制到ocserv的配置目录 mkdir -p /usr/local/etc/ocserv/ ; cp server-cert.pem /usr/local/etc/ocserv/ && cp server-key.pem /usr/local/etc/ocserv/ 复制配置文件样本 cp doc/sample.config /usr/local/etc/ocserv/ocserv.conf
编辑配置文件 vim /usr/local/etc/ocserv/ocserv.conf
修改如下: auth = “plain[/usr/local/etc/ocserv/ocpasswd]” #ocserv支持多种认证方式,这是自带的密码认证,使用ocpasswd创建密码文件 #ocserv还支持证书认证,可以通过Pluggable Authentication Modules (PAM)使用radius等认证方式 server-cert = /usr/local/etc/ocserv/server-cert.pem server-key = /usr/local/etc/ocserv/server-key.pem #证书路径 max-same-clients = 10 #同一个用户最多同时登陆数 run-as-group = nobody ipv4-network = 192.168.10.0 #分配给VPN客户端的IP段 dns = 8.8.8.8 dns = 8.8.4.4 #route = 192.168.1.0/255.255.255.0 #route = 192.168.5.0/255.255.255.0 #注释掉这两行。route参数留空表示所有流量均走VPN。 #ocserv可以给客户端下发路由表。比如可以把公司内网IP段、所有国外IP走VPN出去。 #default-domain = example.com #注释掉这行。 创建认证用的用户文件 ocpasswd -c /usr/local/etc/ocserv/.passwd 修改系统配置,允许转发 注意把网卡接口名称改成你服务器上对应的接口 sed -i ‘s/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g’ /etc/sysctl.conf sysctl -p iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o venet0 -j MASQUERADE iptables -A FORWARD -s 192.168.10.0/24 -j ACCEPT #IP段和venet0接口要根据自己的情况修改 最后运行服务 /usr/local/sbin/ocserv -c /usr/local/etc/ocserv/ocserv.conf 在iOS上安装Cisco AnyConnect即可连接服务器 Android上也有Cisco AnyConnect(需要root),不过Android可选择的太多,推荐Shadowsocks Windows、MAC OS也有Cisco的官方客户端 参考: http://www.infradead.org/ocserv/manual.html http://ttz.im/blog/2014/02/1131 http://www.cisco.com/web/CN/solutions/trends/byod\_smart\_solution/pdf/at\_a\_glance\_c45\_578609.pdf http://botu.me/entry/install-ocserv-on-centos6.html pptpd 在CentOS 6.5上配置Cisco AnyConnect VPN
- 标题: 在CentOS 6.5上配置Cisco AnyConnect VPN
- 作者: jicky huang
- 创建于 : 2016-02-09 23:27:53
- 更新于 : 2025-10-05 20:36:03
- 链接: https://www.hxfund.cn/2016/02/09/在centos-6-5上配置cisco-anyconnect-vpn/
- 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。