آموزش راه اندازی تونل wireguard , ipsec , vxaln و تنظیم SLA در سودار#

در این سناریو قصد داریم دو تونل ipsec , wireguard بین روتر های n4,n11 برقرار کنیم . در حالتی که هر دو تونل وصل هستند ترافیک بین 1.1.1.10 و 4.1.1.10 از طریق تونل IPSec و ترافیک بین 1.1.1.20 و 4.1.1.20 از طریق تونل wireguard منتقل می شود . برای اینکه در زمان قطع شدن هر یکی از دو تونل ارتباط host های (n5,n6,n7,n8) پشت روتر قطع نشود از SLA برای تغییر مسیر بر روی تونل متصل استفاده می کنیم . یک ارتباط لایه ۲ با استفاده از VXLAN نیز بین 192.168.100.10 , 192.168.100.40 نیز از درون تونل ها ایجاد می گردد .

tunnel-sla

حال به تنظیم روتر ها می پردازیم : از ospf برای مسیریابی بین روتر ها استفاده می کنیم :

n1(config)# interface ge0
n1(config-if)# ip address 200.1.2.1/24
n1(config-if)# q
n1(config)# interface ge1
n1(config-if)# ip address 200.1.3.1/24
n1(config-if)# q
n1(config)# interface ge2
n1(config-if)# ip address 1.1.1.1/24
n1(config-if)# q
n1(config)# router ospf
n1(config-router)# network 200.1.2.0/24 area 0
n1(config-router)# network 200.1.3.0/24 area 0
n2(config)# interface ge0
n2(config-if)# ip address 200.1.2.2/24
n2(config-if)# q
n2(config)# interface ge1
n2(config-if)# ip address 200.2.4.2/24
n2(config-if)# q
n2(config)# router ospf
n2(config-router)# network 200.1.2.0/24 area 0
n2(config-router)# network 200.2.4.0/24 area 0
n3(config)# interface ge0
n3(config-if)# ip address 200.1.3.3/24
n3(config-if)# q
n3(config)# interface ge1
n3(config-if)# ip address 200.3.11.3/24
n3(config-if)# q
n3(config)# router ospf
n3(config-router)# network 200.1.3.0/24 area 0
n3(config-router)# network 200.3.11.0/24 area 0
n4(config)# interface ge0
n4(config-if)# ip address 200.2.4.4/24
n4(config-if)# q
n4(config)# interface ge1
n4(config-if)# ip address 200.4.11.4/24
n4(config-if)# q
n4(config)# interface ge2
n4(config-if)# ip address 4.1.1.1/24
n4(config-if)# q
n4(config)# router ospf
n4(config-router)# network 200.2.4.0/24 area 0
n4(config-router)# network 200.4.11.0/24 area 0
n11(config)# interface ge0
n11(config-if)# ip address 200.3.11.11/24
n11(config-if)# q
n11(config)# interface ge1
n11(config-if)# ip address 200.4.11.11/24
n11(config-if)# q
n11(config)# router ospf
n11(config-router)# network 200.3.11.0/24 area 0
n11(config-router)# network 200.4.11.0/24 area 0

تنظیم تونل IPSec :#

تونل IPSec را بین روتر های ‌n1 , n4 از مسیر روتر n2 و تونل wireguard را از مسیر روتر n3, n11 بین روتر های n1 وn4 برقرار می کنیم .

اینترفیس ها را در vrf مربوطه قرار می دهیم (در اینجا pub برای شبکه public و دو vrf دیگر برای شبکه private استفاده می شوند):

crypto ikev2 proposal N1_IKE_PROPOSAL
 integrity sha-96
 encryption aes-256
 group 20
exit
!
crypto ikev2 profile N1_IKE_PROFILE
 keyring local N1_IKE_KEYRING
 proposal N1_IKE_PROPOSAL
 match identity remote address 222.4.4.4
 identity local address 222.1.1.1
 authentication local pre-share
 authentication remote pre-share
exit
!
crypto ikev2 keyring N1_IKE_KEYRING
 peer n2
  pre-shared-key salam!
  identity address 222.4.4.4
exit
!

crypto ikev2 proposal N4_IKE_PROPOSAL
 integrity sha-96
 encryption aes-256
 group 20
