Шифрование туннелей c помощью IPSEC
Tuesday, March 16, 2010 8:58:58 AM
Сетевые туннели позволяют организовать (защищённую) связь хост-хост, хост-сеть и сеть-сеть (даже если эти сети имеют разные транспортные технологии) одним соединением. Любой сетевой туннель выполняет туннелирование (tunneling) инкапсуляцию одной дейтаграммы (возможно зашифрованной) в другую.
IP-IP tunnel
Left-Side
ip tunnel add tun0 mode ipip remote 200.200.200.200 local 100.100.100.100 dev eth0
ifconfig tun0 10.0.0.1 netmask 255.255.255.252 pointopoint 10.0.0.2
ifconfig tun0 mtu 1500 up
Right-Side
ip tunnel add tun0 mode ipip remote 100.100.100.100 local 200.200.200.200 dev eth0
ifconfig tun0 10.0.0.2 netmask 255.255.255.252 pointopoint 10.0.0.1
ifconfig tun0 mtu 1500 up
GRE tunnel
Left-Side
ip tunnel add tunnel0 mode gre local 100.100.100.100 dev eth0 remote 200.200.200.200 ttl 255
ip link set tunnel0 up
ip addr add 10.0.0.1 dev tunnel0
ip route add 10.0.0.0/24 dev tunnel0
Right-Side
ip tunnel add tunnel0 mode gre local 200.200.200.200 dev eth0 remote 100.100.100.100 ttl 255
ip link set tunnel0 up
ip addr add 10.0.0.2 dev tunnel0
ip route add 10.0.0.0/24 dev tunnel0
Пример добавление в /etc/network/interfaces
auto tunnel0
iface tunnel0 inet static
address 10.0.0.1
netmask 255.255.255.255
up ifconfig tunnel0 multicast
pre-up iptunnel add tunnel0 mode gre remote 100.100.100.100 local 200.200.200.200 ttl 255
pointopoint 10.0.0.2
post-down iptunnel del tunnel0
Шифрование с помощь IpSec
Ipsec поддерживает два режима работы: transport - используется для соединение между собой двух узлов, а tunnel для соединение сетей.
Так же в Ipsec может работать с протоколом IKE, который занимается обменом ключей между узлами, но можно и использовать статические ключи.
aptitude install ipsec-tools
Пример работы Ipsec в режиме transport ( ключи статические )
/etc/ipsec-tools.conf
Left-side
flush;
spdflush;
# AH
add 100.100.100.100 200.200.200.200 ah 15700 -A hmac-md5 "1234567890123456";
add 200.200.200.200 100.100.100.100 ah 24500 -A hmac-md5 "1234567890123456";
#ESP
add 100.100.100.100 200.200.200.200 esp 15701 -E 3des-cbc "123456789012123456789012";
add 200.200.200.200 100.100.100.100 esp 24501 -E 3des-cbc "123456789012123456789012";
spdadd 100.100.100.100 200.200.200.200 any -P out ipsec
esp/transport//require;
spdadd 1200.200.200.200 100.100.100.100 any -P in ipsec
esp/transport//require;
Запускаем его.
/etc/init.d/setkey restart
Right-Side
flush;
spdflush;
# AH
add 100.100.100.100 200.200.200.200 ah 15700 -A hmac-md5 "1234567890123456";
add 200.200.200.200 100.100.100.100 ah 24500 -A hmac-md5 "1234567890123456";
#ESP
add 100.100.100.100 200.200.200.200 esp 15701 -E 3des-cbc "123456789012123456789012";
add 200.200.200.200 100.100.100.100 esp 24501 -E 3des-cbc "123456789012123456789012";
spdadd 200.200.200.200 100.100.100.100 any -P out ipsec
esp/transport//require;
spdadd 100.100.100.100 200.200.200.200 any -P in ipsec
esp/transport//require;
Запускаем его.
/etc/init.d/setkey restart
Пример работы Ipsec в режиме tunnel ( ключи статические )
Предполагается что за узлом 100.100.100.100 у нас сеть 10.200.2.0/24, а за узлом 200.200.200.200 у нас сеть 172.16.0.0/24.
Правила расчитаны, что пакеты будут ходить только из сети 10.200.2.0/24 в 172.0.0.0/24 и обратно, и именно эти пакеты будут зашифрованны с помощью Ipsec. Связь между узлами 100.100.100.100 и 200.200.200.200 останется незащищенной.
/etc/ipsec-tools.conf
Left-side
flush;
spdflush;
# AH
add 100.100.100.100 200.200.200.200 ah 15700 -m tunnel -A hmac-md5 "1234567890123456";
add 200.200.200.200 100.100.100.100 ah 24500 -m tunnel -A hmac-md5 "1234567890123456";
#ESP
add 100.100.100.100 200.200.200.200 esp 15701 -m tunnel -E 3des-cbc "123456789012123456789012";
add 200.200.200.200 100.100.100.100 esp 24501 -m tunnel -E 3des-cbc "123456789012123456789012";
spdadd 10.200.2.0/24 172.16.0.0/24 any
-P out ipsec esp/tunnel/200.200.200.200-100.100.100.100/require;
spdadd 172.16.0.0/24 10.200.2.0/24 any
-P in ipsec esp/tunnel/100.100.100.100-200.200.200.200/require;
Запускаем его.
/etc/init.d/setkey restart
Right-side
flush;
spdflush;
# AH
add 100.100.100.100 200.200.200.200 ah 15700 -m tunnel -A hmac-md5 "1234567890123456";
add 200.200.200.200 100.100.100.100 ah 24500 -m tunnel -A hmac-md5 "1234567890123456";
#ESP
add 100.100.100.100 200.200.200.200 esp 15701 -m tunnel -E 3des-cbc "123456789012123456789012";
add 200.200.200.200 100.100.100.100 esp 24501 -m tunnel -E 3des-cbc "123456789012123456789012";
spdadd 172.16.0.0/24 10.200.2.0/24 any
-P out ipsec esp/tunnel/200.200.200.200-100.100.100.100/require;
spdadd 10.200.2.0/24 172.16.0.0/24 any
-P in ipsec esp/tunnel/100.100.100.100-200.200.200.200/require;
Запускаем его.
/etc/init.d/setkey restart
Пример работы Ipsec в режиме tunnel ( обмен ключей через IKE )
Предполагается что за узлом 100.100.100.100 у нас сеть 10.200.2.0/24, а за узлом 200.200.200.200 у нас сеть 172.16.0.0/24.
Правила расчитаны, что пакеты будут ходить только из сети 10.200.2.0/24 в 172.0.0.0/24 и обратно и именно эти пакеты будут зашифрованны с помощью Ipsec. Связь между узлами 100.100.100.100 и 200.200.200.200 останется незащищенной.
aptitude install racoon
/etc/racoon/psk.txt
# IPv4/v6 addresses
100.100.100.100 testtest
200.200.200.200 testtest
Конфиги на узлах зеркальные.
/etc/racoon/racoon.conf
path pre_shared_key "/etc/racoon/psk.txt";
log debug;
listen
{
isakmp 200.200.200.200 [500];
}
remote 100.100.100.100 {
my_identifier address 200.200.200.200
exchange_mode main,aggressive;
nat_traversal off;
proposal {
encryption_algorithm 3des;
hash_algorithm md5;
authentication_method pre_shared_key;
dh_group modp1024;
}
passive off;
proposal_check obey;
verify_cert off;
lifetime time 28800 sec;
exchange_mode main;
dpd_delay 30;
}
sainfo address 10.200.2.0/24[any] any address 172.16.0.0/24[any] any {
pfs_group modp1024;
lifetime time 28800 sec;
encryption_algorithm aes;
authentication_algorithm hmac_sha1;
compression_algorithm deflate;
}
sainfo address 172.16.0.0/24[any] any address 10.200.2.0/24[any] any {
pfs_group modp1024;
lifetime time 28800 sec;
encryption_algorithm aes;
authentication_algorithm hmac_sha1;
compression_algorithm deflate;
}
Перезапускаем его
/etc/init.d/racoon restart
/etc/ipsec-tools.conf
spdadd 172.16.0.0/24 10.200.2.0/24 any
-P out ipsec esp/tunnel/200.200.200.200-100.100.100.100/require;
spdadd 10.200.2.0/24 172.16.0.0/24 any
-P in ipsec esp/tunnel/100.100.100.100-200.200.200.200/require;
Запускаем его.
/etc/init.d/setkey restart
Ссылке по теме:
http://www.opennet.ru/docs/RUS/vpn_ipsec/
http://lartc.org/howto/lartc.tunnel.html
http://besecure.ru/article/284/
http://www.ixbt.com/comm/ipsecure.shtml








Unregistered user # Monday, May 10, 2010 9:01:47 PM
Zl0 # Tuesday, May 11, 2010 10:05:08 AM
http://merlin-rterm.habrahabr.ru/blog/48276/#habracut