What is the procedure for determining the route of a packet from the routing table?

Last time, I introduced the basics of routing between different networks with an example of a routing table. Next, let's take a look at the procedure for deciding the route of a packet using this routing table.

Router selection mechanism

When deciding the packet route, the network address of the communication partner is calculated using Netmask (subnet mask) in order from the top of the routing table. If the address matches the Network Destination, it is considered as a route candidate. As a result of performing this process on all rows, if there is only one candidate route, that route is selected. If there are multiple candidates, compare the "Metric" values ​​in each row and select the row with the smallest value.

Screen 1 How to read the routing table (reposted)

The routing table is also used for direct communication. If the communication partner belongs to the same network, it always matches the local route. In the example of screen 1 posted last time, it is the third line. When the information in that line is read, the value of Gateway matches the value of Interface (= Gateway is itself), so the source terminal judges that "this is the other party to connect directly". be.

Finally to the default gateway

By the way, if you look closely at the routing table on screen 1, there are no rows destined for a specific network address other than the local route in the third row. However, even in this state, communication with the Internet or another network (subnet) in the organization is performed without any problem. The reason is the "default route" on the first line.

As mentioned above, the subnet mask of the default route is "0.0.0.0". Therefore, when the logical product with the IP address of the communication partner (= network address of the communication partner) is calculated, it is always "0.0.0.0", which matches the Network Destination. That is, no matter what the IP address of the communication partner is, the default route is a "route candidate" to that partner. Therefore, if the network to which the communication partner belongs is not registered in the routing table, the default route is selected as the route. Even if there are other route candidates, the default route is selected if the set "Metric" value is the smallest.

ルーティングテーブルからパケットの経路を決める手順とは?

The router specified for the Gateway of this default route is called the "default gateway". Please look at screen 1 again. There is a line called "Default Gateway" at the end of the route. The IP address of the default gateway is also displayed here. From the viewpoint of the packet source terminal, the default gateway is in the position that "if the packet destination cannot be found, send it to the default gateway for the time being, and the rest will be done without permission".

Therefore, for the default gateway, if there is only one router in your network such as SOHO, set that router, and if there are multiple routers, set the IP address of the router closest to the backbone manually or by DHCP. In the case of manual operation, in Windows XP, set it in the "Default gateway" item on the "Internet Protocol (TCP / IP) Properties" screen (Screen 2).

Screen 2 Setting the default gateway

Actual communication procedure

Now, let's take the network of Fig. 1 as an example to explain how communication between subnets is performed. This network consists of two subnets connected by a single router. Router A is set as the default gateway for both PCs belonging to LAN1 and PCs belonging to LAN2. Consider sending data from PC1 to PC4 on this network.

Figure 1 Network configuration

First, PC1 refers to its own routing table and decides how to send a packet for PC4. Since PC4 belongs to a network different from its own, it sends a packet to router A, which is the default gateway. At this time, the communication between PC1 and Router A follows the same procedure as the direct communication described in the previous part.

That is, since PC1 only knows the IP address of Router A, it first asks Router A to tell it the MAC address using ARP ((1) to (2) in Fig. 2), and then sends a data packet for PC4 to Router A. (③ in Fig. 2).

Figure 2 Actual packet exchange

Router A, which receives the packet for PC4, also refers to the routing table registered in itself and decides how to send the packet for PC4 (Table 1).

Table 1 Router A routing table

As a result, since PC4 is on LAN2, which is directly connected to Router A, packets are sent from the interface with the IP address 172.20.175.241 toward PC4. Since this is also a direct communication, the MAC address of PC4 is first known by ARP (④ to ⑤ in Fig. 2), and then the data packet is sent to PC4 (⑥ in Fig. 2).

As described above, communication between subnets, which is the most basic routing, is realized by combining address resolution by ARP. However, in an actual network, there are multiple routers and they are connected to each other. Therefore, the routing operation is also complicated. From the next time, I will explain the mechanism while trying out the actual router.