由于之前已经在机房IDC安装了Anyconnect的VPN服务环境(参考:Anyconnect的VPN环境部署(1)-OpenConnect server(ocserv)服务安装
今天介绍下在linux客户机上连接Anyconnect服务:

1)yum安装openconnect
[root@FangFull-backup ~]# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
[root@FangFull-backup ~]# rpm -ivh epel-release-latest-6.noarch.rpm
[root@FangFull-backup ~]# yum install -y openconnect

2)配置
下载openconnect.zip包(下载地址:https://pan.baidu.com/s/1c2ssqyc    提取密码:qihm)
将openconnect.zip解压到/usr/local目录下
[root@test-huanqiu src]# unzip openconnect.zip
[root@test-huanqiu src]# mv openconnect /usr/local/
[root@test-huanqiu src]# chmod -R 777 /usr/local/openconnect/
[root@test-huanqiu src]# cd /usr/local/openconnect/
[root@test-huanqiu openconnect]# ls
conf COPYING dist helpers install NEWS README scripts
[root@test-huanqiu openconnect]# cd conf/
[root@test-huanqiu conf]# ls
config example.conf
[root@test-huanqiu conf]# cat config
# VPN server to connect to. This is a mandatory option
VPN_SERVER="any.wangshiboholdings.com"                                       //这个是Anyconnect的vpn地址
#server="116.137.17.11"
# vpnc script program to use. You can either use the one from vpnc, or use the
# ones from http://git.infradead.org/users/dwmw2/vpnc-scripts.git
SCRIPT_PROGRAM="/etc/vpnc/vpnc-script"                                        //openconnect安装成功后,就会有这个脚本
# Username to use when connecting. Leave blank if you want to input it
# interactively everytime or if it isn't relevant
USERNAME="wangshibo"                                                                //这个是连接VPN的用户名
# If you do not want to type in your password everytime, this gives a file where
# your password is stored.
#PASSWORD_FILE="/etc/epfl-vpn.pass"
PASSWORD_FILE="/etc/vpnc/passwd"                                           //这个是连接VPN的密码文件,里面是密码
# SHA1 SSL fingerprint of the your vpn server
SERVER_SHA1=""
# Path to SSL certificate of server (or CA having signed the server's
# certificate)
# SERVER_CERT="/etc/ssl/certs/QuoVadis_Root_CA.pem"
# Additional options that are directly passed to openconnect
ADDITIONAL_OPTS=""
3)创建密码文件/etc/vpnc/passwd,输入用户的密码
[root@test-huanqiu conf]# touch /etc/vpnc/passwd
[root@test-huanqiu conf]# echo "PASSWORD" > /etc/vpnc/passwd
[root@test-huanqiu conf]# cat /etc/vpnc/passwd
PASSWORD

4)创建anyconnect脚本日志文件,不然连接anyconnect会失败
[root@test-huanqiu conf]# touch /var/log/openconnect-script.log

5)创建启动脚本脚本
[root@test-huanqiu conf]# vim /bin/vpn_start
#!/bin/sh
/usr/local/openconnect/scripts/vpn-connect /usr/local/openconnect/conf/config

[root@test-huanqiu conf]# chmod 755 /bin/vpn_start

6)执行启动脚本,进行vpn连接
[root@test-huanqiu conf]# /bin/sh /bin/vpn_start
Openconnect successfully started. Use vpn-disconnect to stop.

[root@test-huanqiu conf]# ps -ef|grep vpn
root 894 1 0 09:26 pts/0 00:00:00 /usr/sbin/openconnect --background --no-cert-check --script=/etc/vpnc/vpnc-script --user=wangshibo --passwd-on-stdin any.wangshiboholdings.com
root 898 808 0 09:26 pts/0 00:00:00 grep --color=auto vpn
----------------------------------------------------------------------------------------------------------------------------------
上面使用脚本连接的Anyconnect,也可以用命令直接连接(即上面启动后查看的vpn状态中去掉--passwd-on-stdin部分后的命令)
[root@test-huanqiu conf]# /usr/sbin/openconnect --background --no-cert-check --script=/etc/vpnc/vpnc-script --user=wangshibo any.wamgshiboholdings.com
POST https://any.wangshiboholdings.com/
Attempting to connect to server 13.25.24.115:443
SSL negotiation with any.wangshiboholdings.com
Server certificate verify failed: unable to get local issuer certificate
Connected to HTTPS on any.wangshiboholdings.com
XML POST enabled
Please enter your username and password.
Password:                                                           //输入密码即可
POST https://any.wangshiboholdings.com/
Got CONNECT response: HTTP/1.1 200 OK
CSTP connected. DPD 30, Keepalive 20
RTNETLINK answers: File exists
/etc/vpnc/vpnc-script: line 228: /var/run/vpnc/resolv.conf-backup: No such file or directory
Script '/etc/vpnc/vpnc-script' returned error 1
Connected tun0 as 10.4.9.145, using SSL
Continuing in background; pid 6078

查看已经成功连接
[root@test-huanqiu conf]# ps -ef|grep vpn
root 894 1 0 09:26 pts/0 00:00:00 /usr/sbin/openconnect --background --no-cert-check --script=/etc/vpnc/vpnc-script --user=wangshibo any.wangshiboholdings.com
root 898 808 0 09:26 pts/0 00:00:00 grep --color=auto vpn
----------------------------------------------------------------------------------------------------------------------------------

7)创建监控脚本(直接执行这个脚本,也可以连接Anyconnect)
[root@test-huanqiu conf]# vim /root/vpn_monit.sh
#!/bin/bash
NUM=`ps -ef|grep openconnect|grep -v "grep"|wc -l`
if [ $NUM -eq 0 ];then
     /bin/bash /bin/vpn_start >/dev/null 2>&1
