Соединяем два шлюза CentOS IpSec тунелем

И так, пусть у нас есть два сервера Linux CentOS 5.6(2.6.18-238.9.1.el5):

Gateway 1: реальный IP x.x.x.x внутренняя сеть 192.168.0.0/24(192.168.0.1 на шлюзе)
Gateway 2: реальный IP y.y.y.y внутренняя сеть 10.10.0.0/24(10.10.0.1 на шлюзе)

Устанавливаем ipsec-tools:

yum install ipsec-tools

На Gateway 1 в папке /etc/sysconfig/network-scripts создаем файл ifcfg-ipsec0 и редактируем его:

TYPE=IPSEC
ONBOOT=yes
IKE_METHOD=PSK
SRCGW=192.168.0.1
DSTGW=10.10.0.1
SRCNET=192.168.0.0/24
DSTNET=10.10.0.0/24
DST=y.y.y.y

создаем файл /etc/sysconfig/network-scripts/keys-ipsec0 с уникальным ключом внтури, как пример :

IKE_PSK=111222

Обязательно выставьте права:

chmod 600 /etc/sysconfig/network-scripts/keys-ipsec0

В /etc/racoon/racoon.conf :

path include «/etc/racoon»;
path pre_shared_key «/etc/racoon/psk.txt»;
path certificate «/etc/racoon/certs»; sainfo anonymous
{
pfs_group 2;
lifetime time 1 hour ;
encryption_algorithm 3des, blowfish 448, rijndael ;
authentication_algorithm hmac_sha1, hmac_md5 ;
compression_algorithm deflate ;
}
remote y.y.y.y
{
exchange_mode aggressive, main;
my_identifier address;
proposal {
encryption_algorithm 3des;
hash_algorithm sha1;
authentication_method pre_shared_key;
dh_group 2;
}
}

В файл /etc/racoon/psk.txt:

y.y.y.y 111222

Настраиваем setkey:

setkey -c << EOF
flush;
spdflush;
spdadd 192.168.0.0/24 10.10.0.0/24 any -P out ipsec esp/tunnel/y.y.y.y-x.x.x.x/require;
spdadd 10.10.0.0/24 192.168.0.0/24 any -P in ipsec esp/tunnel/x.x.x.x-y.y.y.y/require;
EOF

И преходим к настройке Iptables:

-A INPUT -p udp —dport 500 -j ACCEPT
-A INPUT -p esp -j ACCEPT
-A INPUT -p ah -j ACCEPT
 

Далее, делаем все то же самое на Gateway 2. Создаем и редактируем /etc/sysconfig/network-scripts/ifcfg-ipsec0:

TYPE=IPSEC
ONBOOT=yes
IKE_METHOD=PSK
SRCGW=10.10.0.1
DSTGW=192.168.0.1
SRCNET=10.10.0.0/24
DSTNET=192.168.0.0/24
DST=x.x.x.x

создаем файл /etc/sysconfig/network-scripts/keys-ipsec0 с уникальным ключом внтури, как пример :

IKE_PSK=111222

Обязательно выставьте права:

chmod 600 /etc/sysconfig/network-scripts/keys-ipsec0

В /etc/racoon/racoon.conf :

path include «/etc/racoon»;
path pre_shared_key «/etc/racoon/psk.txt»;
path certificate «/etc/racoon/certs»;

sainfo anonymous
{
pfs_group 2;
lifetime time 1 hour ;
encryption_algorithm 3des, blowfish 448, rijndael ;
authentication_algorithm hmac_sha1, hmac_md5 ;
compression_algorithm deflate ;
}
remote x.x.x.x
{
exchange_mode aggressive, main;
my_identifier address;
proposal {
encryption_algorithm 3des;
hash_algorithm sha1;
authentication_method pre_shared_key;
dh_group 2;
}
}

В файл /etc/racoon/psk.txt:

x.x.x.x 111222

Настраиваем setkey:

setkey -c << EOF
flush;
spdflush;
spdadd 10.10.0.0/24 192.168.0.0/24 any -P in ipsec esp/tunnel/x.x.x.x-y.y.y.y/require;
spdadd 192.168.0.0/24 10.10.0.0/24 any -P out ipsec esp/tunnel/y.y.y.y-x.x.x.x/require;
EOF

И преходим к настройке Iptables:

-A INPUT -p udp —dport 500 -j ACCEPT
-A INPUT -p esp -j ACCEPT
-A INPUT -p ah -j ACCEPT

0 thoughts on “Соединяем два шлюза CentOS IpSec тунелем

Leave a Reply

Ваш адрес email не будет опубликован. Обязательные поля помечены *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>