0

I have a computer with two NICS, one eth one wlan.

  • wlan is on 10.0.0.0/24
  • eth is on 192.168.0.0/16

Kernel routing table is:

 $ route -n
 Kernel IP routing table
 Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
 0.0.0.0         192.168.0.1     0.0.0.0         UG    100    0        0 enp4s0f0
 0.0.0.0         10.0.0.1        0.0.0.0         UG    600    0        0 wlp3s0
 10.0.0.0        0.0.0.0         255.255.255.0   U     600    0        0 wlp3s0
 169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 enp4s0f0
 192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 enp4s0f0

Questions:

  1. Does the kernel choose which default gw use, or does it send to both?
  2. How does it choose if it chooses?
  3. What is the most efficient way to influence the choice, or to make it make one?

using 4.4.0-45-generic

  • You should define default gateway.Kernel didnt choose default gateway. – supriady Jan 14 '17 at 11:33
  • destination 0.0.0.0 is default gw, no? – lash Jan 14 '17 at 11:34
  • Default Gateway is Router IP address to connect to Internet.Can you connect to internet using 0.0.0.0 as Default gateway?Can you access www.xxxx.com using 0.0.0.0 as name server? – supriady Jan 14 '17 at 13:56
  • 1
    @lash Yes, destination 0.0.0.0 means 'default' and the getaway associated to this destination is the default GW. Either you define it manually, or automatically with DHCP. If there are several default GWs, the kernel choose the one to use according to many parameters (policy, metrics, etc). See Stephen's answer. – xhienne Jan 15 '17 at 14:04
3

In this case the kernel chooses based on the metric: the lower metric wins. (Route selection is based on route specificity, administrative cost, and metric in that order. Both your default gateways have the same specificity and administrative cost.)

To change the selection, the best approach is to change the route metric.

  • 1
    What is the "administrative cost" in OP's output? – xhienne Jan 14 '17 at 12:17
  • @xhienne the administrative cost is 0 for both default routes because they correspond to connected interfaces. A route's administrative cost depends on the source of its definition: 0 if it's a connected interface, 1 if it's a static route, varying amounts for other route sources (depending on the protocol, e.g. RIP v. OSPF). – Stephen Kitt Jan 14 '17 at 13:38
  • Ah ok, so it implied, not actually shown. Thanks for the explanation. But a default GW is necessarily on a connected interface, right? – xhienne Jan 14 '17 at 14:16
  • @xhienne I guess it is — I'm trying to think of scenarios where it wouldn't be but I can't think of one (tunnels etc. appear as new interfaces). – Stephen Kitt Jan 15 '17 at 13:59
  • In newer kernels you can use Policy-based routing (you also need the new iproute2 package) ... you then put the default routes into different tables and create rules which determine when to use each table (and hence, which default route applies). – Murray Jensen Jan 16 '17 at 0:38

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.