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

So initially we have a destination IP address, say, using this address the internet module determines the gateway address. On my machine

$ ip route list
default via dev wlp2s0 proto dhcp metric 600

So the gateway address is for the destination address The gateway address 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 into another IP packet with the destination Is it correct? What's unclear to me is that how the gateway address is determined? How does ip route list know that is the gateway?


1 Answer 1


An IP packet (OSI layer 3) isn't encapsulated by another IP packet but by a data link layer frame (OSI layer 2).

It is that frame that is addressed to the next-hop destination - either the gateway that's been determined by routing or the packet's actual destination when that is local (on the last hop).

In your example the IP packet keeps source and destination IP addresses at all times (that's a given unless NAT is in play). Since a gateway is required, the encapsulating Ethernet frame is addressed to the gateway's MAC address as discovered by ARP. The gateway receives the frame, extracts the packet and repeats the steps you describe: look up route, determine gateway and then send to that gateway using the link layer. On a MAC-based network the 'send to gateway' means use a frame destined to the gateway's MAC address.

  • Thanks for the answer. Regarding then determining gateway IP as far as I understood it was done when obtaining IP address via DHCP.
    – Some Name
    Commented Jun 3, 2023 at 13:46
  • 3
    The default gateway for a host is often configured by DHCP, yes. More detailed routes in routers are either statically configured by an admin (in small networks) or learned from adjacent routers via a dynamic routing protocol like OSPF or BGP.
    – Zac67
    Commented Jun 3, 2023 at 16:28
  • Very inetersting, thanks. Regarding the static routes configuration by admin, don't really get what you mean by that. Couldn't you please give a direction to dig into the topic. E.g. I'm on Linux, how can I provide static routes configuration e.g. for my wifi connection traffic?
    – Some Name
    Commented Jun 4, 2023 at 1:28
  • 1
    Routers aren't usually configured by DHCP. Since a router requires a route for a packet to be forwarded, the routes need to come from somewhere - it's either the admin configuring static routes manually or setting up a routing protocol for dynamic routing exchange with other routers. Sorry, host configurations are explicitly off topic here, see the help center.
    – Zac67
    Commented Jun 4, 2023 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.