LAB GNS3 Thực hành định tuyến OSPF

bởi | CCNP, GNS3

Home » CCNP » LAB GNS3 Thực hành định tuyến OSPF

Sơ đồ bài lab

LAB GNS3 Thực hành định tuyến OSPF

Cấu hình gán IP theo sơ đồ

– Router 1
conf t
int s 2/0
ip add 192.1.12.1 255.255.255.252
no sh
int lo 0
ip add 1.1.1.1 255.255.255.0
int lo 1
ip add 10.0.0.1 255.255.255.0
int lo 2
ip add 10.0.1.1 255.255.255.0
int lo 3
ip add 10.0.2.1 255.255.255.0
int lo 4
ip add 10.0.3.1 255.255.255.0
end

– Router 2
conf t
int s2/0
ip add 192.1.12.2 255.255.255.252
no sh
int fa 0/0
ip add 100.0.0.2 255.255.255.0
no sh
end

– Router 3
conf t
int fa 0/0
ip add 100.0.0.3 255.255.255.0
no sh
int lo 0
ip add 3.3.3.3 255.255.255.0
int lo 1
ip add 30.0.0.1 255.255.255.0
int lo 2
ip add 30.0.1.1 255.255.255.0
int lo 3
ip add 30.0.2.1 255.255.255.0
int lo 4
ip add 30.0.3.1 255.255.255.0
end

– Router 4
conf t
int fa 0/0
ip add 100.0.0.4 255.255.255.0
no sh
int lo 0
ip add 4.4.4.4 255.255.255.0
int lo 1
ip add 40.0.0.1 255.255.255.0
int lo 2
ip add 40.0.1.1 255.255.255.0
int lo 3
ip add 40.0.2.1 255.255.255.0
int lo 4
ip add 40.0.3.1 255.255.255.0
end

Cấu hình OSPF theo các miền trong sơ đồ

Cú pháp định tuyến OSPF

– Cách 1

R(config)#router ospf 1
R(config-router)#network 192.168.1.126 0.0.0.0 area 0

=> 192.168.1.126 là IP-address của interface. 0.0.0.0 là wildcard-mask tức là kiểm tra hết 32 bit.
Cách này không biết cũng làm được. Nhưng khi thay đổi IP của interface thì câu lệnh định tuyến sẽ vô tác dụng

– Cách 2

R(config)#router ospf 1

=> Số 1 là process-id
=> Số process-id gắn được từ 1 <-> 65535

R(config-router)#network test-condition wildcard-mask area area-id

=> Đưa ra điều kiện để chọn interface tham gia định tuyến OSPF. Wildcard-mask được sử dụng để lấy chính xác subnet tham gia định tuyến. area area-id chỉ rõ đường mạng tham gia OSPF sẽ thuộc về area nào.

/24: 0.0.0.255
/25: 0.0.0.127
/26: 0.0.0.63
/27: 0.0.0.31
/28: 0.0.0.15
/29: 0.0.0.7
/30: 0.0.0.3

Cách này thường dùng. Cần phải tính toán wildcard-mask

– Cách 3
Chọn interface tham gia định tuyến OSPF

R(config)#router ospf 1
R(config)#exit
R(config)#int f0/0
R(config-if)#ip ospf 1 area 0

Routing OSPF theo các miền trong sơ đồ

– Router 1: Internal Router
R1(config)#router ospf 1
R1(config-router)#network 192.1.12.0 0.0.0.3 area 1
R1(config-router)#network 10.0.0.0 0.0.3.255 area 1
R1(config-router)#network 1.1.1.0 0.0.0.255 area 1
R1(config-router)#end
– Router 2: Area Border Router
R2(config)#router ospf 1
R2(config-router)#network 192.1.12.0 0.0.0.3 area 1
R2(config-router)#network 100.0.0.0 0.0.0.255 area 0
R2(config-router)#end
– Router 3: Internal Router
R3(config)#router ospf 1
R3(config-router)#network 100.0.0.0 0.0.0.255 area 0
R3(config-router)#network 30.0.0.0 0.0.3.255 area 0
R3(config-router)#network 3.3.3.0 0.0.0.255 area 0
R3(config-router)#end
– Router 4: Internal Router
R4(config)#router ospf 1
R4(config-router)#network 100.0.0.0 0.0.0.255 area 0
R4(config-router)#network 40.0.0.0 0.0.3.255 area 0
R4(config-router)#network 4.4.4.0 0.0.0.255 are 0
R4(config-router)#end

