简体   繁体   中英

Why my routing tables stores a mac address?

I am a student learning computer network.

Here's how my network look like:

   Router(NAT)
  /         \
My PC     My iPad

I have looked up my computer's routing table, and it shows the following:

$ netstat -r
Routing tables

Internet:
Destination        Gateway            Flags           Netif Expire
default            172.22.128.1       UGScg             en0
127.0.0.1          127.0.0.1          UH                lo0
172.22.128.1       0:74:9c:96:72:55   UHLWIir           en0   1200
172.22.161.13      ba:2e:b1:6f:69:39  UHLWI             en0    740

I confirmed that the ip 172.22.161.13 's gateway ba:2e:b1:6f:69:39 is the MAC address of my iPad.

I have a few doubts:

  1. Shouldn't the routing table records ip address of next hop? how can it store a MAC address?
  2. If the command netstat -r also lookups the arp table, how should it send packets to my iPad without going through the router?

The issue here is understanding the functionality of layer 2 and layer 3 in a network.

There is a difference between forwarding packets to the device located on the same subnet and on the device located on the different subnet.

I don't think there is a better definition of subnet, than devices that can communicate via a layer 2 protocol with each other. Routers are used to forward packets between devices in different subnets, that is, two devices in the same subnet do not communicate over the router, at least not over the "router" part of the router.

Devices that are located in the same subnet should be assigned the same IP prefix (ie, the bits covered by network mask are the same). "Should" means that if it is not the case, then your network is configured wrong and may not work properly. This way your PC and your IPad can determine that they are on the same subnet and do not need to go over their default gateway.

Since your PC and your IPad are on the same subnet, they will talk to each other using layer 2. I am not sure from your configuration how many interfaces are actually wireless. If both interfaces are wireless, they may actually be capable of talking directly (i am not sure if wifi protocol in AP mode allows it, i think it does). If your PC is connected over Ethernet, then your Router also acts as a switch/bridge (which is layer 2 device) and forwards packets according to ethernet specification. You can learn about it by googling MAC learning.

This should answer the second question, now to the first one.

Actually, I wonder why the table is storing IP addresses. IP address of the next hop is not used in forwarding. First, note, that communication between devices which are two hops from layer 3 (ie, routers) standpoint happens using layer 2. When a device makes routing decision, in takes the destination address from the IP header and looks up next hop, where what the device needs is a) outgoing interface b) how to reach next hop using layer 2 protocol of the interface. Then the device constructs an appropriate layer 2 header and sends the packet to the next hop device, which more or less does the same. So, actually your PC needs mac address of your router's interface to which it is connected to send the packet somewhere outside of the subnet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM