Linux从2.6内核开始自带IPsec模块,配合IPsec-Tools,可以实现Linux的IPsec功能。

IPsec-Tools包含4个模块

  • libipsec:PF_KEY实现库
  • setkey:用于配置SAD(安全关联数据库)和SPD(安全策略数据库)
  • racoon:IKE守护程序,用于自动建立IPsec连接
  • racoonctl:操作racoon的shell工具

安装步骤

  1. 下载压缩包ipsec-tools-0.8.0.tar.bz2。
  2. 解压

    tar -jxvf ipsec-tools-0.8.0.tar.bz2
  3. 进入解压目录,configure

    cd ipsec-tools-0.8.0

    export CFLAGS="-fno-strict-aliasing" 这一步不执行make阶段会报错。

    ./configure --with-kernel-headers=/lib/modules/2.6.*/build/include 此处必须指定kernel header,系统内核版本必须为2.6
  4. make

    make
  5. make install

    make install

配置文件

  • setkey.conf:SAD和SPD配置信息
#!/usr/sbin/setkey -f

flush;
spdflush; spdadd 1.1.1.1/32 2.2.2.2/32 any -P out ipsec
esp/tunnel/1.1.1.1-2.2.2.2/require; spdadd 2.2.2.2/32 1.1.1.1/32 any -P in ipsec
esp/tunnel/2.2.2.2-1.1.1.1/require;
  • psk.txt 预共享密钥,用于进行IPsec连接

    1.1.1.1 testkey

    2.2.2.2 testkey

注:psk.txt文件的权限应该为400,可使用dd if=/dev/random count=16 bs=1| xxd -ps命令生成密钥。

  • racoon.conf:自动建立IPsec连接的配置文件
    #!/usr/local/bin/racoon

    path include "/root";

    path pre_shared_key "/root/psk.txt";

    remote 10.114.30.21 {
exchange_mode aggressive;
lifetime time 15 min;
proposal {
encryption_algorithm rijndael 128;
hash_algorithm sha1;
authentication_method pre_shared_key;
dh_group 14;
}
} sainfo address 10.114.30.1/32 any address 10.114.30.21/32 any
{
pfs_group 14;
lifetime time 15 mins;
encryption_algorithm rijndael 128;
authentication_algorithm hmac_sha1;
compression_algorithm deflate ;
} sainfo address 10.114.30.21/32 any address 10.114.30.1/32 any
{
pfs_group 14;
lifetime time 15 mins;
encryption_algorithm rijndael 128;
authentication_algorithm hmac_sha1;
compression_algorithm deflate ;
}

建立IPsec隧道

1、 加载setkey.cof配置文件

setkey -f setkey.conf

此时使用setkey -DP命令可以看到SPD数据

 1.1.1.1[any] 2.2.2.2[any] any
in prio def ipsec
esp/tunnel/10.114.30.21-10.114.30.1/require
created: Apr 18 09:45:58 2018 lastused:
lifetime: 0(s) validtime: 0(s)
spid=600 seq=2 pid=97144
refcnt=1
2.2.2.2[any] 1.1.1.1[any] any
out prio def ipsec
esp/tunnel/10.114.30.1-10.114.30.21/require
created: Apr 18 09:45:58 2018 lastused:
lifetime: 0(s) validtime: 0(s)
spid=593 seq=3 pid=97144
refcnt=1

使用setkey -D显示无SAD Entry

No SAD entries.

2、启动racoon进程

/usr/local/sbin/racoon -f -ddddddd /root/racoon.conf -l /tmp/ipsec-log.txt -v

此时在1.1.1.1上ping 2.2.2.2,并在2.2.2.2上使用tcpdump抓esp报文

tcpdump -i eth0 -n src 1.1.1.1 and esp

20:27:46.708527 IP 10.114.30.1 > 10.114.30.21: ESP(spi=0x0cedc045,seq=0x1), length 132

20:27:47.708474 IP 10.114.30.1 > 10.114.30.21: ESP(spi=0x0cedc045,seq=0x2), length 132

可以看到esp报文,说明IPsec隧道已经建立,ping命令发出的的ICMP报文已经被加密。

setkey -FP 刷新SPD

setkey -F 刷新SAD

