由于之前已经在机房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. CoreDataManager-Swift版-兼容iOS10以前的版本

    import UIKit import CoreData // coredata管理器 class CoreDataManager: NSObject { // 单例 static let share ...

  2. 【读书笔记】iOS-给模拟器相册增加图片

    一,打开模拟器(如下图所示)----->找到模拟器中的相册---->打开相册---->把要添加的图片拖动到模拟器中.          

  3. MVC数据库数据分页显示

    首先从数据库获取数据 using System; using System.Collections.Generic; using System.Linq; using System.Web; usin ...

  4. RFID应用范围

    RFID应用范围 (1)物流: 物流过程中的货物追踪,信息自动采集,仓储应用,港口应用,邮政,快递 (2)零售: 商品的销售数据实时统计,补货,防盗 (3)制造业: 生产数据的实时监控,质量追踪,自动 ...

  5. DROP_SNAPSHOT_RANGE过程不能清理表RM$_SNAPSHOT_DETAILS

    今天在测试.验证DROP_SNAPSHOT_RANGE不能彻底快照的过程中遇到了DROP_SNAPSHOT_RANGE无法清理WRM$_SNAPSHOT_DETAILS表中数据的情况,测试服务器版本为 ...

  6. [MySQL Reference Manual] 5 MySQL 服务管理

    5. MySQL 服务管理 5. MySQL 服务管理 5.1 The Mysql Server 5.2 Mysql 服务日志 5.2.1 选择General query log和slow query ...

  7. MongoDB Shard部署及Tag的使用

    Shard部署 准备测试环境 为准备数据文件夹 Cd  /home/tiansign/fanr/mongodb/Shard mkdir configdb1 configdb2 configdb3 mk ...

  8. SSRS 的简单使用(二)

    经过上一篇的初始,我们已经做好了报表的准备工作,接下来我们进行报表的展示和其他一下操作,并且给出一些使用RS的方法方便大家日后能灵活使用. 步骤:        1.首先拖拽表格等进入到设计模板 点击 ...

  9. 用struts2获取session、request、parmeter的方法

    package com.hanqi.action; import java.util.Map; import com.opensymphony.xwork2.ActionContext; public ...

  10. c# 设置winform程序为默认打开软件 在运行中获取参数

    1.右键→打开方式→选择默认程序→选择winform程序 2.修改Program.cs 判断注册的事件是否存在,如果不存在则运行实例,并把参数传入MainForm里,如果存在则把参数写到txt文件中, ...