简介:kernel从Linux2.6内核开始就自带ipsec模块,即ipsec-tools,主要包括libipsec、setkey、racoon和racoonctl这个模块,setkey主要用于配置SAD(安全关联数据库)和SPD(安全策略数据库),racoon用于IKE协商,既实现了双向认证,又能建立和维护IPsec SA。下面使用psk的认证方法配置racooon。
Ipsec v1搭建,debian 7 64位Linux下编译racoon(最简单的安装方法是直接apt-get install -y racoon,然后按需配置)
1,获取源
echo "deb http://www.miroir.vbrunet.eu/debian/ stable main #contrib non-free deb-src http://www.miroir.vbrunet.eu/debian/ stable main #contrib non-free deb http://security.debian.org/ stable/updates main" >> /etc/apt/sources.listapt-get update
apt-get upgrade -yapt-get -y install build-essential fakeroot dpkg-dev
apt-get source racoon
apt-get -y build-dep racoon2,编译安装
echo "export LC_ALL=C" >> /root/.bashrc source /root/.bashrcdpkg-source -x ipsec-tools_0.8.2+20140711-2+deb8u1.dsc
cd ipsec-tools-0.8.2+20140711 fakeroot debian/rules binary dpkg -i ../ipsec-tools_0.8.2+20140711-2+deb8u1_amd64.debapt-get install init-system-helpers
dpkg -i ../racoon_0.8.2+20140711-2+deb8u1_amd64.deb3,设置配置文件
PSK
cat > /etc/racoon/psk.txt <<-EOF # Group Name Group Secret vpn gooday 前面vpn组名,后面vpn预置密钥 EOF欢迎信息(可随意写)
cat > /etc/racoon/motd <<-EOF welcome! EOFchmod 700 /etc/racoon/psk.txt
主配置文件
cat > /etc/racoon/racoon.conf <<-EOF
path pre_shared_key "/etc/racoon/psk.txt"; path certificate "/etc/racoon/certs";listen {
isakmp YOURSERVERIP [500]; 服务器外网ip isakmp_natt YOURSERVERIP [4500]; }remote anonymous {
exchange_mode aggressive, main, base; 同时支持主模式和野蛮模式 mode_cfg on; 通过modcfg获取dns配置 proposal_check obey; nat_traversal on; 开启NAT-T generate_policy unique; ike_frag on; passive on; dpd_delay 20; 死链接超时间隔proposal {
lifetime time 28800 sec; encryption_algorithm 3des; hash_algorithm md5; authentication_method xauth_psk_server; psk用户名密码认证 dh_group 2; } }sainfo anonymous {
encryption_algorithm aes, 3des, blowfish; authentication_algorithm hmac_sha1, hmac_md5; compression_algorithm deflate; }mode_cfg {
auth_source system; 系统用户名和密码认证 dns4 8.8.8.8; banner "/etc/racoon/motd"; 欢迎字符 save_passwd on; network4 192.168.10.20; vpn内网ip netmask4 255.255.255.0; pool_size 200; 最大客户端数量 pfs_group 2; } EOF4,设置iptables规则
iptables -A INPUT -p udp -–dport 500 -j ACCEPT
iptables -A INPUT -p udp --dport 4500 -j ACCEPT
iptables -t nat -A POSTROUTING -s 192.168.10.20/24 -o eth0 -j MASQUERADE
iptables -A FORWARD -s 192.168.10.20/24 -j ACCEPT
5,设置数据转发
echo 1 > /proc/sys/net/ipv4/ip_forward
sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf
6,测试
新建系统账号
useradd USER
passwd USER
7,启动服务器
racoon -F 调试模式
service racoon start 启动服务
8,Windows客户端连接测试
安装shrew site configuration
配置:
add
general选项remote host添加ip
authentication选项 method:mutual PSK + xauth,local identity type设置key identifier,keyid string设置为之前的组名vpn
credentials设置 pre shared key设置为之前的密钥gooday
保存后connect输入user:passwd回车,跳出welcome信息
显示tunnel enabled即连接成功.