It is quite possible that my question may not make a lot of sense. I apologize, but I am not a networking guy, and that's my excuse.

To elaborate, WikiPedia defines "Default Gateway" as a node on a "TCP/IP" network. And the way it works is that if a network interface is sending a packet to an IP address not present on its subnet, it sends it out to the default gateway (which then knows what to do with that packet).

Is this true if a UDP packet (datagram) is involved? I mean, if my network interface is sending a UDP packet to an IP address that is not present on its subnet, would it automatically send it to the Default Gateway as well?


Yes, UDP routes over IP in just the same way as TCP. The default gateway is actually an IP concept, and has nothing to do with TCP -- it will work with any protocol that is built on top of IP, whether that's TCP, UDP or anything else.


Yes, this works for all IP packets (including UDP along with TCP and others).


The key to getting a solid grasp on this is to understand different networking layers and encapsulation. The traditional model to learn is the OSI model. TCP and UDP are both part of the transport layer which gets encapsulated into the network layer (IP). So the TCP and UDP packets become part of the payload of the ip packet.

So to really understand this, go learn:

  • The OSI Model
  • What IP, UDP, and TCP Packets look like (Diagrams). Notice the Header and Payload sections.
  • Packet Encapsulation.

Generally there is agreement that one of the best books to learn this (although it does go into a lot of detail) is TCP/IP Illustrated Volume 1 by W. Richard Stevens. This is really worth your time, network questions like this are almost always on interviews and also learning the design of these protocols might inspire general good design concepts for other things as well.

The direct answer by the way is, "Yes" since the default gateway is for the IP packet is what get routed by the default gateway and both UDP or TCP packets will be encapsulated inside the IP packet. Also you seem to have the default gateway pretty much correct, it is the IP route used when there are no other more specific routes in the routing table.

To answer your title question, "Can a network interface be configured to have a default gateway for UDP packets?":

It can, but this is a little less of a common network configuration. This is called Policy-Based Routing (PBR) but isn't used in everyday local networks -- it s a somewhat advanced router configuration where other layers besides the IP layer (network) layer can be inspected to make routing choices.

  • Thank you for the information. I did study the OSI model in school, but I guess that study needs revision. – Vaibhav Dec 27 '10 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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