What does a routing table contain, only destination LAN address with the next hop? But what does this next hop mean, because looking at this example

enter image description here

I don't see the general rule how a next hop is defined. (for network destination,, I understand, but not the other ones)

I also use a command 'ip route add <> src <> via <> , what should be in the <>? I use Linux Ubuntu as a virtual machine in virtualbox


My guess is that the "rtnetlink reply: invalid argument" error is because either the IP address, mask, and gateway are not of the same class (class A or B or C); or because a "static" address conflicts with some DHCP range of addresses.

The table for R8 in your schema is not a routing table, but describes what R8 will do with addresses. Where it says for example, this should be taken to mean the network segment rather than the IP address.

For sub-networks not directly accessible from R8, such as, the routing table will direct the message to the router that is the nearest to the target network, and that router will then pass on the message according to its own routing table. In this case, messages addressed to 16.0.0.X get passed to the gateway, which is the address of R7, which will forward them to the right recipient.

The routing command executed in R8 should look similar to :

ip route add via src

The src parameter is used when adding a route to a multihomed host, to have control over the source IP address your host is sending from. It can be omitted in simple cases. This will ensure here that the return message will return through the sub-network, but other values can be used if we prefer R7, for some reason, not to return the message through that sub-network.

Note that the src you are giving would only affect the traffic originating at your end. If a foreign packet is being routed, it obviously would already have a source IP address, so it would normally be passed on unaltered (unless using NAT, and this can also be overridden).

I note that in general one does not need to supply routes for every destination. Just like a computer can specify a default gateway in its routing table, which is a catch-all address that receives all messages to addresses that it does not know, so does a router have its own routing table that can contain a gateway. The router's gateway address is represented by the default route of

Note that it is entirely possible to even set up a gateways circuit in the network, for example :
R1 ➝ R4 ➝ R8 ➝ R7 ➝ R6 ➝ R2 ➝ R1.
The number of hops is not optimized here, but messages will still get from every sub-network to every other sub-network. Good network design will normally include one or more centralized routers, in order to minimize the number of hops.

  • Thanks! :D And if I understand correctly in ip route add <> via <> src <>, in the first <> should be the destination network, in the third <>, should be the interface of the current router, and in the second <>, should be the interface connected to the interface of the third <>, but on the other end? Aug 24 '15 at 7:08
  • Your example is from R8 -> R7, but let's say that I want to go from R8 -> R7 -> R6 or from R8 -> R7 -> R6 -> R2 then the src and via will be the same, but only the destinations change ( and respectively)? Aug 24 '15 at 7:11
  • Yes, in both cases R8 doesn't need to know about routes further than R7.
    – harrymc
    Aug 24 '15 at 7:21
  • Ok, but what should the interface be (dev), when I use the command ip route add <> dev <> src <> via <> ? And is my first comment under your answer correct? :) Aug 24 '15 at 7:30
  • I'm a bit lost between <>s. Dev specifies the interface/sub-network through which the message is to go out, where in the multi-home case some ip add commands accept directly the interface-name (eth0 etc.) rather than an IP address. Src specifies the interface/sub-network through which the return-message/answer is to come back.
    – harrymc
    Aug 24 '15 at 7:52

The other ones are more than one hop (router) away. As far as router R8 is concerned it only wants to know the interface to use and the IP of the next router in line to reach the destination network, then it goes to the next router and that router uses it's own routing table to determine the next hop. So to get to the network the routing table defines interface 3, which is and the hop is the next router it is going to which is Once the traffic is received by R2 then R2 will use it's own routing table to determine the best route to the network, which would be out the interface.

  • And it specifies the destination gateway, which is the address of the next router in line.
    – Brian
    Aug 18 '15 at 19:30
  • Thanks! :) I also use a command 'ip route add <> src <> via <> , what should be in the <>? Aug 19 '15 at 11:31
  • This i'm not an expert in, but the first bracket would be the destination IP or network and subnet mask of the destination network followed by the gateway of the next hop )Example for R8 to the 14 network, ip route . The src i am unsure of but it may be there to define a route for a specific source IP, either a workstation or a router, and the via would be the interface it should go out on. Like i said not an expert here so please can someone verify this for me? Thanks.
    – Brian
    Aug 19 '15 at 14:15
  • Ok, because I used 'ip route add <destination IP> src <interface of current router> via <interface next router in line>, but that errored in 'rtnetlink reply: invalid argument' Aug 19 '15 at 21:10
  • How can I make other users look at this? :) I really need an answer :) Aug 20 '15 at 8:12

I'm not sure from where your design and routing table come from. Anyway in an environment like yours, the routes to the remote networks are usually defined through routing protocols (ie. dynamic routing); the use of static routes (defined by the user/admin), with all the redundant paths you have, will cause routing loops or black holes eventually.

In other words, every subnet of your diagram can be reached through every interface of R8 actually, depending by the configuration of the other routers.

For instance: if you define the interface 1 of R8 as the next hop for (meaning that packets destined to any IP of the subnet will be sent out the interface 1), and if R4 (the actual next-hop out of interface 1 of R8) has another static to through R1, your packet will cross R8->R4->R1->Destination. On the other side, if in this example you still send your packet for to R4, but R4 is configured with a different static for that points to R8, you will have a routing loop and your packet will bounce between R8 and R4 until its TTL will expire.

The same theory is applicable to any other remote network like, where it is less obvious if R8 should forward its packet to R2 or R4.

The main thing to remember is that IP packets don't have memory, they're just forwarded by evaluating their destination (ie. routers don't take care about the interface from where the packet was received - unless you use things like source-routing but it's not the case here).

The table you posted doesn't show if static or dynamic routing is used (it misses also the subnet of those networks), but unless this is a particular theoretic exercise, dynamic routing is what you need.

Dynamic routing can define the best path from a router to a destination network, by using different parameters like number of hop, bandwidth, latency, and so (depending by the specific dynamic routing protocol). Also, they can manage failures of redundant links properly.

As another example, if you decide to put a static for pointing to R3 and R3 router crashes, you will continue to forward packets destined to (for instance) to a black hole. If you decide to load balance to with 2 routes (with same metric) through R3 and R4, if R4 goes down (or one of its interfaces is broken), R8 will continue to forward the packet 1 to R3, the packet 2 to R4, the packet 3 to R3, and so on. This will cause apparently random things, because if the packets use TCP, the missed ones will be retransmitted, making less obvious that half of your traffic is trashed (eg. intermittent loss of line of some services, slowness, etc.).

If you're using Linux, Quagga can be the software to use for dynamic routing, but the assumption is that other routers are running a dynamic routing protocol.

However, if your goal is to set a static route, these commands should work (I'm assuming /24 but if classful it might be a /8):

ip route add dev eth3

same of:

ip route add via

Anyway the second one is usually preferred in a multiaccess network (no multicast/broadcast traffic needed, no tons of ARP requests, etc.).

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.