1

I'm trying to learn Linux routing tables and ran into bit of snag. In the example below I'm not sure what is happening. My understanding is 0.0.0.0 means that for line 1 and 2 any packets outside of its network look at the default gateway 10.0.0.1.

Destination Gateway Genmask       Flags MSS Window  irtt    Iface
10.0.0.0    0.0.0.0  255.255.255.0  U   40  0          0    eth1
10.1.1.0    0.0.0.0  255.255.255.0  U   40  0          0    eth0
0.0.0.0     10.0.0.1    0.0.0.0     UG  40  0           0   eth1

So my question is this, which interface is closer to the Internet? Im not sure if packets immediate leave eth0 and eth1 sends packets to the gateway 10.0.0.1 or if both eth0 and eth1 both route packets to 10.0.0.1 for the Internet.

1
  • As you don't explain how the interfaces are connected, it's hard to tell which one is "closer to the Internet". Also given several answers, would you care to accept one of those?
    – U. Windl
    Sep 30, 2022 at 6:35

5 Answers 5

1

in your routing table you computer know about 2 subnetwork.
1- 10.0.0.0/24
2- 10.1.1.0/24
rest traffic will be send to your gateway (10.0.0.1).

what does mean? if you send packet to addres from subnet 1, then your computer try send it via eth1.

Answer to your question is that eth1 is nearest "internet", because each ask to internet will go thru 10.0.0.1 (gateway).

1

So my question is this, which interface is closer to the Internet?

None of them - 10.0.0.0/8 is not globally routable as of RFC 1918. However, the third entry says that 10.0.0.1 is the default gateway (traffic to 0.0.0.0/0 goes there except for destinations at 10.0.0.0/24 and 10.1.1.0/24), which may have a route (using NAT) to the Internet. In this case eth1 is "closer" to the Internet (in a suitable sense).

1

When a packet is sent to the IP stack, the driver searches your routing table for the route that best matches the destination IP address. It does this by performing a binary and of the destination defined in each route and the destination defined in the packet. Whichever result most closely matches the destination defined in the packet is the route the driver uses. If there is a default gateway defined for that route then the packet is sent to the gateway. If there is no gateway defined for that route then it is assumed that the destination is on the local network and the packet is sent directly to the destination.

Thus, a packet with a destination address of 10.1.1.67 will match the route 10.1.1.0/24 and will leave on port eth0 as configured by the second route. A packet with a destination address of 10.0.0.84 will leave on eth1 as configured by the first route. Any other destination address will only match the third route and will leave via eth1, headed for the gateway.

There is no way to say which route is "closer" to the internet as none of those routes deal with publicly routed addresses, rather those are all Class A private addresses. Class A, B, and C addresses ranges that are reserved for private use and are not typically routed to the internet. It is entirely possible that the packets will be routed through other networks before reaching the internet or they may never reach the internet at all.

2
  • There are two record in the route table handled by eth1. Does that mean eth1 connects two networks? When different packets arrives, does eth1 sends the packets to different network based on the destination ip address?
    – Ryan Lyu
    Mar 9, 2022 at 7:10
  • 1
    @RyanLyu Eth1 itself is only connected to one network, as indicated by the single network route (10.0.0.0/24). However, the default route (0.0.0.0/0) is also on eth1, so any traffic not handled by a more specific route (bitmask greater than 0) will be handled by the default route and sent out through eth1. For instance, traffic destined for the 10.1.1.0/24 network will be sent out eth0, due to the more specific (/24) route.
    – smokes2345
    Mar 15, 2022 at 21:13
1

You don't get it completely right. The first two lines tell you that there is no gateway for reaching networks 10.0.0.0/24 and 10.1.1.0/24, but they are reachable through the respective interfaces eth1 and eth0, respectively. So if you want to send a packet to 10.0.0.1, the packet is sent out over eth1, and a packet to 10.1.1.47 is sent over eth0.

To reach the Internet, the destination address won't be in the networks 10.0.0.0/24 or 10.1.1.0/24, so the last line would match (0.0.0.0/0) and the kernel would know that it would have to send the packet to the given gateway (10.0.0.1). A dependent routing decision would be made to decide how to reach this gateway and as mentioned earlier, this would be made possible by sending the packet out over interface eth1.

1
  • the destination for first route record is not a gateway. when eth1 gets the packets to 10.0.0.10, what will eth1 do? who is the next step?
    – Ryan Lyu
    Mar 9, 2022 at 7:15
0

Economic routers, have 2 IP addresses

  1. LAN, 99% is 192.168.1.1 and we can (should) change it.
  2. WAN. It is assigned automatically by ISP

The Gateway is the address to which packet are destinated, in each computer it is setted using DHCP (most times), if gateway is not setted computers in your LAN can communicate, but can't send packets outside.

Here you can find the answer well explained: https://stackoverflow.com/questions/8599424/understanding-routing-table-entry

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .