云网牛站
所在位置:首页 > Linux云服务器 > 从Linux终端使用Cisco AnyConnect连接到VPN服务器

从Linux终端使用Cisco AnyConnect连接到VPN服务器

2019-12-17 15:24:32作者:戴进稿源:云网牛站

这是关于如何从Linux命令行界面使用Cisco AnyConnect应用程序连接到VPN服务器的简短指南,此设置的基本要求是安装AnyConnect客户端应用程序,参考在Ubuntu/Debian/Fedora上安装Cisco AnyConnect的方法

从Linux终端使用Cisco AnyConnect连接到VPN服务器

 

从Linux终端使用Cisco AnyConnect连接到VPN服务器的方法

1、如果你使用了本指南中介绍的安装方法,则用于连接、断开连接和检查VPN状态的vpn脚本位于以下目录中:

从Linux终端使用Cisco AnyConnect连接到VPN服务器

$ ls /opt/cisco/anyconnect/bin/

total 3.7M

-rwxr-xr-x. 1 root root  14K Dec 13 03:26 acinstallhelper

-rwxr-xr-x. 1 root root 783K Dec 13 03:26 acwebhelper

-rwxr-xr-x. 1 root root  688 Dec 13 03:26 anyconnect_uninstall.sh

-rwxr-xr-x. 1 root root  315 Dec 13 03:26 load_tun.sh

-rwxr-xr-x. 1 root root 506K Dec 13 03:26 manifesttool

drwxr-xr-x. 2 root root 4.0K Dec 13 03:26 plugins

-rwxr-xr-x. 1 root root  76K Dec 13 03:26 vpn

-rwxr-xr-x. 1 root root 999K Dec 13 03:26 vpnagentd

-rwxr-xr-x. 1 root root 418K Dec 13 03:26 vpndownloader

-rwxr-xr-x. 1 root root 398K Dec 13 03:26 vpndownloader-cli

-rwxr-xr-x. 1 root root 487K Dec 13 03:26 vpnui

-rwxr-xr-x. 1 root root 9.2K Dec 13 03:26 vpn_uninstall.sh

2、检查vpn连接脚本命令选项:

$ /opt/cisco/anyconnect/bin/vpn --help

Usage: vpn [options] | [cmd] [host]

options:

-h Print this usage statement.

-v Print version.

-s Read commands from response file to work non-interactively.

Example: vpn -s < response.txt

commands: [connect|disconnect|hosts|state|stats]

3、这是一个连接示例:

$ /opt/cisco/anyconnect/bin/vpn -s connect 192.168.10.10

4、出现提示时接受不受信任的连接,并提供你的VPN用户名和密码:

Copyright (c) 2004 - 2019 Cisco Systems, Inc.  All Rights Reserved.

>> state: Disconnected

>> state: Disconnected

>> notice: Ready to connect.

>> registered with local VPN subsystem.

>> contacting host (192.168.10.10) for login information...

>> notice: Contacting 192.168.10.10.

AnyConnect cannot verify server: 192.168.10.10

- Certificate does not match the server name.

Connecting to this server may result in a severe security compromise!

Most users do not connect to untrusted servers unless the reason for the error condition is known.

Connect Anyway? [y/n]: y

>> Please enter your username and password.

Username: [jmutai] 

Password: 

Second Password:

5、如果提供了正确的帐户信息,则应启动连接:

>> state: Connecting

>> notice: Establishing VPN session...

The AnyConnect Downloader is analyzing this computer. Please wait...

Initializing the AnyConnect Downloader...

The AnyConnect Downloader is performing update checks...

>> notice: The AnyConnect Downloader is performing update checks...

>> notice: Checking for profile updates...

>> notice: Checking for product updates...

The AnyConnect Downloader updates have been completed.

Please wait while the VPN connection is established...

>> notice: Checking for customization updates...

>> notice: Performing any required updates...

>> notice: The AnyConnect Downloader updates have been completed.

>> state: Connecting

>> notice: Establishing VPN session...

>> notice: Establishing VPN - Initiating connection...

>> notice: Establishing VPN - Examining system...

>> notice: Establishing VPN - Activating VPN adapter...

>> notice: Establishing VPN - Configuring system...

>> notice: Establishing VPN...

>> state: Connected

6、检查VPN连接状态:

$ /opt/cisco/anyconnect/bin/vpn state

Cisco AnyConnect Secure Mobility Client (version 4.7.01076) .

Copyright (c) 2004 - 2019 Cisco Systems, Inc.  All Rights Reserved.

>> state: Connected

>> state: Connected

>> state: Connected

>> registered with local VPN subsystem.

VPN>

7、要获取连接统计信息,请使用以下命令:

$ /opt/cisco/anyconnect/bin/vpn stats

 

断开VPN

1、要断开与VPN的连接,请使用以下命令:

$ /opt/cisco/anyconnect/bin/vpn -s disconnect 192.168.10.11

2、将192.168.10.11替换为你的VPN服务器IP地址。

 

从CLI自动执行VPN连接

1、如果要脚本自动执行连接,请首先创建帐户信息文件,如下:

$ vim ~/.vpn_creds

username

Password

y

2、在文件中设置VPN用户名和密码,然后创建一个脚本文件,如下所示:

$ vim vpn_connect.sh

#!/bin/bash

VPN_SERVER="192.168.10.10"

echo "Connecting to VPN.."

/opt/cisco/anyconnect/bin/vpn -s  < ~/.vpn_creds connect ${VPN_SERVER}

3、使脚本可执行:

$ chmod +x vpn_connect.sh

4、运行脚本以连接到你的VPN服务器:

$ ./vpn_connect.sh

Connecting to VPN..

Cisco AnyConnect Secure Mobility Client (version 4.7.01076) .

Copyright (c) 2004 - 2019 Cisco Systems, Inc.  All Rights Reserved.

>> state: Disconnected

>> state: Disconnected

>> notice: Ready to connect.

>> registered with local VPN subsystem.

>> contacting host (192.168.10.10) for login information...

>> notice: Contacting 192.168.10.10.

>> Please enter your username and password.

Username: [jkmutai] jmutai

Password: 

>> state: Connecting

>> notice: Establishing VPN session...

The AnyConnect Downloader is analyzing this computer. Please wait...

Initializing the AnyConnect Downloader...

The AnyConnect Downloader is performing update checks...

>> notice: The AnyConnect Downloader is performing update checks...

>> notice: Checking for profile updates...

>> notice: Checking for product updates...

>> notice: Checking for customization updates...

The AnyConnect Downloader updates have been completed.

>> notice: Performing any required updates...

Please wait while the VPN connection is established...

>> notice: The AnyConnect Downloader updates have been completed.

>> state: Connecting

>> notice: Establishing VPN session...

>> notice: Establishing VPN - Initiating connection...

>> notice: Establishing VPN - Examining system...

>> notice: Establishing VPN - Activating VPN adapter...

>> notice: Establishing VPN - Configuring system...

>> notice: Establishing VPN...

>> state: Connected

5、现在,你可以使用AnyConnect VPN客户端安全地连接到公司网络了。

 

相关主题

Ubuntu/CentOS/Debian上使用L2TP和Cisco IPsec设置IPSec VPN的方法

精选文章
热门文章