کارگاه پیکربندی VRF، OSPF، Subinterface و Route-Leaking با BGP#

فهرست مطالب#

  1. معرفی توپولوژی

  2. دیاگرام شبکه

  3. پیکربندی VRF

  4. پیکربندی Subinterface

  5. پیکربندی OSPF

  6. پیکربندی BGP Route-Leaking

  7. پیکربندی هاست‌ها

  8. تست و اعتبارسنجی


معرفی توپولوژی#

در این کارگاه، یک شبکه با ساختار زیر پیاده‌سازی می‌شود:

  • دو روتر: R1 و R2

  • چهار هاست: host1 (red), host2 (blue), host3 (red), host4 (blue)

  • VRF های مورد نیاز:

    • red: برای شبکه قرمز

    • blue: برای شبکه آبی

    • mgmt: برای مدیریت (یک‌طرفه - فقط دریافت از سایر VRF ها)

  • مسیرهای ارتباطی:

    • Primary Path: WireGuard + OSPF

    • Backup Path: OSPF مستقیم


دیاگرام شبکه#

                    ┌─────────────────┐
                    │  MGMT Network   │
                    │   (1.3.1.0/24)  │
                    └────────┬────────┘
                             │
                    ┌────────┴────────┐
                    │                │
              ┌─────▼─────┐    ┌─────▼─────┐
              │    R1     │    │    R2     │
              │           │    │           │
              │ VRF: red  │    │ VRF: red  │
              │ VRF: blue │    │ VRF: blue │
              │ VRF: mgmt │    │           │
              └─────┬─────┘    └─────┬─────┘
                    │                │
        ┌───────────┴──────────┐      │
        │                      │      │
   ┌────▼────┐          ┌──────▼───┐  │
   │ host1   │          │  host2   │  │
   │ (red)   │          │ (blue)   │  │
   │1.1.1.10 │          │2.1.1.10  │  │
   │ge1.100  │          │ge1.200   │  │
   └─────────┘          └──────────┘  │
                                      │
                            ┌─────────┴─────────┐
                            │                   │
                       ┌────▼────┐         ┌────▼────┐
                       │ host3   │         │ host4   │
                       │ (red)   │         │ (blue)   │
                       │3.1.1.10 │         │4.1.1.10  │
                       │ge1.100  │         │ge1.200   │
                       └─────────┘         └──────────┘

مسیرهای ارتباطی بین R1 و R2:
  Primary:  WireGuard (wg+ospf) - مسیر اصلی
  Backup:   OSPF مستقیم - مسیر پشتیبان (cost 100)

توضیحات دیاگرام:

  • R1: دارای سه VRF (red, blue, mgmt)

  • R2: دارای دو VRF (red, blue)

  • host1 و host3: در VRF red (VLAN 100)

  • host2 و host4: در VRF blue (VLAN 200)

  • MGMT Network: فقط در R1، دسترسی یک‌طرفه به تمام VRF ها

  • Subinterface ها:

    • ge1.100: برای VRF red (VLAN 100)

    • ge1.200: برای VRF blue (VLAN 200)

  • Route-Leaking: از red و blue به mgmt (یک‌طرفه)


پیکربندی VRF#

ایجاد VRF ها در R1#

vtysh
configure terminal

# ایجاد VRF ها
vrf red
!
vrf blue
!
vrf mgmt
!

ایجاد VRF ها در R2#

vtysh
configure terminal

# ایجاد VRF ها
vrf red
!
vrf blue
!

ایجاد Interface های VRF (Loopback)#

برای هر VRF باید یک interface loopback ایجاد شود:

در R1:

interface red
 no shutdown
 ip address 127.0.0.1/8
exit
!
interface blue
 no shutdown
 ip address 127.0.0.1/8
exit
!
interface mgmt
 no shutdown
 ip address 127.0.0.1/8
exit
!

در R2:

interface red
 no shutdown
 ip address 127.0.0.1/8
exit
!
interface blue
 no shutdown
 ip address 127.0.0.1/8
exit
!

