I'm new to networking and reading
IP protocol specification and got some question regarding the paragraph
2.2 Model of Operation. Here is what is discribed:
The internet module prepares a datagram header and attaches the data to it. The internet module determines a local network address for this internet address, in this case it is the address of a gateway. It sends this datagram and the local network address to the local network interface. The local network interface creates a local network header, and attaches the datagram to it, then sends the result via the local network.
So initially we have a destination IP address, say
220.127.116.11, using this address the internet module determines the gateway address. On my machine
$ ip route list default via 18.104.22.168 dev wlp2s0 proto dhcp metric 600
So the gateway address is
22.214.171.124 for the destination address
126.96.36.199. The gateway address
188.8.131.52 is used to create a
local network header. The thing is that there's no field like
gateway address in the IP packet structure.
From what I understood from the RFC paragraph above the
local network interface wraps the IP packet with the final destination
184.108.40.206 into another IP packet with the destination
220.127.116.11. Is it correct? What's unclear to me is that how the gateway address is determined? How does
ip route list know that
18.104.22.168 is the gateway?