Showing posts with label RIP. Show all posts
Showing posts with label RIP. Show all posts

Wednesday, November 16, 2011

[Juniper] Routing Policy and RIP protocol on Junos OS


1.Routing policy là gì?

Routing table là nơi chứa thông tin các routes mà router học được. Quá trình để học các routes của router có thể diễn ra bằng nhiều cách: static, dynamic,... Ngoài ra router còn quảng bá các thông tin định tuyến của nó cho các routers khác. Quá trình learn-to-share này của router nhằm mục đích chính là làm cho toàn bộ router trong hệ thống mạng sẽ có cái nhìn toàn diện và đầy đủ nhất về mạng.

Mỗi giao thức có một cách riêng để xem xét và xử lý thông tin về route. Trong một hệ thống mạng thì không thể chỉ sử dụng một giao thức, mà sẽ sử dụng nhiều giao thức, tùy thuộc vào yêu cầu của công tác quản trị. Do đó, các thông tin đến và đi khỏi router cũng cần phải được lọc, khồn phải lúc nào ta cũng dùng những thứ mặc định của giao thức.

Routing policy (RP) điều khiển luồng vận chuyển các thông tin định tuyến đến và đi khỏi routing table. Sử dụng RP ta có thể làm các thao tác accept, reject, modify attributes của các routes:
  • -Nhận được từ các dynamic protocol.
  • -Được gửi tới các dynamic protocol.
  • -Được ghi vào forwarding table.


Với những mục đích trên của các routes thì RP có 2 hướng để áp dụng là export và import. Export được sử dụng để áp dụng cho các route đi ra khỏi routing table. Import được sử dụng để dành cho các hoạt động đi vào routing table.


2.Routing Policy mặc định của các giao thức

Mỗi một giao thức có một RP mặc định. RP mặc định của giao thức là cách mà giao thức đó xử lý thông tin routing khi chưa bị áp dụng RP. RP mặc định của một số giao thức:

Protocol Import Export
RIP chấp nhận tất cả các routes được quảng bá từ neighbor và đưa vào inet.0 Không quảng bá routes ra ngoài.
OSPF Chấp nhận tất cả các routes được quảng bá Quảng bá tất cả các routes đã được học bởi OSPF
BGP Chấp nhận tất cả các BGP routes đang active. Đưa vào inet.0 (IPv4) và đưa vào inet6.0 (IPv6) Quảng bá mọi BGP routes đang active


3.Xây dựng Routing Policy

Trước hết ta sẽ tìm hiểu thành phần của RP. Một RP chứa một hoặc nhiều term. Term là các mệnh đề được xây dựng để lọc các giá trị điều kiện, sử dụng kết quả lọc này để áp dụng các hành đối xảy ra với đối tượng.

Mệnh đề term gồm 2 vế chính. Vế đưa ra điều kiện để so sánh là from, vế đưa ra các hành động cho đối tượng là then.

Đối với một RP có nhiều term thì các term sẽ được xử lý theo thứ tự từ trên xuống. Nên lưu ý thứ tự sắp xếp các term đề việc lọc được đúng.

3.1.Các điều kiện để lọc – Match conditions

Trong term thì vế from sẽ đưa ra các tình huống để so sánh. Các thông tin định tuyến sẽ được lọc với điều kiện này. Các điều kiện này thường liên quan đến:
  • -Prefix ( route-filter hoặc prefix-list)
  • -Protocol (OSPF, BGP, static, RIP...)
  • -Các thuộc tính của protocol: OSPF area ID, AS path, community
  • -Next-hop


Nếu không có vế from thì tất cả các routes sẽ được lọc.  

  • +Prefix-list là một list các prefix được cấu hình trong mode [edit policy-options]. Có thể được sử dụng bởi firewall filters và routing policy terms. Ví dụ:


[edit policy-options]
user@router# show
prefix-list rfc1918 { <-- định nghĩa một prefix-list tên là rfc1918
10.0.0.0/8;
172.16.0.0/12; <-- các prefix trong list
192.168.0.0/16;
}
  • +Route filter lọc các routes bên trong một polic. TRong một term có thể sử dụng nhiều route-filter. Route-filter không thể tái sử dụng hoặc một thành phần bên ngoài sử dụng như prefix-list.