پیکربندی Subinterface#

پیکربندی Subinterface در R1#

Subinterface ها برای جداسازی VLAN ها و اتصال به هاست‌ها استفاده می‌شوند:

# Subinterface برای VRF red (VLAN 100)
interface ge1.100
 encapsulation dot1q 100 exact
 no shutdown
 ip vrf forwarding red
 ip address 1.1.1.1/24
exit
!

# Subinterface برای VRF blue (VLAN 200)
interface ge1.200
 encapsulation dot1q 200 exact
 no shutdown
 ip vrf forwarding blue
 ip address 2.1.1.1/24
exit
!

# Interface برای MGMT VRF
interface ge5
 no shutdown
 ip vrf forwarding mgmt
 ip address 1.3.1.1/24
exit
!

پیکربندی Subinterface در R2#

# Subinterface برای VRF red (VLAN 100)
interface ge1.100
 encapsulation dot1q 100 exact
 no shutdown
 ip vrf forwarding red
 ip address 3.1.1.1/24
exit
!

# Subinterface برای VRF blue (VLAN 200)
interface ge1.200
 encapsulation dot1q 200 exact
 no shutdown
 ip vrf forwarding blue
 ip address 4.1.1.1/24
exit
!

نکات مهم:

  • encapsulation dot1q <vlan-id> exact: برای تگ‌گذاری VLAN

  • هر Subinterface باید به VRF مربوطه اختصاص داده شود

  • IP address باید در subnet مربوط به VRF باشد


پیکربندی OSPF#

پیکربندی OSPF در R1#

OSPF برای VRF red#

router ospf vrf red
 redistribute connected
 redistribute static
 redistribute bgp
 network 1.1.1.0/24 area 0
exit
!

OSPF برای VRF blue#

router ospf vrf blue
 redistribute connected
 redistribute static
 redistribute bgp
 network 2.1.1.0/24 area 0
exit
!

تنظیم Cost برای Interface (برای Backup Path)#

اگر می‌خواهید cost را برای interface تنظیم کنید:

# برای interface در VRF red
interface ge1.100
 ip ospf cost 100
exit
!

# برای interface در VRF blue
interface ge1.200
 ip ospf cost 100
exit
!

پیکربندی OSPF در R2#

# OSPF برای VRF red
router ospf vrf red
 redistribute connected
 network 3.1.1.0/24 area 0
exit
!

# OSPF برای VRF blue
router ospf vrf blue
 redistribute connected
 network 4.1.1.0/24 area 0
exit
!

پیکربندی WireGuard برای Primary Path (در R1)#

# WireGuard interface برای VRF red
interface wireguard100
 no shutdown
 ip mtu 1420
 ip vrf forwarding red
 wireguard mode routing
 wireguard source 0.0.0.0
 wireguard private-key <private-key-n1-red>
 wireguard port 10100
 wireguard peer <R2-public-ip>
  public-key <R2-public-key>
  endpoint <R2-public-ip> port 10100
  vrf Public
  allowed-ip 10.16.0.2/32
 ip address 10.16.0.1/32
 ip ospf network point-to-multipoint
 ip ospf area 0
exit
!

# WireGuard interface برای VRF blue
interface wireguard200
 no shutdown
 ip mtu 1420
 ip vrf forwarding blue
 wireguard mode routing
 wireguard source 0.0.0.0
 wireguard private-key <private-key-n1-blue>
 wireguard port 10200
 wireguard peer <R2-public-ip>
  public-key <R2-public-key>
  endpoint <R2-public-ip> port 10200
  vrf Public
  allowed-ip 10.16.0.2/32
 ip address 10.16.0.1/32
 ip ospf network point-to-multipoint
 ip ospf area 0
exit
!

نکته: WireGuard برای Primary Path استفاده می‌شود و OSPF برای Backup Path.


پیکربندی BGP Route-Leaking#

هدف از Route-Leaking این است که VRF mgmt بتواند به تمام شبکه‌های موجود در VRF های red و blue دسترسی داشته باشد، اما این دسترسی یک‌طرفه است (فقط از VRF های دیگر به mgmt).

