Static route: the route entry written manually by a person is called static route, which is permanent and effective, with the highest priority and efficiency.
What's a router for?
Connect networks of different address segments. Block webcasts of different address segments.
The router has multiple interfaces, at least two, one LAN on one side.
Query the routing entry in the routing table show ip route
R1#show ip route Codes: C - connected, S - static, 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 i - IS-IS, su - IS-IS summary, 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.0.0/24 is directly connected, FastEthernet1/0
C: It means direct link. That is to say, I can connect any host on the 192.168.0.0/24 network by using interface 1 / 0.
Do not exit the global mode, execute the command in the privileged mode in the global mode: add do before the command in the original privileged mode
R2(config)#do show ip interface brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 192.168.0.2 YES manual up up FastEthernet1/0 unassigned YES unset administratively down down R2(config)#
Test whether two points are connected: ping
R1#ping 192.168.0.2 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.0.2, timeout is 2 seconds: .!!!! Success rate is 80 percent (4/5), round-trip min/avg/max = 60/61/64 ms R1#ping 192.168.0.2
Meaning of [.!!] in execution result:! The representative is through; the representative is not. Just one! , that's all. As for why there is the first point, it is because of ARP.
If the router has two interfaces and the ip address of interface f0/0 is 192.168.0.1/24, then the ip address of another interface f1/0 cannot be configured to be the ip address of the same network segment as interface f0/0, and the following error will be reported: [% 192.168.0.0 overlaps with FastEthernet 0 / 0].
Routers are created to connect different address segment networks. When two interfaces are set to the same address segment, they become switches. It would be better to use the switch directly. Switches are much cheaper than routers.
R2(config)#do show ip interface brief Interface IP-Address OK? Method Status Protocol FastEthernet0/0 192.168.0.2 YES manual up up FastEthernet1/0 unassigned YES unset administratively down down R2(config)#interface f1/0 R2(config-if)#ip addres 192.168.0.3 255.255.255.0 % 192.168.0.0 overlaps with FastEthernet0/0
It can be seen that the router is connected to different LANs and isolates the broadcast of two LANs.
The protocol used for ping is ICMP. ICMP is a network layer protocol.
From f0/0, an interface of router A, ping the address of f1/0, A non direct connection interface of another router B. the two interfaces are in different network segments:
To ping, ICMP Protocol should be used. The message of ICMP Protocol requires active IP address and destination IP address. Because it is impossible to know which interface (there is no entry of f1/0 network segment in router B in the routing table in router A), the source IP address cannot be known. Therefore, the packet of ICMP Protocol cannot be made, of course, it cannot be sent, so ping is not possible.
ping. You must be able to go and return to ping.
Add route entry
Method 1: do not specify the interface, that is, do not specify the source IP. The router needs to query recursively once to obtain the source IP of the interface: ip route 192.168.1.0 255.255.255.0 192.168.0.2
192.168.1.0 255.255.255.0: target network
192.168.0.2: next jump.
In order to access the 192.168.1.0 255.255.255.0 network, we must use 192.168.0.2 as a springboard.
R1(config)#ip route 192.168.1.0 255.255.255.0 192.168.0.2 R1(config)#do show ip route Gateway of last resort is not set C 192.168.0.0/24 is directly connected, FastEthernet1/0 S 192.168.1.0/24 [1/0] via 192.168.0.2
S: Represents static routing.
Method 2, the next hop is not specified, but the out interface is specified. No next hop, route addressing is slow: IP route 192.168.1.0 255.255.255.0 F1 / 0
R1(config)#ip route 192.168.1.0 255.255.255.0 f1/0 R1#show ip route C 192.168.0.0/24 is directly connected, FastEthernet1/0 S 192.168.1.0/24 is directly connected, FastEthernet1/0
Method 3: specify both the interface and the next hop: ip route 192.168.1.0 255.255.255.0 f1/0 192.168.0.2
R1(config)#ip route 192.168.1.0 255.255.255.0 f1/0 192.168.0.2 R1(config)#do show ip route C 192.168.0.0/24 is directly connected, FastEthernet1/0 S 192.168.1.0/24 [1/0] via 192.168.0.2, FastEthernet1/0
This is the best way
Terminal network: only one next hop to all networks.
For example, the host in the company is private ip, and the company has only one public ip, so the next hop of the router needs to be designated as this public ip.
S 0.0.0.0/0 [1/0] via Public network ip, FastEthernet1/0
Load balancing route entry:
The destination is the same, and there are many paths to reach the destination. In order to avoid the congestion of some routes, load balancing route entries are used to distribute requests to each route evenly.
S 0.0.0.0/0 [1/0] via 192.168.0.2,192.168.1.2,192.168.2.2 ...
Mask longest matching principle
When more than one route entry can reach the destination, which route should be selected?
Select the one with the longest mask.
For example: the destination is 192.168.2.1, and there are two routing entries, as shown below. Both of them can be reached, but s 192.168.2.1/32 is selected. Because the length of its mask is 32, the other is 24
S 192.168.2.1 /32 via ... S 192.168.2.0 /24 via ...
For example, when visiting 188.8.131.52, 184.108.40.206/24 and 220.127.116.11/24 do not match, only 18.104.22.168/8 can be matched
22.214.171.124/32 126.96.36.199/24 188.8.131.52/8
Advantages and disadvantages of static routing:
QQ group of mutual learning in c/c + +: 877684253