Saturday, April 18, 2015

Step 1- Weight ( 13 step selection routes BGP)


1- WEIGHT (Highest)
1.1 overview:
+ Wieght càng cao càng ưu tiên
+ sử dụng trên thiết bị cisco
+ mang tính chất local router, không gửi đi trong quá trình update
+ áp dụng theo chiều incoming update và ảnh hưởng outbound update
+ mặc định giá trị weight khi nhận update = 0 (không thể giảm weight trong chọn route) , và local = 32768
1.2 command modify:
+ neighbor {ip} [Weight]
+ route-map
Route-map có thể map:
_Prefix-list
_AS-path :
_ BGP attribute

Chú ý: + chỉ áp dụng theo chiều IN
  + Route not match by route-map by discarded
1.3 Test.

Ví dụ: R6 và R4 advertise 8.8.8.0/24 sang R2.

=> R2 học 8.8.8.0/24 qua 10.1.26.6 R6. best 
Xem lại 13 step chon route trong BGP:
  1. Giá trị weight =  0
  1. Local preference = 100 ( defaul = 100, để rõ ta show ip bgp 8.8.8.0 để thấy rõ hơn).
  1. As-path ==>BREAK . R2 học qua R6 có As-path ngắn hơn R4 

- Modify weight sao R2 chọn R4 như là best path tới 8.8.8.0
+  change default weight to neighbor:
 #router bgp 200
   #nei 10.1.24.4 weight 200          // modify all weight value in  route update from R4 to R2
+ sử dụng route-map
#access-list 1 permit 8.8.8.0 0.0.0.255   //match only route 8.8.8.0 and modify weight update from R4->R2
#route-map modify_weight_from_R4 permit 10
   #match ip address 1
    #set weight 100
#route-map modify_weight_from_R4 permit 20    //modify route not map by route-map by discarst
#router bgp 200
   #nei 10.1.24.4 route-map modify_weight_from_R4 permit 10 in   //chỉ áp dụng theo chiều in, nếu áp dụng theo chiều out sẽ có. Log thông báo không hỗ trợ, tuy nhiên cmd vẫn có trong config

      - Ngoài cách match ip access-list chúng ta có thể sự dụng:
  •  match ip prefix-list:
         #ip prefix-list ccie permit 8.8.8.0/24
         #route-map TST permit 10
            #mat ip address prefix-list ccie
            #Set weight 100
         #route-map TST permit 20
  • Match As-path
       #ip as-path access-list 1 permit _200$
           #route-map TST permit 10
           #ip as-path access-list 1
           #set weight 100
        #route-map TST permit 20

                 => mỗi phương pháp có ưu điểm và nhược điểm riêng, nên chú ý lựa chọn phù hợp theo yêu cầu.

Saturday, April 11, 2015

OSPF problem when config summary network with virtual-link

Topology:



- R1 create 3 loopback network then advertise into ospf area 0.
 lo0: 1.1.0.1/24
 lo1: 1.1.1.1/24
 lo2: 1.1.2.1/24

- Advertise loopback0 network R4 into ospf area 2.
- verify R1:

- Because area 2 are discontigous Non-AREA .router in area 0 havent route loopback R4.
- Config virtual-link btw R2 and R4 are slove problem.
                                 R2#
                                       router ospf 1
                                       area 1 virtual-link 4.4.4.4
                                 R4#
                                        router ospf 1
                                        area 1 virtual-link 2.2.2.2
=> Neighbor btw R2 and R4 over virtual-link up.
- in R2, summary 3 network learn via R1 into area 1.
                                                                         1.1.0.0/24
                                                                         1.1.1.0/24
                                                                         1.1.2.0/24
                                      => summary route: 1.1.0.0/22
                               R2#
                                     router ospf 1
                                     are 0 range 1.1.0.0 255.255.252.0
- verify R3:


=> we have problem, 3 network advertise by R1 are not summary.