Kiểm tra các thông số OSPF

R2#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
30.0.3.1 1 FULL/BDR 00:00:37 100.0.0.3 FastEthernet0/0
40.0.3.1 1 FULL/DROTHER 00:00:31 100.0.0.4 FastEthernet0/0
10.0.3.1 0 FULL/ - 00:00:32 192.1.12.1 Serial2/0
R2#show ip ospf interface s2/0
Serial2/0 is up, line protocol is up
Internet Address 192.1.12.2/30, Area 1, Attached via Network Statement
Process ID 1, Router ID 192.1.12.2, Network Type POINT_TO_POINT, Cost: 64
Topology-MTID Cost Disabled Shutdown Topology Name
0 64 no no Base
Transmit Delay is 1 sec, State POINT_TO_POINT
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:04
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 4, maximum is 4
Last flood scan time is 0 msec, maximum is 4 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 10.0.3.1
Suppress hello for 0 neighbor(s)
R2#show ip ospf interface f0/0
FastEthernet0/0 is up, line protocol is up
Internet Address 100.0.0.2/24, Area 0, Attached via Network Statement
Process ID 1, Router ID 192.1.12.2, Network Type BROADCAST, Cost: 1
Topology-MTID Cost Disabled Shutdown Topology Name
0 1 no no Base
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.1.12.2, Interface address 100.0.0.2
Backup Designated router (ID) 30.0.3.1, Interface address 100.0.0.3
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:01
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
Index 1/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 2, Adjacent neighbor count is 2
Adjacent with neighbor 30.0.3.1 (Backup Designated Router)
Adjacent with neighbor 40.0.3.1
Suppress hello for 0 neighbor(s)
R2#clear ip ospf process
yes
R3#clear ip ospf process
yes
R4#clear ip ospf process
yes
R2#show ip ospf interface f0/0
FastEthernet0/0 is up, line protocol is up
Internet Address 100.0.0.2/24, Area 0, Attached via Network Statement
Process ID 1, Router ID 192.1.12.2, Network Type BROADCAST, Cost: 1
Topology-MTID Cost Disabled Shutdown Topology Name
0 1 no no Base
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 192.1.12.2, Interface address 100.0.0.2
Backup Designated router (ID) 40.0.3.1, Interface address 100.0.0.4
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:04
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
Index 1/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 7
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 2, Adjacent neighbor count is 2
Adjacent with neighbor 30.0.3.1
Adjacent with neighbor 40.0.3.1 (Backup Designated Router)
Suppress hello for 0 neighbor(s)

Thay đổi giá trị Router-ID

Router-ID để định danh một router trong các router chạy OSPF. Router-ID có định dạng của một địa chỉ IP. Mặc định, tiến trình OSPF trên mỗi router sẽ tự động bầu chọn giá trị Router-ID là địa chỉ IP cao nhất trong các interface đang activate, ưu tiên cổng loopback

R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1

=> Gắn giá trị router-id cho router 1

R1(config-router)#no network 1.1.1.0 0.0.0.255 area 1
R1(config-router)#exit
R1(config)# no int lo 0

=> xoá bỏ đi interface loopback 0 — IP: 1.1.1.1
Chú ý:
+ Giá trị router-id: không nhất thiết phải là IP của 1 interface nào đó trên router
+ Giá trị router-id không được phép trùng với nhau giữa các router

R1#clear ip ospf process
yes

Kiểm tra:

R1#show ip ospf
Routing Process "ospf 1" with ID 1.1.1.1

Thêm các câu lệnh ip ospf network point-to-point ở từng interface loopback

R3#show ip route ospf
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/2] via 100.0.0.4, 00:17:48, FastEthernet0/0
10.0.0.0/32 is subnetted, 4 subnets
O IA 10.0.0.1 [110/66] via 100.0.0.2, 00:17:53, FastEthernet0/0
O IA 10.0.1.1 [110/66] via 100.0.0.2, 00:17:53, FastEthernet0/0
O IA 10.0.2.1 [110/66] via 100.0.0.2, 00:17:53, FastEthernet0/0
O IA 10.0.3.1 [110/66] via 100.0.0.2, 00:17:53, FastEthernet0/0
40.0.0.0/32 is subnetted, 4 subnets
O 40.0.0.1 [110/2] via 100.0.0.4, 00:17:48, FastEthernet0/0
O 40.0.1.1 [110/2] via 100.0.0.4, 00:17:48, FastEthernet0/0
O 40.0.2.1 [110/2] via 100.0.0.4, 00:17:48, FastEthernet0/0
O 40.0.3.1 [110/2] via 100.0.0.4, 00:17:48, FastEthernet0/0
192.1.12.0/30 is subnetted, 1 subnets
O IA 192.1.12.0 [110/65] via 100.0.0.2, 00:17:53, FastEthernet0/0

