I'm new to networking and reading RFC791
about 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 40.40.40.40
, using this address the internet module determines the gateway address. On my machine
$ ip route list
default via 20.20.20.1 dev wlp2s0 proto dhcp metric 600
So the gateway address is 20.20.20.1
for the destination address 40.40.40.40
. The gateway address 20.20.20.1
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 40.40.40.40
into another IP packet with the destination 20.20.20.1
. Is it correct? What's unclear to me is that how the gateway address is determined? How does ip route list
know that 20.20.20.1
is the gateway?