Forwarding gateway and NAT gateway

On any machine, when accessing another IP address, it will first determine whether the target IP address and the IP address of the current machine are in the same network segment. How to determine the same network segment? CIDR and subnet mask are required.

If it is the same network segment, then there is nothing to do with the gateway. Just put the source address and destination address into the IP header, then obtain the MAC address through ARP, put the source MAC and destination MAC into the MAC header, and send it out. .

If they are not on the same network segment, this needs to be sent to the default gateway Gateway. The address of the Gateway must be in the same network segment as the source IP address. Often it's either the first or the second. For example, for the network segment 192.168.1.0/24, the Gateway is often 192.168.1.1/24 or 192.168.1.2/24.

How to send it to the default gateway? Isn't the gateway on the same network segment as the source IP address? This process is the same as sending to other machines on the same network segment: put the source address and destination IP address into the IP header, obtain the MAC address of the gateway through ARP, and put the source MAC and gateway MAC into the MAC header. , send it out. The port where the gateway is located, such as 192.168.1.1/24, receives the network packets. What to do next depends entirely on the gateway.

The gateway is often a router, a layer 3 forwarding device. Just remove the MAC header and IP header, and then use the contents inside to see where the device will forward the packet next.

Static routing actually means configuring rules one by one on the router. Whenever you want to choose which hand to throw from, match the rules one by one, find the matching rules, and throw out from a certain port as set in the rules to find the next hop IPX.

The MAC address is an address that is only valid within a LAN. Therefore, as long as the MAC address passes through the gateway, it will definitely change because the LAN has been changed. The main difference between the two is whether the IP address changes. A gateway that does not change the IP address is called a forwarding gateway; a gateway that changes the IP address is called a NAT gateway.

This article is a study note for Day 8 in September. The content comes from Geek Time's "Internet Protocol". This course is recommended.

Guess you like

Origin blog.csdn.net/key_3_feng/article/details/132765785