O: Các dòng route OSPF chung AREA
O IA: OSPF Inter Area: Các dòng route OSPF thuộc AREA khác

Lưu ý: Đối với router Cisco, ở giao thứcc OSPF, thì các đường route của các interface vật lý sẽ thấy đúng, các đường route của interface loopback thì sai. Để thấy đúng đường mạng theo sơ đồ thì ta phải dùng câu lệnh “ip ospf network point-to-point” ở từng interface loopback
//R1 R3 R4

int lo 0
ip ospf network point-to-point
int lo 1
ip ospf network point-to-point
int lo 2
ip ospf network point-to-point
int lo 3
ip ospf network point-to-point
exit
R3#show ip route ospf
4.0.0.0/24 is subnetted, 1 subnets
O 4.4.4.0 [110/2] via 100.0.0.4, 00:01:56, FastEthernet0/0
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
O IA 10.0.0.0/24 [110/66] via 100.0.0.2, 00:02:29, FastEthernet0/0
O IA 10.0.1.0/24 [110/66] via 100.0.0.2, 00:02:29, FastEthernet0/0
O IA 10.0.2.0/24 [110/66] via 100.0.0.2, 00:02:30, FastEthernet0/0
O IA 10.0.3.1/32 [110/66] via 100.0.0.2, 00:26:01, FastEthernet0/0
40.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
O 40.0.0.0/24 [110/2] via 100.0.0.4, 00:01:57, FastEthernet0/0
O 40.0.1.0/24 [110/2] via 100.0.0.4, 00:01:57, FastEthernet0/0
O 40.0.2.0/24 [110/2] via 100.0.0.4, 00:01:57, FastEthernet0/0
O 40.0.3.1/32 [110/2] via 100.0.0.4, 00:25:56, FastEthernet0/0
192.1.12.0/30 is subnetted, 1 subnets
O IA 192.1.12.0 [110/65] via 100.0.0.2, 00:26:01, FastEthernet0/0

Cấu hình DHCP Server tại Router

– Cấu hình Router 2 cấp DHCP Server

R2(config)#interface fa 0/1
R2(config-if)#ip address 192.168.200.254 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#router ospf 1
R2(config-router)#network 192.168.200.0 0.0.0.255 area 0
R2(config-router)#exit
R2(config)#ip dhcp pool net200
R2(dhcp-config)# network 192.168.200.0 /24
R2(dhcp-config)# default-router 192.168.200.254
R2(dhcp-config)# dns-server 8.8.8.8 8.8.4.4
R2(dhcp-config)# exit
R2(config)#ip dhcp excluded-address 192.168.200.1 192.168.200.10

– Khởi động máy ảo Linux đóng vai trò là PC
username: tc
tc@box ~:$sudo su
tc@box ~:# dhclient eth0
tc@box ~:# ifconfig eth0
=> kiểm tra IP trên interface
tc@box ~:# route
=> kiểm tra default-gateway
tc@box ~:# cat /etc/resolv.conf
=> kiểm tra DNS Server

– Cấu hình Router 4 là DHCP Server cấp IP cho đường mạng 192.168.200.0/24

R4(config)#ip dhcp pool net200
R4(dhcp-config)#network 192.168.200.0 /24
R4(dhcp-config)#default-router 192.168.200.254
R4(dhcp-config)#dns-server 8.8.8.8 8.8.4.4
R4(dhcp-config)#exit
R4(config)#ip dhcp excluded-address 192.168.200.1 192.168.200.10

Xóa đi cấu hình DHCP Server ở Router 2

R2(config)#no ip dhcp pool net200
R2(config)#no ip dhcp excluded-address 192.168.200.1 192.168.200.10