WHY ???
Area 1 should be transit and carry a virtual link and area 0 prefixes should be summarized in the transit area. Per OSPF functionality, it is impossible to summarize prefixes entering a transit area, as this may result in routing loops. Therefore, summarization requirement and virtual link do not work together well.
This solution to this problem is using a tunnel in area 0 as opposed to a virtual-link. The tunnel will encapsulate transit packets and hide them from R3, therefore preventing any possible forwarding loops due to summarization
R2#
router ospf 1
 no area 1 virtual-link 4.4.4.4
 area 0 range 1.1.0.0 255.255.252.0
!
interface Tunnel0
 ip address 192.168.24.2 255.255.255.0
 ip ospf 1 area 0
 tunnel source 10.1.23.2
 tunnel destination 10.1.34.4

R4#
router ospf 1
 no area 1 virtual-link 2.2.2.2
 area 0 range 1.1.0.0 255.255.252.0 not-advertise
!
interface Tunnel0
 ip address 192.168.24.4 255.255.255.0
 ip ospf 1 area 0
 tunnel source 10.1.34.4
 tunnel destination 10.1.23.2

- Verify R3:

Thursday, April 9, 2015

NAT over MPLS VPN

Step 1: config MPLS VPN
 - network: 10.1.xy.0/24
 - loopback address: x.x.x.0/24
 - R2, R3, R4 core MPLS. running ospf are 0.
 - R2 and R4 establish M-BGP
Step 2: config nat on R4.
R4#
interface Loopback1
 ip vrf forwarding VPN
 ip address 44.44.44.44 255.255.255.0
 ip nat outside
 ip virtual-reassembly
!
interface FastEthernet0/0
 ip vrf forwarding VPN
 ip address 192.168.45.4 255.255.255.0
 ip nat inside
 ip virtual-reassembly
 duplex auto
 speed auto
!
interface Serial0/0
 ip address 10.1.34.4 255.255.255.0
 ip nat outside
 ip virtual-reassembly
 ip ospf 1 area 0
 mpls ip
!
ip route vrf VPN 5.5.5.5 255.255.255.255 FastEthernet0/0 192.168.45.5
!
ip nat inside source list 1 interface Loopback1 vrf VPN overload
!
access-list 1 permit 5.5.5.5
-------------------------------------------------------------------------------------------
R5# 
interface FastEthernet0/0
 ip address 192.168.45.5 255.255.255.0
!
ip forward-protocol nd
ip route 0.0.0.0 0.0.0.0 FastEthernet0/0 10.1.45.4

Step 3: verify
R5#ping 1.1.1.1 so l0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 1.1.1.1, timeout is 2 seconds:
Packet sent with a source address of 5.5.5.5
!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 32/46/84

R4#debug ip nat
Mar  1 00:38:42.427: NAT*: s=5.5.5.5->44.44.44.44, d=1.1.1.1 [70]
*Mar  1 00:38:42.507: NAT*: s=1.1.1.1, d=44.44.44.44->5.5.5.5 [70]
*Mar  1 00:38:42.535: NAT*: s=5.5.5.5->44.44.44.44, d=1.1.1.1 [71]
*Mar  1 00:38:42.559: NAT*: s=1.1.1.1, d=44.44.44.44->5.5.5.5 [71]
*Mar  1 00:38:42.575: NAT*: s=5.5.5.5->44.44.44.44, d=1.1.1.1 [72]
*Mar  1 00:38:42.583: NAT*: s=1.1.1.1, d=44.44.44.44->5.5.5.5 [72]
*Mar  1 00:38:42.603: NAT*: s=5.5.5.5->44.44.44.44, d=1.1.1.1 [73]
*Mar  1 00:38:42.631: NAT*: s=1.1.1.1, d=44.44.44.44->5.5.5.5 [73]
*Mar  1 00:38:42.655: NAT*: s=5.5.5.5->44.44.44.44, d=1.1.1.1 [74]
*Mar  1 00:38:42.667: NAT*: s=1.1.1.1, d=44.44.44.44->5.5.5.5 [74]
R4#show ip nat translations vrf VPN
Pro Inside global      Inside local       Outside local      Outside global
icmp 44.44.44.44:14    5.5.5.5:14         1.1.1.1:14         1.1.1.1:14

