由于之前已经在机房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. c语言模拟实现oc引用计数

    #include<stdio.h> #include<stdlib.h> //在c中引入 引用计数机制 // 要解决的问题:  1,指向某块动态内存的指针有几个? //    ...

  2. XCode6无论如何都无法升级为XCode8为什么呀?

    因为开发微信支付需要IOS9.0版本,但是本来的XCode是6.0版本,所以最高的是8.3版本,所以要进行升级更新,但是打开更新中心发现没有更新提示,所以到AppStore里面进行下载,因为本机已经安 ...

  3. run() 和 start() 的区别

    1) start: 用start方法来启动线程,真正实现了多线程运行,这时无需等待run方法体代码执行完毕而直接继续执行下面(指主线程下面)的代码.通过调用Thread类的start()方法来启动一个 ...

  4. 安卓--selector简单使用

    selector ---选择器 在App的使用中经常能看到selector的身影 如:一个按键看上去白色或者其它颜色,可能是一张图片 按下去又显示其它的颜色或者另外一张图片 这里使用shape配合使用 ...

  5. 第二个activity

    Android四大组件 Activity BroadCastReceiver Service ContentProvider 创建第二个Activity 创建第2个Activity的过程 1. 创建c ...

  6. nginx 配置优化的几个参数(转)

    nginx配置文件里面需要注意的一些参数 worker_processes 8  nginx要开启的进程数 一般等于cpu的总核数 其实一般情况下开4个或8个就可 我开2个 以了 多了没有太多用每个n ...

  7. MySQL Proxy

    最近翻看了mysql proxy的资料,特发上来. mysql proxy的推荐使用方式是采用配置文件来完成,当前在命令行的执行如下:mysql-proxy -P 192.168.1.101:3306 ...

  8. HDFS分布式文件系统资源管理器开发总结

      HDFS,全称Hadoop分布式文件系统,作为Hadoop生态技术圈底层的关键技术之一,被设计成适合运行在通用硬件上的分布式文件系统.它和现有的分布式文件系统有很多共同点,但同时,它和其他的分布式 ...

  9. English -有感过四六级后的托福单词表-附下载

    好像自从上学期不高不低过了六级之后就没怎么持续接触英语的东西了,欧,除了要debug的时候遇到问题了,去Google到了再用那些仅有的英语知识去看别人的文章.可能是因为看到的都是自己平时接触过的方面的 ...

  10. oracle存储过程、函数、序列、包

    一. 存储过程 1. 语法 create or replace procedure procedureName(seqName varchar2) is /*声明变量*/ n ); cursor cu ...