FreeBSD下通过IPSec建立(扩展)企业内部VPN
时间:2007-01-04 10:28:33
来源: 作者:whsong 点击:次 出处:技术无忧
关键字:Free
IETF的IP层加密标准协议IPSec协议是个一个三层隧道协议,用于传输三层网络协议,它主要应用于构建企业内部虚拟专网(Intranet VPN)和扩展的企业内部虚拟专网(Extranet VPN)。IPSec 协议不是一个单独的协议,它给出了应用于IP层上网络数据安全的一整套体系结构,它包括Authentication Header(AH)协议和 Encapsulating Security Payload(ESP)协议、Internet Key Exchange(IKE)协议和用于网络验证及加密的一些算法等。IPSec 规定了如何在对等层之间选择安全协议、确定安全算法和密钥交换,向上提供了访问控制、数据源验证、数据加密等网络安全服务。 IPSec有多种封装传输模式,其中,IPSec的ESP/tunnel mode可以跨Internet连接两个网络。FreeBSD早在3.X版本时就支持IPSec,下面我们将用两台FreeBSD主机作网关,连接两个不同地域间的网络。
一、 环境
LAN(Beijing)<->FreeBSD A<-----> Internet <------> FreeBSD B<->LAN(Shanghai)
LAN(Beijing): 172.16.1.0/24
FreeBSD A: 外部合法IP: 1.2.3.4 内部IP: 172.16.1.1
LAN(Shanghai): 192.168.0.0/24
FreeBSD B: 外部合法IP: 5.6.7.8 内部IP: 192.168.0.1
二、 定制内核
在FreeBSDA、B的内核配置文件中加入:
options IPSEC #IP security
options IPSEC_ESP #IP security (crypto; define w/ IPSEC)
device gif 4 #通过gif(4) device实现IP-IP tunneling
重新编译,安装新内核、重新启动。
三、 配置
在FreeBSD A下:
# vi /usr/local/etc/rc.d/ipsec.sh
#!/bin/sh
# make a tunnel interface
gifconfig gif0 1.2.3.4 5.6.7.8
ifconfig gif0 172.16.1.1 192.168.0.1 netmask 0xffffff00
# Make a static route
route add -net 192.168.0.0/24 192.168.0.1
# read in the config
setkey -f /etc/ipsec.conf
# chmod +x /usr/local/etc/rc.d/ipsec.sh
# vi /etc/ipsec.conf
flush;
spdflush;
add 1.2.3.4 5.6.7.8 esp 9991 -E blowfish-cbc "password";
add 5.6.7.8 1.2.3.4 esp 9992 -E blowfish-cbc "wordpass";
spdadd 172.16.1.0/24 192.168.0.0/24 any -P out ipsec esp/tunnel/1.2.3.4-5.6.7.8/require;
spdadd 192.168.0.0/24 172.16.1.0/24 any -P in ipsec esp/tunnel/5.6.7.8-1.2.3.4/require;
在FreeBSD B下:
# vi /usr/local/etc/rc.d/ipsec.sh
#!/bin/sh
gifconfig gif0 5.6.7.8 1.2.3.4
i fconfig gif0 192.168.0.1 172.16.1.1 netmask 0xffffff00
route add -net 172.16.1.0/24 172.16.1.1
setkey -f /etc/ipsec.conf
# chmod +x /usr/local/etc/rc.d/ipsec.sh
# vi /etc/ipsec.conf
flush;
spdflush;
# Note that the add rules are the same as on Node A!
add 1.2.3.4 5.6.7.8 esp 9991 -E blowfish-cbc "password";
add 5.6.7.8 1.2.3.4 esp 9992 -E blowfish-cbc "wordpass";
spdadd 192.168.0.0/24 172.16.1.0/24 any -P out ipsec esp/tunnel/5.6.7.8-1.2.3.4/require;
spdadd 172.16.1.0/24 192.168.0.0/24 any -P in ipsec esp/tunnel/1.2.3.4-5.6.7.8/require;
四、 测试
两个局域网内的计算机的Default Gateway指向各自的FreeBSD主机内部地址,或者手动添加静态路由。Ping对方网内的主机,看是否联通。
五、 其他
1、 如果使用FreeBSD版本是4.4-Release之后,编译内核时用pseudo-device gif代替device gif 4;且在/etc/rc.conf中定义gif设备(详见/etc/default/rc.conf):
gif_interfaces="gif0"
gifconfig_gif0="1.2.3.4 5.6.7.8"
否则,创建不了gif设备。可用ifconfig –a 看gif0是否建立。
2、 如果想限制对方网内计算机的访问权限,可以结合防火墙控制

上一篇:使用FreeBSD模拟路由器转发











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面