I have connected a computer (running Debian Wheezy) to two different DHCP servers (routers) through a cable and through a wifi device. If I look at the routes with route, I get the following result
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.2.1 0.0.0.0 UG 202 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 303 0 0 wlan0
192.168.1.0 * 255.255.255.0 U 303 0 0 wlan0
192.168.2.0 * 255.255.255.0 U 202 0 0 eth0
If I perform a traceroute to some outside address, I see that it goes through the first router 192.168.2.1. If I remove one route with
$ route del default eth0
and run traceroute to the same address, I see that is now uses 192.168.1.1.
My questions.
Which of the two default routes is picked? Is it always the first one listed by route, or is it chosen every time according to some criteria?
If one default route has higher priority, how does it get chosen? Is it simply the interface that came up first during boot?
If I want to have a preferred route or even remove one of the two default routes, how do I do that? Is it sufficient to delete the route using
$ route del default eth0
or will this route be added again automatically each time the client is assigned a new address?
Some context to my questions: Computer X is attached to networks A and B using DHCP. The A-router should serve as a gateway for X but the B-router should not: the B-router should only allow X to communicate with computers on network B.