I have the following situation:

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 usb0   U     9      0        0 wlan1   U     1      0        0 usb0

And I would want to use a one-liner to setup the gateway of to be (current secondary ip is
Can I use something like

sudo ip route add from via dev wlan1
RTNETLINK answers: File exists

Again, I need something temporary which forces all packets sent from to pass from gateway (don't want to setup a set of scripts/whatnot to do this). Is there a one liner I can use?


  • That can be made with asymmetric routing, but not as a one-liner as far as I know. More info on this: microhowto.info/howto/…
    – nKn
    Dec 28, 2015 at 15:28
  • 1
    No, you cannot: re-read my answer here, superuser.com/questions/1018196/… Dec 28, 2015 at 15:34
  • What do you mean by "sent from"? Do you mean having a source IP address of exactly Dec 28, 2015 at 15:44
  • Gateways are per route, and Routes are per destination (Not Source) so you cannot set a gateway for a secondary IP; you can only set the gateway on the to In that case all traffic destined for the net will go through, but it will do so regardless of whether the traffic is sourced from or another ip on that LAN. Dec 28, 2015 at 15:49
  • @MariusMatutiae I'll try the below first answer; I hope you're wrong, but you migth be just right :)
    – Emanuele
    Dec 28, 2015 at 17:49

1 Answer 1


The way to force all of your traffic thru wlan1 instead instead of usb0 is to force a new gateway: as sudo,

ip route del default
ip route add default via dev wlan1

(I assume your gateway has IP address, if not change accordingly). You can restore the previous situation by means of

ip route del default 
ip route add default via dev usb0

If you do not know/remember the IP address of the gateway, then use instead

ip route del default
dhclient -v usb0

(-v option is for verbose, it does not exist on all distros, you may have to drop it).

You may also decide that you would like to have two gateways, one per interface; with the Linux kernel (and only with the Linux kernel) this can be done, you find in David'Schwartz's answer an excellent short explanation of how to do it. Once you do, you will have to decide thru which interface the output of each application passes (you can decide on a per-application basis). This means that a given application, say ssh may bind to either interface, or, in other words, that the IP address from which ssh starts can be either that of usb0 or that of wlan1; the rule discussed by David Schwartz then takes care automatically of routing correctly ssh.

Notice that this way, you may have one ssh connection go thru wlan1, and another one going thru wlan1.

You must log in to answer this question.

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