Wednesday, April 1, 2015

Native vlan



Đối với 802.1Q, thì mỗi port trunk sẽ có 1 native vlan. Giá trị này có ý nghĩa như sau:
+ khi gói tin đi ra khỏi port trunk có giá trị vlan giống với native thì vlan header này sẽ bị bóc ra
+ khi gói tin đi vào port-trunk không có vlan thì switch sẽ gán thêm native vlan vào header


R1
interface FastEthernet0/0
 ip address 10.1.12.1 255.255.255.0
R2
interface FastEthernet0/0
 ip address 10.1.12.2 255.255.255.0
R3
interface FastEthernet1/0
 switchport access vlan 10
!
interface FastEthernet1/1
 switchport mode trunk

R1 không thể ping đến 10.1.12.2

Giải thích như sau:
R1 ping 10.1.12.2 gói tin ra đền f1/0 R3 sẽ tag vlan 10 và được đẩy ra trunk qua cổng f1/1. Nhưng khi gói tin về, gói tin sẽ đi untag đi vào f1/1 và sẽ tag native vlan (default vlan 1) --> gói tin bị drop tai R3
 => solution: sử dụng " switchport trunk native vlan 10" ở port f1/1 để SW tag vlan 10 vào gói tin => gói tin sẽ được đẩy ra int f1/0