这两个操作会清楚SAD和SPD,关闭ipsec隧道。

  • 查看日志

    tail -f /tmp/ipsec-log.txt

    2018-04-17 19:40:23: INFO: @(#)ipsec-tools 0.7.3 (http://ipsec-tools.sourceforge.net)

    2018-04-17 19:40:23: INFO: @(#)This product linked OpenSSL 1.0.1e-fips 11 Feb 2013 (http://www.openssl.org/)

    2018-04-17 19:40:23: INFO: Reading configuration from "/root/racoon.conf"

    2018-04-17 19:40:23: INFO: 127.0.0.1[500] used as isakmp port (fd=6)

    2018-04-17 19:40:23: INFO: 1.1.1.1[500] used as isakmp port (fd=7)

从日志中可以看到建立隧道的过程,需要开启Debug模式。

IPsec工具之ipsec-tools的更多相关文章

  1. Threejs 官网 - Three.js 的图形用户界面工具(GUI Tools with Three.js)

    Threejs 官网 - Three.js 的图形用户界面工具(GUI Tools with Three.js) 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) ...

  2. MAC 命令行工具(Command Line Tools)安装

    不过升级后安装命令行工具(Command Line Tools)时发现官网没有clt的下载安装包了,原来改了,使用命令在线安装. 打开终端,输入命令:xcode-select --install 选择 ...

  3. Chrome的开发者工具(Chrome Developer Tools)

    Chrome的开发者工具(Chrome Developer Tools) 按F12 https://developer.chrome.com/devtools/index http://www.w3s ...

  4. Android 开发小工具之:Tools 属性 (转)

    Android 开发小工具之:Tools 属性 http://blog.chengyunfeng.com/?p=755#ixzz4apLZhfmi 今天来介绍一些 Android 开发过程中比较有用但 ...

  5. [ipsec][crypto] ike/ipsec与tls的认证机制比较

    前言 接上篇:[ipsec][crypto] 有点不同的数字证书到底是什么 本篇内容主要是上一篇内容的延伸.抽象的从概念上理解了证书是什么之后,我们接下来 从实践的角度出发,以IKEv2和TLS两个协 ...

  6. [ipsec][crypto] 在IPSec ESP使用AES-GCM加密时的IV

    IV IV是指初始化向量. 在我们当前讨论的场景中: 在IPSec ESP使用AES-GCM加密 IV有两个含义: 1. ESP报文封装时的IV,RFC中称为 AES-GCM IV +-+-+-+-+ ...

  7. MAC OS 如何安装命令行工具:Command Line Tools

    打开终端输入:xcode-select --install 回车 安装好了测试结果:gcc -v 显示如下: xcode-select: note: install requested for com ...

  8. Xcode 命令行工具 Command Line Tools

    xcode命令行工具包是一个小型独立包,可供下载独立于Xcode的和允许您执行命令行开发OS X. 在OS X10.9,就以及没有clt的下载安装包了,需要使用命令在线安装. xcode-select ...

  9. VS 使用vs2017自带的诊断工具(Diagnostic Tools)诊断程序的内存问题

    前言 一般来说.NET程序员是不用担心内存分配释放问题的,因为有垃圾收集器(GC)会自动帮你处理.但是GC只能收集那些不再使用的内存(根据对象是否被其它活动的对象所引用)来确定.所以如果代码编写不当的 ...

随机推荐

  1. JDBC学习笔记——PreparedStatement的使用

    PreparedStatement public interface PreparedStatement extends Statement;可以看到PreparedStatement是Stateme ...

  2. 个人作业-Week 2 代码复审

    一.概要部分 1.代码能符合需求和规格说明么? 经过我自己的测试和助教的检测,他的代码符合需求和规格的说明. 2.代码设计是否有周全的考虑? 这里代码设计我们是从两个方面检查的: 对方处理控制台输入的 ...

  3. PAT 甲级 1087 All Roads Lead to Rome

    https://pintia.cn/problem-sets/994805342720868352/problems/994805379664297984 Indeed there are many ...

  4. Linux命令(十四) 查看工作目录文件 ls

    目录 1.命令简介 2.常用参数介绍 3.实例 4.直达底部 命令简介 ls 命令是 Linux 下最常用的命令. ls 就是 list 的缩写.默认情况下 ls 命令用来打印出当前目录的清单, 如果 ...

  5. PSP(3.23——3.29)以及周记录

    3.23 9:30 10:30 15 45 Android Studio 界面设计学习 A Y min 13:00 13:15 0 15 站立会议 A Y min 23:20 23:45 0 25 英 ...

  6. codeforces71A

    Way Too Long Words CodeForces - 71A XUPT_ACM的杨队是一个强迫症晚期的大神,他特别反感长单词,就像 "localization" 和&qu ...

  7. contentInsetAdjustmentBehavior各个值之间的区别

    iOS11也出了不少时候了网上说适配的文章一大堆.关于contentInsetAdjustmentBehavior这个参数之间的区别,好像没什么人能说明.往下看的前提是你已经知道什么是安全区域,没看明 ...

  8. Square Numbers UVA - 11461(水题)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  9. #LOJ2564 SDOI2018 原题识别 主席树

    转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/9057297.html 原题链接: 今天考试考了前天的SDOI考题 天啊我菜爆,只有T2拿了30分 然后考试后半 ...

  10. Different between Telnet/SSH/FTP

    http://www.differencebetween.net/category/technology/protocols-formats/ Telnet vs SSH Secure Shell, ...