else
    echo "It is ok"
fi

8)结合crontab,实现定期检查
[root@test-huanqiu conf]# crontab -l
*/30 * * * * /bin/sh /bin/vpn_start >/dev/null 2>&2
* * * * * /bin/bash /root/vpn_monit.sh > /dev/null 2>&1

Anyconnect的VPN环境部署(2)-在Linux客户机上连接Anyconnect的更多相关文章

  1. Anyconnect的VPN环境部署(1)-OpenConnect server(ocserv)服务安装

    打算在公司IDC机房部署一套VPN环境,经过考虑,最终决定采用Cisco下的开源技术AnyConnect.AnyConnect的优势有:1)长连接,待机不会断开:2)速度快,稳定性好:3)安全性好,全 ...

  2. Delphi 10.2 Linux 程序开发环境部署的基本步骤(网络连接方式要选择桥接或者是Host Only)

    Delphi 10.2 Linux 程序开发环境部署的基本步骤 http://blog.qdac.cc/?p=4477 升級到 Delphi 10.2 Tokyo 笔记http://www.cnblo ...

  3. Centos下PPTP环境部署记录

    PPTP(点到点隧道协议)是一种用于让远程用户拨号连接到本地的ISP,通过因特网安全远程访问公司资源的新型技术.它能将PPP(点到点协议)帧封装成IP数据包,以便能够在基于IP的互联网上进行传输.PP ...

  4. 一个CentOS7的开发环境部署,包括防火墙|VPN|多IP多网关|HTTP代理服务器设置等

    http://www.lenggirl.com/code/centos7.html layout: post title: "一个CentOS7的开发环境部署,包括防火墙|VPN|HTTP代 ...

  5. Linux Debian 7部署LEMP(Linux+Nginx+MySQL+PHP)网站环境

    我们在玩VPS搭建网站环境的时候,都经常看到所谓的LAMP.LNMP.LEMP,LAMP, 其中的A代表APECHE WEB驱动环境,LNMP中的N代表NGINX驱动环境,只不过海外的叫法NGINX ...

  6. Linux下FTP虚拟账号环境部署总结

    vsftp的用户有三种类型:匿名用户.系统用户.虚拟用户.1)匿名登录:在登录FTP时使用默认的用户名,一般是ftp或anonymous.2)本地用户登录:使用系统用户登录,在/etc/passwd中 ...

  7. Linux环境:持续集成环境部署系列

    之前的博客介绍了Linux环境下持续集成环境部署的一些内容,这篇博客将其整理一下,算做一个index,方便自己和大家查阅... 1.linux下安装JDK Jenkins是一个java开源的持续集成工 ...

  8. 环境部署(七):linux下Jenkins+Git+JDK持续集成

    前面几篇博客介绍了linux下安装Jenkins.Git.JDK以及Git基础教程和Git关联github等内容,这篇博客,介绍下如何在linux服务器中利用它们构建持续集成环境... 一.准备工作 ...

  9. Linux下开源邮件系统Postfix+Extmail+Extman环境部署记录

    一.基础知识梳理MUA (Mail User Agent) MUA 既是"邮件使用者代理人",因为除非你可以直接利用类似 telnet 之类的软件登入邮件主机来主动发出信件,否则您 ...

随机推荐

  1. Android 中的Json解析工具fastjson 、序列化、反序列化

    Android中通常需要访问服务器,然而服务器返回的数据很多时候都是Json格式 1.fastjson简介 阿里巴巴FastJson是一个Json处理工具包,包括“序列化”和“反序列化”两部分,它具备 ...

  2. Android SQL语句实现数据库的增删改查

    本文介绍android中的数据库的增删改查 复习sql语法: * 增 insert into info (name,phone) values ('wuyudong','111') * 删 delet ...

  3. OC中的protocol

    一. 简单使用 1. 基本用途 可以用来声明一大堆方法(不能声明成员变量) 只要某个类遵守了这个协议,就相当于拥有这个协议中的所有方法声明 只要父类遵守了某个协议,就相当于子类也遵守了 2. 格式 协 ...

  4. 【Android】监听Notification被清除

    前言 一般非常驻的Notification是可以被用户清除的,如果能监听被清除的事件就可以做一些事情,比如推送重新计数的问题. 声明 欢迎转载,但请保留文章原始出处:)  博客园:http://www ...

  5. UITableView全面解析

    本文转自:http://www.cocoachina.com/ios/20140922/9710.html 在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以 ...

  6. qq邮箱过滤器 + Foxmail(IMAP)

      一.qq邮箱过滤器       二.Foxmail+  IMAP,实现自定义目录下载     IMAP介绍,和POP比较 如何在Foxmail中配置IMAP

  7. 写在复习MVC后

    MVC的一些 今天把MVC复习了下,包括官方文档以及各种中文博客. 官方文档里面最能说明的问题的图片,相对于传统的MVC,苹果分离了View和Model之间的通信,实现了更好的复用性.我觉得MVC更 ...

  8. 集合迭代器快速失败行为及CopyOnWriteArrayList

    以下内容基于jdk1.7.0_79源码: 什么是集合迭代器快速失败行为 以ArrayList为例,在多线程并发情况下,如果有一个线程在修改ArrayList集合的结构(插入.移除...),而另一个线程 ...

  9. 分组函数 ----group by 使用总结

    总结:1,在where子句中不能用分组聚合函数.       2,如果没有group by 子句,select 不能同时出现字段与分组的聚合函数.       3,在有 group by 的子句的查询 ...

  10. JavaScript Patterns 6.7 Borrowing Methods

    Scenario You want to use just the methods you like, without inheriting all the other methods that yo ...