連網技術與網絡管理2023-05-27 靜態路由

Usage of router

Routers are network devices that operate at the network layer (Layer 3) of the OSI model. They are used to connect multiple networks together and facilitate the exchange of data between these networks. Routers perform the following important functions:

  1. Packet forwarding: Routers examine the destination IP address of incoming packets and make forwarding decisions based on routing tables. They determine the optimal path for packets to reach their destination across different networks.

  2. Network addressing: Routers use IP addresses to identify and route packets. They enable communication between devices on different networks by forwarding packets between networks based on IP addressing schemes.

  3. Network segmentation: Routers can divide a large network into smaller subnets, allowing for better organization and management of network resources. Each subnet can have its own IP address range, subnet mask, and network devices.

  4. Interconnectivity: Routers provide connectivity between different types of networks, such as connecting a local area network (LAN) to the internet or connecting multiple LANs together. They enable devices on different networks to communicate with each other.

  5. Network security: Routers can implement various security features, such as firewall functionality, access control lists (ACLs), and network address translation (NAT), to protect networks from unauthorized access and control the flow of traffic.

  6. Path selection and routing protocols: Routers use routing protocols, such as OSPF (Open Shortest Path First) or BGP (Border Gateway Protocol), to exchange routing information with other routers and dynamically determine the best paths for forwarding packets.

Overall, routers play a crucial role in directing network traffic, connecting networks, and ensuring efficient and secure data transmission between devices and networks.

 

static route

A static route is a manually configured route in a router's routing table that specifies the path to reach a specific network or destination. Unlike dynamic routing protocols that automatically exchange routing information between routers, static routes are manually configured by a network administrator.

Static routes are typically used in small networks or for specific routing requirements where a particular network needs to be reached through a specific next-hop router or interface. They provide a fixed path for forwarding packets and do not dynamically adapt to changes in the network topology.

When a router receives a packet with a destination IP address, it checks its routing table to determine the appropriate next-hop for forwarding the packet. If a static route exists for the destination network, the router will use the specified next-hop router or interface to forward the packet. If there is no matching static route, the router will use its default route or rely on dynamic routing protocols to find a suitable route.

Static routes offer simplicity and control over network routing. They can be useful for connecting isolated networks, defining backup routes, or overriding the default routing behavior. However, static routes require manual configuration and do not provide automatic adaptation to network changes, so they may not be suitable for large or dynamic networks.

It's worth noting that the configuration syntax for static routes may vary depending on the router's operating system or vendor.

 

自主學習的是,動態路由。靜態路由更穩定,可以避免arp攻擊。

 

靜態路由配置

ip route network  [mask] {address | interface} [distance] [permanent]

The "ip route" command with the specified syntax is used to configure a static route on a router. Here's an explanation of each parameter:

  • network: This specifies the destination network or subnet you want to reach. It can be either an IP network address or a specific IP address.
  • mask: This is an optional parameter that specifies the subnet mask associated with the destination network. If not provided, the command assumes a classful network mask based on the IP address provided.
  • address: This parameter specifies the IP address of the next-hop router or the exit interface through which the router should forward the traffic to reach the destination network.
  • interface: This parameter specifies the exit interface through which the router should forward the traffic to reach the destination network. Instead of specifying a specific next-hop IP address, you can use the exit interface directly.
  • distance: This is an optional parameter that sets the administrative distance for the static route. The administrative distance determines the reliability or trustworthiness of a particular routing source. If not specified, the default administrative distance is used.
  • permanent: This is an optional parameter that makes the static route permanent, meaning it remains in the routing table even if the router is restarted.

Address 下一跳路由器的IP地址

Interface 本地路由器的出站接口

 

The "ip route" command is used to configure static routes on a router. The exact syntax may vary depending on the router's operating system, but here is a general example of how to use the "ip route" command:

To add a static route:

ip route <destination_network> <subnet_mask> <next_hop>

 

  • <destination_network> is the network or destination you want to reach.
  • <subnet_mask> is the subnet mask associated with the destination network.
  • <next_hop> is the IP address or exit interface through which the router should forward the traffic to reach the destination network.

For example, let's say you want to add a static route to the network 192.168.2.0/24 via the next-hop IP address 10.0.0.1:

ip route 192.168.2.0 255.255.255.0 10.0.0.1

 