پیکربندی BGP در R1#

BGP برای VRF red#

router bgp 65000 vrf red
 !
 address-family ipv4 unicast
  redistribute connected
  redistribute static
  redistribute ospf
  rd vpn export 65000:20
  rt vpn import 65000:10
  rt vpn export 65000:20
  export vpn
  import vpn
 exit-address-family
exit
!

BGP برای VRF blue#

router bgp 65000 vrf blue
 !
 address-family ipv4 unicast
  redistribute connected
  redistribute static
  redistribute ospf
  rd vpn export 65000:30
  rt vpn import 65000:10
  rt vpn export 65000:30
  export vpn
  import vpn
 exit-address-family
exit
!

BGP برای VRF mgmt (Route-Leaking)#

این بخش کلیدی است. VRF mgmt باید Route Target های VRF های دیگر را import کند:

# ایجاد Access List برای فیلتر کردن Route ها (اختیاری)
ip access-list rmap-acl
 5 permit 1.3.1.0/24 any
!

# پیکربندی BGP برای mgmt VRF
router bgp 65000 vrf mgmt
 bgp disable-ebgp-connected-route-check
 !
 address-family ipv4 unicast
  redistribute connected
  redistribute static
  rd vpn export 65000:10
  rt vpn import 65000:20 65000:30
  rt vpn export 65000:10
  route-map vpn export rmap1
  export vpn
  import vpn
 exit-address-family
exit
!

# Route-map برای کنترل Export (اختیاری)
route-map rmap1 permit 10
 match ip address rmap-acl
exit
!

توضیحات Route Target:

  • rd vpn export: Route Distinguisher برای export

  • rt vpn import: Route Target هایی که باید import شوند (از red: 65000:20 و از blue: 65000:30)

  • rt vpn export: Route Target برای export (65000:10 برای mgmt)

  • export vpn و import vpn: فعال‌سازی VPN export/import

پیکربندی Access Control برای MGMT (اختیاری)#

برای جلوگیری از دسترسی از mgmt به سایر VRF ها:

# Access List برای deny کردن ترافیک از mgmt
ip access-list DENY-TO-MGMT
 5 deny any any
!

# Access List برای permit کردن ترافیک به mgmt
ip access-list MGMT_ALL
 5 permit any any reflect
!

# اعمال Access List روی interface mgmt
interface ge5
 ip access-group DENY-TO-MGMT out
 ip access-group MGMT_ALL in
exit
!

پیکربندی هاست‌ها#

پیکربندی host1 (red VRF)#

# در هاست (Linux)
ip link add link eth0 name eth0.100 type vlan id 100
ip address add dev eth0.100 1.1.1.10/24
ip link set dev eth0.100 up
ip route add default via 1.1.1.1

پیکربندی host2 (blue VRF)#

# در هاست (Linux)
ip link add link eth0 name eth0.200 type vlan id 200
ip address add dev eth0.200 2.1.1.10/24
ip link set dev eth0.200 up
ip route add default via 2.1.1.1

پیکربندی host3 (red VRF)#

# در هاست (Linux)
ip link add link eth0 name eth0.100 type vlan id 100
ip address add dev eth0.100 3.1.1.10/24
ip link set dev eth0.100 up
ip route add default via 3.1.1.1

پیکربندی host4 (blue VRF)#

# در هاست (Linux)
ip link add link eth0 name eth0.200 type vlan id 200
ip address add dev eth0.200 4.1.1.10/24
ip link set dev eth0.200 up
ip route add default via 4.1.1.1

تست و اعتبارسنجی#

بررسی وضعیت VRF ها#

# در R1
show vrf
show ip vrf

بررسی OSPF Neighbors#

# در R1
show ip ospf neighbor vrf red
show ip ospf neighbor vrf blue
show ip ospf route vrf red
show ip ospf route vrf blue

بررسی BGP Routes#

# در R1
show ip bgp vrf red
show ip bgp vrf blue
show ip bgp vrf mgmt