exit
!
crypto ikev2 profile N4_IKE_PROFILE
 keyring local N4_IKE_KEYRING
 proposal N4_IKE_PROPOSAL
 match identity remote address 222.1.1.1
 identity local address 222.4.4.4
 authentication local pre-share
 authentication remote pre-share
exit
!
crypto ikev2 keyring N4_IKE_KEYRING
 peer n1
  pre-shared-key salam!
  identity address 222.1.1.1
exit
!

crypto ipsec transform-set N1_TS esp hmac sha-256 cipher aes-256
 mode transport
exit
!
crypto ipsec profile N1_IPSec_PROFILE
 set transform-set N1_TS
 set ikev2-profile N1_IKE_PROFILE
 set security-association lifetime seconds 3600
exit
!

crypto ipsec transform-set N4_TS esp hmac sha-256 cipher aes-256
 mode transport
exit
!
crypto ipsec profile N4_IPSec_PROFILE
 set transform-set N4_TS
 set ikev2-profile N4_IKE_PROFILE
 set security-association lifetime seconds 3600
exit
!


ساخت تونل GRE و اعمال IPSec Profile در آن :

!
interface tunnel10
 tunnel source 200.1.2.1
 tunnel destination 200.2.4.4
 tunnel protection ipsec profile N1_IPSec_PROFILE
 ip address 10.0.0.1/24
exit
!

!
interface tunnel40
 tunnel source 200.2.4.4
 tunnel destination 200.1.2.1
 tunnel protection ipsec profile N4_IPSec_PROFILE
 no shutdown
 ip address 10.0.0.4/24
exit
!


تنظیم تونل wireguard#

قبل از ساخت تونل به نکات زیر دقت کنید :

  • یک vrf در روتر می سازیم و اینترفیس ge1 در روتر های n1,n4 را در آن vrf قرار می دهیم تا ترافیک wireguard مجبور شود از اینترفیس ge1 که در این مثال دلخواه ماست عبور کند (به صورت پیش فرض wireguard از هر طریقی که به مقصد route داشته باشد به peer وصل می شود و با آپدیت شدن جدول مسیریابی تغییر می کند)

  • در تنظیم peer هم مشخص می کنیم که برای ارتباط با peer از vrf مورد نظر استفاده کند

ساخت vrf و تنظیم اینترفیس در vrf#

n1(config)# vrf red
n1(config-vrf)# q
n1(config)# interface ge1  
n1(config-if)# ip vrf forwarding red
n1(config-if)# ip address 200.1.3.1/24
n1(config-if)# end
n1# 
n4(config)# vrf red
n4(config-vrf)# q
n4(config)# interface ge1  
n4(config-if)# ip vrf forwarding red
n4(config-if)# ip address 200.4.11.4/24
n4(config-if)# end
n4# 

ساخت کلید wg#

در ابتدا برای هر تونل یک کلید wg تولید می کنیم .

n1(config)# crypto key generate x25519 label wg1
informational-ZEBRA: new X25519 key wg1 generated

n1(config-if)# do sh crypto key wg1
Keypair Label: wg1
  Algorithm:   X25519
  Public key:  5EE66239C731B4DC99E9BA0F46D9AE028ABD5A49F98E427BB185B19BE7FBDE14
  Public key base64:  XuZiOccxtNyZ6boPRtmuAoq9Wkn5jkJ7sYWxm+f73hQ=

n4(config)# crypto key generate x25519 label wg4
informational-ZEBRA: new X25519 key wg4 generated


n4(config)# do sh crypto key wg4
  Algorithm:   X25519
  Public key:  30437B535537B1D4184A4D1F1A1AFA9EAF40173D03563E808D08C776111E4324
  Public key base64:  MEN7U1U3sdQYSk0fGhr6nq9AFz0DVj6AjQjHdhEeQyQ=

ساخت اینترفیس wireguard#

n1(config)# interface wireguard10  
n1(config-if)# wireguard mode routing
n1(config-if)# wireguard source 200.1.3.1
n1(config-if)# wireguard private-key wg1
n1(config-if)# wireguard port 2500
n1(config-if)# ip address 50.0.0.10/32
n1(config-if)# end
n1# 
n4(config)# interface wireguard40  
n4(config-if)# wireguard mode routing
n4(config-if)# wireguard source 200.4.11.4
n4(config-if)# wireguard private-key wg4
n4(config-if)# wireguard port 1400
n4(config-if)# ip address 50.0.0.40/32
n4(config-if)# end
n4# 