To remove a static route, you can use the "no" form of the command followed by the same parameters used when adding the route:

no ip route 192.168.2.0 255.255.255.0 10.0.0.1

 

Remember to adjust the syntax based on the specific router's operating system you are working with, as the command syntax may vary. It's recommended to consult the router's documentation or command reference for accurate information on how to use the "ip route" command on your specific router.

 

交換機連線之後,先紅色,後面再自動綠色。

路由器連線之後,默認都是紅色。

PC0配置192.168.1.2,255.255.255.0,網關爲192.168.1.1

PC1配置192.168.3.2,255.255.255.0,網關爲192.168.3.1

 

路由器配置命令

en 進入管理員模式

conf t 配置終端

配置第一個路由器

int fa0/0

ip address 192.168.1.1 255.255.255.0  配置路由器地址和網關

no shutdown 讓上面的配置立即生效

 

int fa0/1

ip address 192.168.2.1 255.255.255.0

no shutdown

 

配置第二個路由器

en

conf t

int fa0/0

ip address 192.168.2.2 255.255.255.0

no shutdown

 

int fa0/1

ip address 192.168.3.1 255.255.255.0

no shutdown

 

查看路由器配置

Router#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

C    192.168.1.0/24 is directly connected, FastEthernet0/0
C    192.168.2.0/24 is directly connected, FastEthernet0/1

兩個端口是直連路由

 

Router#show ip route 
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

C    192.168.2.0/24 is directly connected, FastEthernet0/0
C    192.168.3.0/24 is directly connected, FastEthernet0/1

 

左邊的PC192.168.1.2想要和右邊的192.168.3.2進行通訊,

那麼左邊的路由器,需要將192.168.3.0的消息下一跳轉給192.168.2.2,也就是轉給了右邊的路由器

反過來,右邊的PC192.168.3.2想要和左邊的1912.168.1.2通訊,

那麼右邊的路由器,需要將192.168.1.0的消息下一跳轉給192.168.2.1,也就是轉給了左邊的路由器

 

配置路由,

Router(config)#ip route 192.168.3.0 ?  命令輸入一半,打問號,會提示下一個待輸入的是什麼
  A.B.C.D  Destination prefix mask
Router(config)#ip route 192.168.3.0 255.255.255.0 ?
  A.B.C.D          Forwarding router's address
  Ethernet         IEEE 802.3
  FastEthernet     FastEthernet IEEE 802.3
  GigabitEthernet  GigabitEthernet IEEE 802.3z
  Loopback         Loopback interface
  Null             Null interface
  Serial           Serial

 

第一個路由器裏配置

ip route 192.168.3.0 255.255.255.0 192.168.2.2  配置下一跳地址爲192.168.2.2

查看路由show ip route發現多了一條記錄

C    192.168.1.0/24 is directly connected, FastEthernet0/0   開頭的C是connected
C    192.168.2.0/24 is directly connected, FastEthernet0/1
S    192.168.3.0/24 [1/0] via 192.168.2.2

"S    192.168.3.0/24 [1/0] via 192.168.2.2": This entry represents a static route. It states that the network 192.168.3.0/24 can be reached via the next hop IP address 192.168.2.2. The "S" denotes a static route, and the [1/0] represents the administrative distance and metric for the route.

 

第二個路由器配置

ip route 192.168.1.0 255.255.255.0 192.168.2.1

 

默認路由

The command "ip route 0.0.0.0 0.0.0.0 172.16.2.2" is used to configure a default route on a router.

Let's break down the command:

  • "0.0.0.0 0.0.0.0" represents the destination network and subnet mask. In this case, it is 0.0.0.0/0, which matches any destination IP address.
  • "172.16.2.2" is the next-hop IP address or the gateway where the router should send the packets for any destination that doesn't have a more specific route.

By configuring this command, the router is effectively setting up a default route that directs all packets with unknown destination addresses to the next-hop IP address 172.16.2.2. This next-hop IP address should be the IP address of the next device in the network path that can route the packets towards their intended destination.

In other words, if the router receives a packet with a destination IP address that doesn't match any specific route in its routing table, it will forward the packet to 172.16.2.2, expecting that this gateway will have a more specific route or know how to forward the packet further to reach its destination.

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章