Chinaunix首页 | 论坛 | 博客
  • 博客访问: 308350
  • 博文数量: 720
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 8080
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-17 23:09
文章分类

全部博文(720)

文章存档

2010年(720)

我的朋友

分类:

2010-10-03 11:57:59

  在实际的工作中,经常遇到需要将处在不同地点的两个局域网络连接起来的要求。采用freebsd ipsec tunnel方式可以方便的将两个局域网络连接起来,且具有很好的安全性。下面将用一个案例来讲述如何采用这种方式连接两个局域网络。   假设有如下的网络结构:   两台freebsd机器都分别配置为两个子网的防火墙,并对内核配置增加ipsec支持,相关的内核配置参数如下:   # ip security (crypto; define w/ ipsec)   options ipsec   options ipsec_esp   options ipsec_debug   # generic tunnel interface   pseudo-device gif 4   # berkeley packet filter used by dhcp server.   pseudo-device bpf 4   # firewall flags   options ipfirewall   options ipdivert   options ipfilter   options ipfilter_log   重新编译内核。   为启动防火墙功能,/etc/rc.conf中加入如下的配置选项:   gateway_enable="yes"   defaultrouter="172.x.1.110" # 由接入服务商提供   firewall_enable="yes"   firewall_type="open"   natd_enable="yes"   natd_interface="rl0" # 根据机器网卡配置确定   named_enable="yes"   要进行两台freebsd机器之间的自动的ipsec key交换,必须安装port /usr/ports/.security/racoon,配置文件存储在/usr/local/etc/racoon/racoon.conf,key文件存储在/usr/local/etc/racoon/psk.txt。要在系统启动时启动/usr/local/sbin/racoon。   不需要修改配置文件,只需修改key文件即可,如下:   # /usr/local/etc/racoon/psk.txt   # ipv4/v6 addresses   #   192.168.1.1 foobar   192.168.2.1 foobar   key文件必须设置存储权限为0600,否则racoon无法运行;   #chown root.wheel /usr/local/etc/racoon/psk.txt   #chmod 0600 /usr/local/etc/raccoon/psk.txt   为了在启动时建立ipsec tunnel连接并添加两个内网的路由,可使用下面的shell脚本,存储在/usr/local/etc/rc.d/tunnel.sh   #!/bin/sh # bsd1_ip="192.168.1.1" bsd1_pub_ip="172.16.1.254" bsd1_net="192.168.1.0/24" bsd2_ip="192.168.2.1" bsd2_pub_ip="172.17.1.254" bsd2_net="192.168.2.0/24" gif0="gif0 inet" gifconfig="/usr/sbin/gifconfig" ifconfig="/sbin/ifconfig" hostname=`/bin/hostname` netmask="255.255.255.0" echo "\nstarting ipsec tunnel... " case $hostname in bsd1.test.com) $gifconfig $gif0 $bsd1_pub_ip $bsd2_pub_ip $ifconfig $gif0 $bsd1_ip $bsd2_ip netmask $netmask /usr/sbin/setkey -fp /usr/sbin/setkey -f /usr/sbin/setkey -c << eof spdadd $bsd1_net $bsd2_net any -p out ipsec esp/tunnel/${bsd1_pub_ip}-${bsd2_pub_ip}/require; spdadd $bsd2_net $bsd1_net any -p in ipsec esp/tunnel/${bsd2_pub_ip}-${bsd1_pub_ip}/require; eof /sbin/route add $bsd2_net $bsd1_ip ;; bsd2.test.com) $gifconfig $gif0 $bsd2_pub_ip $bsd1_pub_ip $ifconfig $gif0 $bsd2_ip $bsd1_ip netmask $netmask /usr/sbin/setkey -fp /usr/sbin/setkey -f /usr/sbin/setkey -c << eof spdadd $bsd2_net $bsd1_net any -p out ipsec esp/tunnel/${bsd2_pub_ip}-${bsd1_pub_ip}/require; spdadd $bsd1_net $bsd2_net any -p in ipsec esp/tunnel/${bsd1_pub_ip}-${bsd2_pub_ip}/require; eof /sbin/route add $bsd1_net $bsd2_ip ;; esac 基本的配置完成。这样在系统启动时,自动交换key,并建立tunnel。 如果喜欢采用freebsd ipsec tunnel方式连接两个局域网络 - tunnel请收藏或告诉您的好朋友.
阅读(200) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~