توجه

دقت شود تنظیم wireguard mode routing حتما انجام شود. چون در این سناریو قصد داریم از ip تونل های wireguard به عنوان gateway در SLA استفاده کنیم باید wireguard را در حالت routing استفاده کنیم به صورت پیش فرض wiregaurd بسته هایی که مبدا آن ها را نشناسد (در جدول مسیریابی خود نداشته باشد) حذف می کند و در تونل انتقال نمی دهد اما در حالت routing این سیاست اعمال نمی شود و بسته ها صورت نرمال منتقل می شوند

افزودن Wireguard peer#

n1(config)# interface wireguard10  
n1(config-if)# wireguard peer n4
n1(config-wg-peer)# public-key 30437B535537B1D4184A4D1F1A1AFA9EAF40173D03563E808D08C776111E4324
n1(config-wg-peer)# endpoint 200.4.11.4 port 1400
n1(config-wg-peer)# allowed-ip 50.0.0.40/32
n1(config-wg-peer)# vrf red
n1(config-wg-peer)# end
n1# 

n4(config)# interface wireguard40  
n4(config-if)# wireguard peer n1
n4(config-wg-peer)# public-key 5EE66239C731B4DC99E9BA0F46D9AE028ABD5A49F98E427BB185B19BE7FBDE14
n4(config-wg-peer)# endpoint 200.1.3.1 port 2500 
n4(config-wg-peer)# allowed-ip 50.0.0.10/32
n4(config-wg-peer)# vrf red
n4(config-wg-peer)# end
n4# 

مشاهده وضعیت تونل#

برای مشاهده وضعیت تونل های wirguard می توان از دستور زیر استفاده کرد:

n1# sh wireguard 
Wireguard 10
  Mode: Routing
  Source: 0.0.0.0
  Key: wg1
  Public key: 5EE66239C731B4DC99E9BA0F46D9AE028ABD5A49F98E427BB185B19BE7FBDE14
  Public-key Base64: XuZiOccxtNyZ6boPRtmuAoq9Wkn5jkJ7sYWxm+f73hQ=
  Port: 2500

  Peer n4:
    Public key: 30437B535537B1D4184A4D1F1A1AFA9EAF40173D03563E808D08C776111E4324
    Public-key Base64: MEN7U1U3sdQYSk0fGhr6nq9AFz0DVj6AjQjHdhEeQyQ=
    Preshared key: 0000000000000000000000000000000000000000000000000000000000000000
    Preshared key Base64: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
    Endpoint: 200.4.11.4
    Current Endpoint: 200.4.11.4
    Current Source: 200.1.3.1
    Persistent keepalive: 10
    Port: 1400
    Current Port: 1400
    VRF: red
    Connected: True
    Allowed IPs:
     - 50.0.0.40/32

n1#  

توجه

Connected: True مشخص می کند که تونل وصل شده است .

تنظیم static route ها با استفاده از SLA#

در اینجا از icmp-echo برای ping به IP اینترفیس تونل در طرف مقابل استفاده میکنیم تا مطمئن شویم تونل وصل است و در صورت قطع بودن با استفاده از track ها تغییراتی در جدول route اضافه کنیم و ارتباط پایدار را برای host های پشت روتر ایجاد کنیم.

تنظیم SLA#

ابتدا برای هر تونل یک SLA تنظیم می کنیم . sla1 برای تونل ipsec و sla2 برای تونل wireguard :

ip sla 1
 icmp-echo 10.0.0.4 source-ip 10.0.0.1
  frequency 7
!
ip sla 2
 icmp-echo 50.0.0.40 source-ip 50.0.0.10
  frequency 6
!
ip sla schedule 1 start-time now life forever
!
ip sla schedule 2 start-time now life forever
!

ip sla 1
 icmp-echo 10.0.0.1 source-ip 10.0.0.4
  frequency 7
!
ip sla 2
 icmp-echo 50.0.0.10 source-ip 50.0.0.40
  frequency 7
!
ip sla schedule 1 start-time now life forever
!
ip sla schedule 2 start-time now life forever
!

تنظیم track ها#

ما track ها را برای