# بررسی Route-Leaking
show ip bgp vrf mgmt
# باید route های red و blue را ببینید

تست Connectivity#

از host1 به host3 (هر دو در red VRF)#

# در host1
ping 3.1.1.10

از host2 به host4 (هر دو در blue VRF)#

# در host2
ping 4.1.1.10

از MGMT به تمام هاست‌ها (Route-Leaking)#

# در MGMT network
ping 1.1.1.10  # host1 (red)
ping 2.1.1.10  # host2 (blue)
ping 3.1.1.10  # host3 (red)
ping 4.1.1.10  # host4 (blue)

بررسی Route Table#

# در R1
show ip route vrf red
show ip route vrf blue
show ip route vrf mgmt

# باید در mgmt VRF، route های red و blue را ببینید

تست یک‌طرفه بودن Route-Leaking#

# از host1 (red) نباید بتوانید به MGMT دسترسی داشته باشید
# در host1
ping 1.3.1.1  # باید fail شود

# اما از MGMT باید بتوانید به host1 دسترسی داشته باشید
# در MGMT network
ping 1.1.1.10  # باید success شود

خلاصه دستورات کلیدی#

ایجاد VRF#

vrf <vrf-name>

پیکربندی Subinterface با VLAN#

interface <interface>.<vlan-id>
 encapsulation dot1q <vlan-id> exact
 ip vrf forwarding <vrf-name>
 ip address <ip>/<mask>

پیکربندی OSPF در VRF#

router ospf vrf <vrf-name>
 redistribute connected
 redistribute bgp
 network <network>/<mask> area <area-id>

پیکربندی BGP Route-Leaking#

router bgp <as-number> vrf <source-vrf>
 address-family ipv4 unicast
  rd vpn export <as>:<value>
  rt vpn export <as>:<value>
  export vpn
 exit-address-family

router bgp <as-number> vrf mgmt
 address-family ipv4 unicast
  rt vpn import <as>:<value1> <as>:<value2>
  import vpn
 exit-address-family

نکات مهم#

  1. Route Target ها باید مطابقت داشته باشند:

    • VRF red: export با RT 65000:20

    • VRF blue: export با RT 65000:30

    • VRF mgmt: import از 65000:20 و 65000:30

  2. Route-Leaking یک‌طرفه است:

    • mgmt می‌تواند به red و blue دسترسی داشته باشد

    • red و blue نمی‌توانند به mgmt دسترسی داشته باشند

  3. Subinterface ها باید VLAN Tag داشته باشند:

    • از encapsulation dot1q استفاده کنید

    • هاست‌ها نیز باید VLAN interface داشته باشند

  4. OSPF Cost:

    • برای تنظیم اولویت مسیرها از ip ospf cost استفاده کنید

    • Cost کمتر = مسیر ترجیحی

  5. WireGuard برای Primary Path:

    • WireGuard باید در VRF مربوطه پیکربندی شود

    • OSPF روی WireGuard interface فعال شود


عیب‌یابی#

مشکل: OSPF Neighbor برقرار نمی‌شود#

# بررسی کنید:
show ip ospf interface vrf <vrf-name>
show ip ospf neighbor vrf <vrf-name>

# مطمئن شوید که:
# 1. Interface ها UP هستند
# 2. IP address ها درست هستند
# 3. Network statement درست است

مشکل: BGP Route-Leaking کار نمی‌کند#

# بررسی کنید:
show ip bgp vrf mgmt
show ip bgp vrf red
show ip bgp vrf blue

# مطمئن شوید که:
# 1. Route Target ها مطابقت دارند
# 2. export vpn و import vpn فعال هستند
# 3. Route ها در source VRF وجود دارند

مشکل: Connectivity بین هاست‌ها برقرار نیست#

# بررسی کنید:
# 1. VLAN tagging در هاست و روتر
# 2. IP address ها در subnet درست
# 3. Default gateway در هاست‌ها
# 4. Route table در روتر

جدول آدرس‌دهی IP#

دستگاه

Interface