Ví dụ sử dụng prefix-list ở trên với vế from:

policy-statement policy-1 {
from {
prefix-list rfc1918; <-- điều kiện lọc
}
then reject; <-- hành động áp dụng với các routes khớp điều kiện trên

Các điều kiện có thể được sử dụng sau mệnh đề from:

[edit policy-options]
user@Junos# set policy-statement new-policy from ?
Possible completions:
  aggregate-contributor  Match more specifics of an aggregate
+ apply-groups         Groups from which to inherit configuration data
+ apply-groups-except  Don't inherit configuration data from these groups
  area                 OSPF area identifier
+ as-path              Name of AS path regular expression (BGP only)
+ as-path-group        Name of AS path group (BGP only)
  color                Color (preference) value
  color2               Color (preference) value 2
+ community            BGP community
+ condition            Condition to match on
> external             External route
  family               
  instance             Routing protocol instance
+ interface            Interface name or address
  level                IS-IS level
  local-preference     Local preference associated with a route
  metric               Metric value
  metric2              Metric value 2
  metric3              Metric value 3
  metric4              Metric value 4
> multicast-scope      Multicast scope to match
+ neighbor             Neighboring router
+ next-hop             Next-hop router  
  next-hop-type        Next-hop type
  origin               BGP origin attribute
+ policy               Name of policy to evaluate
  preference           Preference value
  preference2          Preference value 2
> prefix-list          List of prefix-lists of routes to match
> prefix-list-filter   List of prefix-list-filters to match
+ protocol             Protocol from which route was learned
  rib                  Routing table
> route-filter         List of routes to match
  route-type           Route type
> source-address-filter  List of source addresses to match
  state                Route state
+ tag                  Tag string
  tag2                 Tag string 2

3.2.Các hành động áp dụng

Một số hành động được áp dụng:
  • -Các hành động kết thúc policy: accept, reject
  • -Các hành động kiểm soát hướng: next term, nex policy
  • -Các hành động chỉnh sửa thuộc tính: community (dành cho BGP), preference


3.3.Xây dựng Routing Policy

Để có được một RP hoàn chỉnh cần thực hiện 2 bước chính:
  • -Xây dựng RP theo yêu cầu
  • -Áp dụng RP (import hay export) phụ thuộc vào từng level

RP được cấu hình dưới mode [edit policy-options]:
Ví dụ:
Xây dựng RP với các term

[edit policy-options]
user@router# show
policy-statement my-policy { <-- định nghĩa policy tên là my-policy
term accept-local-route {
from {
protocol direct;  <-- điều kiện là match các route directly connected và interface ge-0/0/0
interface ge-0/0/0;
}
then accept;
}
term accept-some-static-routes {
from {
protocol static;
route-filter 172.18.1.0/24 exact; <-- chỉ lọc đúng 172.18.1.0/24
route-filter 172.18.2.0/24 exact;
}
then accept;
}
term accept-rip-routes {
from protocol rip;
then accept;
}
}

Áp dụng RP vào giao thức OSPF

[edit protocols ospf]
user@router# show
export my-policy; <-- export policy
area 0.0.0.0 {
interface ge-0/0/1.0;
interface ge-0/0/2.0;
interface ge-0/0/3.0 {
passive;
}
interface lo0.0;
}

4.Xây dựng một Routing Policy hoàn chỉnh

Sau khi đã nắm được các khái niệm trong RP, ta sẽ đi làm một ví dụ cụ thể về RP. Sử dụng giao thức RIP để minh họa.

Như đã nêu ở trên, mặc định thì RIP sẽ không quảng bá bất cứ route nào của nó tới neighbor. Ta sẽ phân tích từng thành phần trong RP này. Yêu cầu là đã cấu hình bật chức năng RIP trên từng router.

Trước hết cần xác định xem mục đích của RP này là gì. Giả sử ta sẽ đặt tên của Policy này là rip-policy.
Policy này sẽ áp dụng lọc các route do giao thức RIP đưa ra đồng thời quảng bá các connected routes. Như vậy điều kiện để lọc ở đây là dựa trên mặt giao thức, cụ thể là RIP. Ta sẽ xây dựng vế from như sau:

from protocol rip direct

mục đích là sẽ đồng ý để RIP quảng bá các route ra ngoài, mệnh đề then sẽ là accept

then accept

Như vậy, rip-policy sẽ có nội dung:


Lưu ý rằng dấu [] là để chỉ phép toán OR. [a b] hoặc a hoặc b hoặc cả a và b.

 Sau khi đã xây dựng rip-policy, ta sẽ áp dụng policy này. Ở đây sẽ áp dụng cho giao thức RIP.


 Như vậy, policy này sẽ nói cho giao thức RIP biết rằng: "mọi routes học được từ RIP và các connected routes sẽ được quảng bá (export) ra ngoài”.

Wednesday, October 26, 2011

Overviews of Routing Information Protocol – RIP

1.Overview of RIP

 RIP is a standard protocol, but in this post, i want to introduce some knowledges relate to Junos OS

 RIP is a dynamic routing protocol operates within a Routing Domain (IGP). It uses the distance vector algorithm to determine the best route to a destination. The distance is measured in hops, which is a number of router that a packet must pass to reach the destination. The best route is the route with the lowest of hops. In routing table, RIP maintains two informations:

  • IP address of the destination network
  • and the hop count (metric) to that destination. 


 RIP v1 routers exchange their routing information by broadcasting RIP route information every 30 minutes. RIP uses UDP packets for all transactions with port number 520

 2.Routing loops in RIP 

 A problem of the most dynamic routing protocol is routing loop that provides the incorrect routing information. RIP uses two methods to control this problem:
 -Split horizon: when a device receives the route advertisement on an interface, it will not readvertise back that information on the earlier interface.

In the figure above, Router Z advertises route 10.1.1.0/24 to router C and increases 1 in the metric. At this time, router C knows that the metric to reach to 10.1.1.0 is 1. And router C does not advertise this information back to router Z since it received from router Z. And so on, router A and B receive information from router C and increase the metric by 1 and again, do not advertise back to router C.

-Poison reverse: when a RIP device knows a route is no longer connected or reachable, it will advertises that route with an infinite value of metric (16). With this information, each RIP device treats that route is unreachable and never advertise information about that route.

Junos software default supports all above functions.

3.Limitations of RIP

-RIP can be used only in a small network. Because the infinite of hops are 16.
-RIPv1 only uses classful routing. It can not handle the subnet and mask informations
-RIPv1 only uses plain-text password authentication which can be easily sniffed in the insecured network.

4.RIPv2

RIPv2 was developed to increase the security in RIP. It supports CIDR and MD5 authentication. The limitation of 15 hops was remained.

By default, Junos RIP only listens to RIP updates. The router does not advertise the updates until you tell it to do. This is done by setting up the routing policy.

5.Configuring RIP on Junos OS

I use Junos Olive running on VMware to emulate in this guide


5.1.Basic RIP configuration

Diagram:


Configuration on each router:

[edit protocols rip]
cuong@Jun1# show
group rip-group { <- define a rip group 
export rip-policy; <- a routing policy to advertise RIP information
neighbor em1.0; <- interfaces take part in the routing
neighbor lo0.0;
}
// routing policy allows rip advertises information

[edit policy-options]
cuong@Jun1# show 
policy-statement rip-group {
    from protocol [ rip direct ]; <- all rip/direct routes
    then accept; <-- all routes after from statement are allowed
}


[edit protocols rip]
cuong@Jun2# show
group rip-group {
export rip-policy;
neighbor em1.0;
neighbor em2.0;
}

[edit protocols rip]
cuong@Jun3# show
group rip-group {
export rip-policy;
neighbor em1.0;
neighbor lo0.0;
}


Results in each router:

cuong@Jun1> show route protocol rip

inet.0: 9 destinations, 10 routes (9 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

11.0.0.0/24 *[RIP/100] 00:06:53, metric 2, tag 0
> to 10.0.0.6 via em1.0
172.16.1.0/24 *[RIP/100] 00:06:02, metric 3, tag 0
> to 10.0.0.6 via em1.0
192.168.128.0/24 [RIP/100] 00:06:53, metric 2, tag 0
> to 10.0.0.6 via em1.0
224.0.0.9/32 *[RIP/100] 00:07:43, metric 1
MultiRecv
--
cuong@Jun2> show route protocol rip

inet.0: 9 destinations, 10 routes (9 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

172.16.1.0/24 *[RIP/100] 00:06:26, metric 2, tag 0
> to 11.0.0.6 via em2.0
192.168.2.0/24 *[RIP/100] 00:08:01, metric 2, tag 0
> to 10.0.0.5 via em1.0
192.168.128.0/24 [RIP/100] 00:08:01, metric 2, tag 0
to 10.0.0.5 via em1.0
> to 11.0.0.6 via em2.0
224.0.0.9/32 *[RIP/100] 00:07:17, metric 1
MultiRecv

--
cuong@Jun3> show route protocol rip

inet.0: 9 destinations, 10 routes (9 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

10.0.0.0/24 *[RIP/100] 00:07:36, metric 2, tag 0
> to 11.0.0.5 via em1.0
192.168.2.0/24 *[RIP/100] 00:08:23, metric 3, tag 0
> to 11.0.0.5 via em1.0
192.168.128.0/24 [RIP/100] 00:07:36, metric 2, tag 0
> to 11.0.0.5 via em1.0
224.0.0.9/32 *[RIP/100] 00:06:52, metric 1
MultiRecv

Testing routes

cuong@Jun1> ping 172.16.1.1
PING 172.16.1.1 (172.16.1.1): 56 data bytes
64 bytes from 172.16.1.1: icmp_seq=0 ttl=63 time=0.598 ms
64 bytes from 172.16.1.1: icmp_seq=1 ttl=63 time=1.002 ms
64 bytes from 172.16.1.1: icmp_seq=2 ttl=63 time=1.017 ms
^C
--- 172.16.1.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.598/0.872/1.017/0.194 ms


5.2.Enabling authentication

Using two commands to set authentication on RIP routers

[edit protocols rip]
set authentication-type md5 <-- md5 is a type of authentication, it encrypts the plain-text password

[edit protocols rip]
cuong@Jun3# set authentication-key juniper <-- juniper is a key (password), used for all RIP routers in network.

Configuration on each router:

cuong@Jun1# set rip authentication-type md5

[edit protocols]
cuong@Jun1# set rip authentication-key juniper

[edit protocols]
cuong@Jun1# show
rip {
authentication-type md5;
authentication-key "$9$R2AcrvxNboJDWLJDikTQEcy"; ## SECRET-DATA
group rip-group {
export rip-policy;
neighbor em1.0;
neighbor lo0.0;
}
}

--
cuong@Jun2# set authentication-type md5

[edit protocols rip]
cuong@Jun2# set authentication-key juniper

[edit protocols rip]
cuong@Jun2# show
authentication-type md5;
authentication-key "$9$fQ390BEevLApvLxNY25QF"; ## SECRET-DATA
group rip-group {
export rip-policy;
neighbor em1.0;
neighbor em2.0;
}

--
cuong@Jun3# set authentication-type md5

[edit protocols rip]
cuong@Jun3# set authentication-key juniper

[edit protocols rip]
cuong@Jun3# show
authentication-type md5;
authentication-key "$9$0DAq1EyM87s2alK2aZU.mO1R"; ## SECRET-DATA
group rip-group {
export rip-policy;
neighbor em1.0;
neighbor lo0.0;
}



  

Tuesday, January 11, 2011

Tìm hiểu về Distance Vector[Part1]


1.Khái niệm Distance và Vector

Thuật ngữ distance vector mô tả về cách router biết thông tin về các routes. Kết thúc quá trình, khi một router học được 1 route đến 1 subnet, tất cả những gì router biết là một vài khái niệm về distance(khoảng cách đến subnet tính bằng số lượng router đi qua-metric) và next-hop cũng như outgoing interface sử dụng để đến route đó(vector-hướng đi của packet).

Thursday, January 6, 2011

Khái niệm Administrative Distance và Metric

I.Metrics

Routing protocols sẽ chọn route nào đc đánh giá là tốt nhất(best route) đến mối subnet. Việc lựa chọn này dựa vào việc route nào có metric càng nhỏ thì được đánh giá là càng tốt.
 Với mỗi giao thức thì lại có cách đánh giá riêng về metric. Ví dụ, với RIP thì đánh giá qua số lượng router(hop count) phải đi qua để đến subnet đích. Còn đối với OSPF, EIGRP thì lại khác.