BGP filter

             * Một số tool filter trong BGP:

  1. AS-Path List
  2. Distribute-list
  3. Prefix-list
  4. Distance
  5. Route-map


                   1. AS-Path List .
    + filter các route dựa trên thuộc tính AS mà mỗi route luôn mang theo khi update
    + filter route được update  hoặc update tới các peer trước khi đưa lên bảng BGP RIB

    Ưu điểm:
    + không tạo black hole.
    + giảm hiệu suất làm việc CPU.
    Nhược điểm:
    + không filter được route mong muốn. (filter cả AS path)

    • AS-Path List là một danh sách mô tả các hoạt động Permit hoặc Deny với điều kiện match là thuộc tính AS mà mỗi route mang theo được mô tả bởi các Regular Expression
    • Regular Expression  là hệ thống chuẩn các biểu diễn các kí tự “string”. Sau đây là một số biểu diễn mà chúng ta hay dùng:
      • _100_      Những Route đi qua AS 100
      • ^100&    Bắt đầu và kết thúc bằng AS 100. Có thể hiểu là AS nhận  được route này kết nối trực tiếp với AS 100. (Route chưa đi qua AS nào khác)
      • _100$     Route có nguồn gốc là AS 100
      • ^100_      Bắt đầu là AS 100
      • ^*            Route Local AS
      • .*              Match tất cả

    Ví dụ: R3 filter mạng 8.8.8.0/24 từ R1 quảng bá sang.



    Cấu hình R3:

    #ip as-path access-list 1 deny _100$
    #router bgp 300
    # neighbor 10.1.13.1 filter-list 1 in                                 // filter truoc khi dua len BGP RIB



                 ================================================================
     2. Distribute-list.
    + áp dụng:
    + trong command neighbor: neighbor a.b.c.d distribute-list {}       //chỉ filter route từ      neighbor update sang
    + trong mode router: (config-router)#distribute-list { }                 //filter tất cả các route match access-list  từ các neighbor update sang, nếu định nghĩa thêm interface trong cmd trên, thì cmd filter không có ý nghĩa. Bởi vì BGP thiết lập dựa vào TCP, nó không quan tâm đến interface
    + filter chính xác từng route mong muốn với "deny" và không "permit"
    • distribute-list +  access-list standard.
      • Hoạt động hầu như được tất cả các trường hợp
      • Nhược điểm khi áp dụng filter supernet nó lại filter các mạng có địa chỉ mạng giống nhau nhưng subnet nhỏ hơn
    Ví dụ: mạng 8.8.1.0/24-8.8.31.0/24
    8.8.0.0/19
    • Khi dùng ACL standard filter 8.8.0.0/19 thì các mạng8.8.1.0/24 – 8.8.31.0/24 đều bị filter .
    • Distribute-list + access-list extended
      • Để giải quyết vấn đề bất cập khi filter một Supernet, ta dùng ACL Extended thay thế cho ACL Standard.
      • Cấu hình ACL Extended như sau:
      • Source Add + Wildcard mask là mạng (prefix) muốn filter.
      • Des Add         - Netmask của Prefix trên.
      • Wildcardmask    - Biểu diễn số  “netmask” cần biểu diễn. ( Có thể hiểu nó là wildcard-mask của Netmask)
    + Chú ý: Distribute – list không kết hợp được với IP Prefix List trong cmd Neighbor  

    Ví dụ1: filter 8.8.8.0/24 trên R3 từ R1 advertise sang.


    Config R3:
    access-list 1 deny   8.8.8.0 0.0.0.255
    access-list 1 permit any
    !        
    router bgp 300
    distribute-list 1 in Serial0/0



    • Như đã đưa ra ở trên, khi command distribute-list định nghĩa thêm interface áp dụng, thì quá trình filter sẽ không thực hiện. 

    Config R3:
    access-list 1 deny   8.8.8.0 0.0.0.255
    access-list 1 permit any
    !        
    router bgp 300
    distribute-list 1 in


    • Khi thay đổi cmd như trên thì R3 filter mạng 8.8.8.0/24 . Tuy nhiên nó đã filter tất cả các route match với access-list. Như trên là filter 8.8.8.0/24 từ R1 và R2 gửi sang.
    • Để tránh trường hợp này, ta sử dụng distribute-list theo chiều "out" trên R1 hoặc áp dụng
    distribute-list trong command: neighbor {} {}

    Config R1:
    Cách 1.
    access-list 1 deny   8.8.8.0 0.0.0.255
    access-list 1 permit any
    !
    router bgp 100
    distribute-list 1 out      
      // tương tự với trường hợp trên, khi chỉ rõ interface thì quá trình filter không    thực hiện được

    Cách 2.
    access-list 1 deny   8.8.8.0 0.0.0.255
    access-list 1 permit any
    !
    neighbor 10.1.13.1 distribute-list 1 out    // TH distribute-list không áp dụng được với ip prefix-list
    // có thể áp dụng chiều in theo R3
    // mỗi cách có ưu nhược điểm, tuy trường hợp ta sử dụng cho hợp lý.


     Ví dụ 2: trên R1 tạo l1: 8.8.1.8/24 và 8.8.31.8/24 . Trên R3 ta tiến hành filter mạng 8.8.0.0/19.


    Config R3:
    access-list 1 deny   8.8.0.0 0.0.31.255
    access-list 1 permit any
    !
    router bgp 300
    distribute-list 1 in


    • Ta thấy 2 mạng 8.8.1.0/24 và 8.8.31.0/24 đã bị filter. Khi sử dụng access-list standard nó không filter chính xác mask mong muốn. Để tránh trường hợp này ta sử dụng access-list extended.

    Ví dụ 3. filter mạng 8.8.1.0/24 trên R3, sử dụng ip access-list extended

    Config R3:
    access-list 100 deny   ip  8.8.1.0 0.0.0.255  255.255.255.0 0.0.0.255
    access-list 100 permit ip any any
    !
    router bgp 300
     distribute-list 100 in



    Hoặc sử dụng distribute-list +  ip prefix-list để filter dễ dàng hơn ( chú ý ip prefix không thực hiện được trong cmd neighbor+distribute-list)
    permit ip 10.0.0.0 0.0.0.0 255.255.0.0 0.0.0.0 - matches 10.0.0.0/16 - Only
    permit ip 10.0.0.0 0.0.0.0 255.255.255.0 0.0.0.0  - matches 10.0.0.0/24 - Only
    permit ip 10.1.1.0 0.0.0.0 255.255.255.0 0.0.0.0 - matches 10.1.1.0/24 - Only
    permit ip 10.0.0.0 0.0.255.0 255.255.255.0 0.0.0.0 - matches 10.0.X.0/24 - Any number in the 3rd octet of the network with a /24 subnet mask.
    permit ip 10.0.0.0 0.255.255.0 255.255.255.0 0.0.0.0 - matches 10.X.X.0/24 - Any number in the 2nd & 3rd octet of the network with a /24 subnet
    mask.
    permit ip 10.0.0.0 0.255.255.255 255.255.255.
    240 0.0.0.0 -matches 10.X.X.X/28 - Any number in the 2nd, 3rd & 4th octet of the network
    with a /28 subnet mask.
    permit ip 10.0.0.0 0.255.255.255 255.255.255.0 0.0.0.255 -Matches 10.X.X.X/24 to 10.X.X.X/32 - Any number in the 2nd, 3rd & 4th octet of
    the network with a /24 to /32 subnet mask.
    permit ip 10.0.0.0 0.255.255.255 255.255.255.128 0.0.0.127 -Matches 10.X.X.X/25 to 10.X.X.X/32 - Any number in the 2nd, 3rd & 4th octet of
    the network with a /25 to /32 subnet mask


         ================================================================
    3. Prefix - list .
      • Là một option trong cmd Neighbor. Dùng đề filter route update từ 1 peer hoặc filter route trước khi gửi update.
      • Là danh sách các Prefix – list với các Prefix với các tiêu chuẩn permit/deny

     * nguyen ly hoat dong tuong tu nhu tool filter distribute list:

    Ví dụ: R3 filter 8.8.1.0/24

    Config R3:
    ip prefix-list an seq 5 deny 8.8.8.0/24
    !
    Router bgp 300
    Neighbor 10.1.13.1 prefix-list in

    Một số trường hợp đặc biệt cần chú ý:

    ip prefix-list A permit 0.0.0.0/0 ge 32  -               Matches all hosts routes
    ip prefix-list B permit 0.0.0.0/1 ge 8    - Any subnets in Class A address space (/1: 1st bit(0) can’t change) ip prefix-list C
     ip permit 128.0.0.0/2 ge 16  - Any subnets in Class B address space (/2: 1st 2 bits(10) can’t change)
    ip prefix-list D permit 192.0.0.0/3 ge 24  - Any subnets in Class C address space (/3: 1st 3 bits(110) can’t change)
    ip prefix-list E permit 0.0.0.0/0 le 32   - Match any/all routes
    ip prefix-list F permit 0.0.0.0/0   - Match just the default route ip prefix-list G permit 0.0.0.0/1 le 24  - Matches any iprefix in Class A address space with more than 256 addresses
     ip prefix-list H permit 10.0.0.0/8  - Matches only a 10.0.0.0/8 route (no more, no less)
     ip prefix-list I permit 10.0.0.0/8 le 32  - Matches any route in the RFC-1918 pvt 10/8 range (including 10.1.2.0/24)
      ip prefix-list J permit 172.16.0.0/12 le 32  - Matches any route in the RFC-1918 pvt 172.16/12 range
     ip prefix-list K permit 192.168.0.0/16 le 32  - Matches any route in the RFC-1918 pvt 192.168.0.0/16 range

    ============================================================
    4. DISTANCE.

    • Dùng để tăng AD của một tuyến đường.  Để filter ta tăng AD = 255.
    • Nhược điểm của nó là sẽ gây ra ‘blackhole”.
    • Để phát huy công dụng của nó, ta thường sử dụng nó để tăng AD trong tiến trình Redistribute để tránh loop đồng thòi tạo Route backup
    • Distance có thể modify AD của D.Routing. Hoặc riêng từng route bằng cách kết hợp với công cụ hỗ trợ ACL o

     ví dụ. Filter mạng 8.8.1.0/24 trên R3 sử dụng distance

    Config R3:
    Access-list 1 permit 8.8.1.0 0.0.0.255
    !
    Router bgp 300
    Distance 255 10.1.13.1 0.0.0.0 1






    Kết luận: ngoài những tool cơ bản trên chúng ta có thể sử dụng route-map, aggregate-route…