ipsec openswan sonicwall

Топология сети :

| 1.1.1.1 | —— | 2.2.2.2 | —- | 192.168.1.0/24 |

1.1.1.1 — Debian машина без NAT
2.2.2.2 — внешний адрес sonicwall
192.168.1.0/24 — nat за sonicwall, к которому требуется получить доступ из 1.1.1.1

Debian :
1. Ставим openswan :

apt-get update
apt-get upgrade
apt-get install openswan

2. Авторизация будет через PSK ( pre shared key )

cat /etc/ipsec.secret


1.1.1.1 2.2.2.2: PSK "mysecretkey"

3. Далее отключаем правила редиректа трафика и включаем forwarding :

root@xxx:/# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0

4. Вносим правила в iptables :

iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT
iptables -A INPUT -p esp -j ACCEPT
iptables -A INPUT -p udp -m udp --dport 500 -j ACCEPT
iptables -A INPUT -p udp -m udp --dport 4500 -j ACCEPT
iptables -A PREROUTING -s 192.168.1.0/24 -j ACCEPT
iptables -A OUTPUT -p esp -j ACCEPT
iptables -A OUTPUT -p udp -m udp --dport 500 -j ACCEPT
iptables -A OUTPUT -p udp -m udp --sport 4500 -j ACCEPT
iptables -t nat -A POSTROUTING -d 192.168.1.0/24 -j SNAT --to-source 1.1.1.1
iptables -t nat -A POSTROUTING -d 192.168.1.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -j ACCEPT --destination 192.168.1.0/255.255.255.0
iptables -t nat -A PREROUTING -j ACCEPT --source 192.168.1.0/255.255.255.0

5. Проверяем корректность настроек ( для OpenVZ также со стороны ноды делаем — https://openvz.org/IPsec )

root@xxx:/# ipsec verify
Checking your system to see if IPsec got installed and started correctly:
Version check and ipsec on-path [OK]
Linux Openswan U2.6.38/K2.6.32-042stab108.8 (netkey)
Checking for IPsec support in kernel [OK]
SAref kernel support [N/A]
NETKEY: Testing XFRM related proc values [OK]
[OK]
[OK]
Checking that pluto is running [OK]
Pluto listening for IKE on udp 500 [OK]
Pluto listening for NAT-T on udp 4500 [OK]
Two or more interfaces found, checking IP forwarding [FAILED]
Checking NAT and MASQUERADEing [OK]
Checking for 'ip' command [OK]
Checking /bin/sh is not /bin/dash [WARNING]
Checking for 'iptables' command [OK]
Opportunistic Encryption Support [DISABLED]

6. Приводим конфиг /etc/ipsec.conf к виду :

config setup
nat_traversal=yes
oe=off
nhelpers=0
virtual_private=%v4:192.168.1.0/24
plutostderrlog=/var/log/pluto.log
conn sonicwall
type=tunnel
left=1.1.1.1
leftsubnet=1.1.1.1/32
rightxauthserver=yes
leftid=1.1.1.1
right=2.2.2.2
rightid=2.2.2.2
keyingtries=0
pfs=no
aggrmode=no
auth=esp
esp=3des-sha1
ike=3des-sha1
authby=secret
keyexchange=ike
rightsubnet=192.168.1.0/24
# This allows the VPN to come up automatically when openswan starts
auto=start
ikelifetime=8h
keylife=1h
compress=no

7. Перезагружаем :

/etc/init.d/ipsec restart

Sonicwall :
1. Создаем новое VPN подключение
2. General :

Policy Type - Site-to-Site
Authenication Method - IKE using Preshared Secret
Name - любое имя
IPSEC Primary Gateway Name or Address - 1.1.1.1
IPSEC Secondary Gateway Name or Address - 2.2.2.2
Shared secret - указываем пароль из /etc/ipsec.secret
Local IKE ID - IP Address - 2.2.2.2
Peer IKE ID - IP Address - 1.1.1.1

3. Network :

Local Networks
Choose local network from host - выбираем группу, в которой состоит 192.168.1.0/24 подсеть

Remote Networks
Choose destination network from list - выбираем или создаем группу 1.1.1.1/32

4. Proposals :

IKE Phase 1
Exchange - Main
DH Group - 5
Encryption - 3DES
Authentication - SHA1
Life Time ( seconds ) - 28800

IKE Phase 2
Protocol - ESP
Encryption - 3DES
Authentication - SHA1
Enable Perfect Forward Secrecy - Disable
Life Time ( seconds ) - 28800

5. Advanced :

Enable Keep Alive - enable
All other disable
Default LAN Gateway - 0.0.0.0

6. Применяем изменения и на странице VPN в Sonicwall должен напротив нашего соединения загореться зеленый кружок.

Tags: , ,

Leave a Reply