– Cấu hình Router 2 thành đại lý đi xin IP đại diện cho PC “ip helper-address”
+ Router 2 sẽ bỏ đi các IP broadcast của packet DHCP Discovery – OFFER – Request – ACK và thay bằng
IP src = 192.168.200.254
IP dst = 4.4.4.4 <—- “ip helper-address 4.4.4.4″<— do ta cấu hình
+ Sau đó packet được định tuyến đi đến DHCP Server
+ DHCP Server sử dụng IP src là 192.168.200.254 và so với các DHCP Pool được cấu hình trong Router 4
+ DHCP Server sẽ lấy 1 IP thuộc Network Pool chung đường mạng so với IP SRC và cấp xuống cho Router 2
+ Router 2 truyền packet xuống cho PC
R2(config)#int fa 0/1
R2(config-if)# ip helper-address 4.4.4.4
=> 4.4.4.4 là IP của DHCP Server (R4)
R2(config-if)# exit

– Cấu hình PC bỏ đi IP và xin lấy IP mới
tc@box ~:# dhclient -r
=> bỏ đi IP
tc@box ~:# dhclient eth0
=> xin IP

R4#show ip dhcp binding
Bindings from all pools not associated with VRF:
IP address Client-ID/ Lease expiration Type
Hardware address/
User name
192.168.200.11 010c.0295.5a00.00 Sep 08 2022 08:12 AM Automatic

Default Route OSPF — Multi Metric

– Router 1 có đường link kết nối Internet. Cấu hình cho Router 1 có thể ra Internet

R1(config)#interface fa 0/0
R1(config-if)#ip address dhcp
R1(config-if)#no shutdown
R1(config-if)#end
R1#show ip int brief
FastEthernet0/0 192.168.64.140 YES DHCP up up
R1#show ip route static
S* 0.0.0.0/0 [254/0] via 192.168.64.2
Administrative Distance (Default gateway do DHCP Server cấp xuống)
R1#ping 8.8.8.8
!!!!
R1(config)#ip route 0.0.0.0 0.0.0.0 f0/0 10

– Router 1 thông qua giao thức OSPF quảng cáo cho các router khác cùng hoạt động OSPF biết giá trị Default Route (0.0.0.0/0)

R1(config)#router ospf 1
R1(config-router)#default-information originate metric 10
R2#show ip router ospf 1
O*E2 0.0.0.0/0 [110/10] via 192.1.12.1, 00:01:04, Serial2/0
R1#ping 192.168.1.103
!!!

=> 192.168.1.103 là IP ở interface fa 0/0 của R3

– Router 3 có đường kết nối Internet Dự Phòng

R3(config)#interface fa 0/1
R3(config-if)#ip add dhcp
R3(config-if)#no sh
R3(config-if)#exit
R1(config)#router ospf 1
R1(config-router)#default-information originate metric 20

– Kiểm tra quá trình hoạt động của OSPF Default Route — Multi Metric

R1# show ip route
S* 0.0.0.0/0 [254/0] via 192.168.64.2
R2#show ip route
O*E2 0.0.0.0/0 [110/10] via 192.1.12.1, 00:41:12, Serial2/0
R3#show ip route
O*E2 0.0.0.0/0 [110/10] via 100.0.0.2, 00:23:29, FastEthernet0/0
R4#show ip route
O*E2 0.0.0.0/0 [110/10] via 100.0.0.2, 00:24:05, FastEthernet0/0

==> Các R2, R3, R4 Sử dụng Default Route do Router 1 cấp xuống có Multi Metric=10

– Giả sử đường mạng kết nối đi internet ở R1 bị mất kết nối. Hệ thống sẽ chuyển sang sử dụng default route ở R3 để kết nối internet

R1(config)#int fa 0/0
R1(config-if)# shutdown
R1(config-if)# exit
R1#show ip route
O*E2 0.0.0.0/0 [110/20] via 192.1.12.2, 00:00:08, Serial2/0
R2#show ip route
O*E2 0.0.0.0/0 [110/20] via 100.0.0.3, 00:00:45, FastEthernet0/0
R3#show ip route
S* 0.0.0.0/0 [254/0] via 192.168.64.2
R4#show ip route
O*E2 0.0.0.0/0 [110/20] via 100.0.0.3, 00:01:50, FastEthernet0/0

==> Các R2, R3, R4 Sử dụng Default Route do Router 1 cấp xuống có Multi Metric=20