IP Address

VRF

VLAN

R1

ge1.100

1.1.1.1/24

red

100

R1

ge1.200

2.1.1.1/24

blue

200

R1

ge5

1.3.1.1/24

mgmt

-

R2

ge1.100

3.1.1.1/24

red

100

R2

ge1.200

4.1.1.1/24

blue

200

host1

eth0.100

1.1.1.10/24

red

100

host2

eth0.200

2.1.1.10/24

blue

200

host3

eth0.100

3.1.1.10/24

red

100

host4

eth0.200

4.1.1.10/24

blue

200


کانفیگ کامل R1 (مرجع)#

# R1 Complete Configuration
hostname R1
!
vrf red
!
vrf blue
!
vrf mgmt
!
# Interfaces
interface ge1.100
 encapsulation dot1q 100 exact
 no shutdown
 ip vrf forwarding red
 ip address 1.1.1.1/24
 ip ospf cost 100
exit
!
interface ge1.200
 encapsulation dot1q 200 exact
 no shutdown
 ip vrf forwarding blue
 ip address 2.1.1.1/24
 ip ospf cost 100
exit
!
interface ge5
 no shutdown
 ip vrf forwarding mgmt
 ip address 1.3.1.1/24
exit
!
interface red
 no shutdown
 ip address 127.0.0.1/8
exit
!
interface blue
 no shutdown
 ip address 127.0.0.1/8
exit
!
interface mgmt
 no shutdown
 ip address 127.0.0.1/8
exit
!
# OSPF Configuration
router ospf vrf red
 redistribute connected
 redistribute bgp
 network 1.1.1.0/24 area 0
exit
!
router ospf vrf blue
 redistribute connected
 redistribute bgp
 network 2.1.1.0/24 area 0
exit
!
# BGP Configuration
router bgp 65000 vrf red
 !
 address-family ipv4 unicast
  redistribute connected
  redistribute static
  redistribute ospf
  rd vpn export 65000:20
  rt vpn import 65000:10
  rt vpn export 65000:20
  export vpn
  import vpn
 exit-address-family
exit
!
router bgp 65000 vrf blue
 !
 address-family ipv4 unicast
  redistribute connected
  redistribute static
  redistribute ospf
  rd vpn export 65000:30
  rt vpn import 65000:10
  rt vpn export 65000:30
  export vpn
  import vpn
 exit-address-family
exit
!
router bgp 65000 vrf mgmt
 bgp disable-ebgp-connected-route-check
 !
 address-family ipv4 unicast
  redistribute connected
  redistribute static
  rd vpn export 65000:10
  rt vpn import 65000:20 65000:30
  rt vpn export 65000:10
  export vpn
  import vpn
 exit-address-family
exit
!

کانفیگ کامل R2 (مرجع)#

# R2 Complete Configuration
hostname R2
!
vrf red
!
vrf blue
!
# Interfaces
interface ge1.100
 encapsulation dot1q 100 exact
 no shutdown
 ip vrf forwarding red
 ip address 3.1.1.1/24
exit
!
interface ge1.200
 encapsulation dot1q 200 exact
 no shutdown
 ip vrf forwarding blue
 ip address 4.1.1.1/24
exit
!
interface red
 no shutdown
 ip address 127.0.0.1/8
exit
!
interface blue
 no shutdown
 ip address 127.0.0.1/8
exit
!
# OSPF Configuration
router ospf vrf red
 redistribute connected
 network 3.1.1.0/24 area 0
exit
!
router ospf vrf blue
 redistribute connected
 network 4.1.1.0/24 area 0
exit
!

منابع و مراجع#

  • فایل‌های کانفیگ نمونه در sim/bgp-rk-4node-wg/

  • تست‌های Route-Leaking در tests/bgp/bgp-rk.robot

  • مستندات VRF در tests/vrf/

  • فایل دیاگرام: tmp.tldr


نویسنده: کارگاه بر اساس دیاگرام و کانفیگ‌های موجود در Repository
تاریخ: 2024
نسخه: 1.0