2

I often use Wi-Fi from some public networks which don't allow some protocols (like torrent or IRC - next I will only speak about IRC). If I want to use one of those protocols, I have to use my phone 3G connection (through the usb0 interface).

I'd like to stay connected to the Wi-Fi for my web navigation (so use the classical wlan0 interface), but use another interface (here usb0) for some softwares (often only for weechat, a CLI IRC client).

Thus I have two (linked) questions :

  • how to simultaneously connect to two interfaces without all messing things up ?
  • how to configure one software to use an interface, and another software to use the other interface ? As weechat is a CLI software, maybe I just have to declare a specific environment variable ; but how to be sure that Firefox doesn't use usb0 instead of wlan0 ?
2

The simplest solution is to have two separate routing tables; one of them (wlan0, in your case) will be the default one, while we can use a neat trick to force a specific application to use the non-default table.

First, create two tables (substitute NAME1 with a name making sense to you, same thing with IP1, DEV1, and so on):

echo 201 NAME2 >> /etc/iproute2/rt_tables

Add a gateway to each routing table (if needed):

ip route add NET1 dev DEV1 src SRC1 table main
ip route add NET2 dev DEV2 src SRC2 table NAME2

Then a default route:

ip route add default via IP1 table main
ip route add default via IP2 table NAME2

Then the rules to select the route table based on the source address:

ip rule add from IP1 table main
ip rule add from IP2 table NAME2

Now we need to force weechat to use IP2.We do so by building a new bind module. It is trivial to do so, there are simple instructions in the reference. Once you have compiled the module and placed in /usr/lib, you issue the command:

 BIND_ADDR=IP2 LD_PRELOAD=/usr/lib/bind.so weechat

and you are done. The advantage of this is that it can be easily scripted, and can be repeated for as many applications as you like.

2

If you define two sub-networks, for example:

  • 192.168.1.x / 255.255.255.0 - wlan0
  • 192.168.2.x / 255.255.255.0 - usb0

If you define gateway only for wlan0, all network traffic beside addressed directly to 192.168.2.x goes through wlan0.

You can route network traffic to specific IP addresses through you usb0 interface. You can also route the traffic over specific interface for a process in linux.

  • The sentence You can route network traffic to specific IP addresses through your usb0 interface is wrong. If you only have one gateway, on the other interface, how can you route to any given WAN addresses on the usb0 interface? You barely mention a solution. – MariusMatutiae Nov 24 '15 at 11:50
  • @MariusMatutiae man route -> gw GW -> "If you specify the address of one of your local interfaces, it will be used to decide about the interface to which the packets should be routed to.". – g2mk Nov 24 '15 at 15:56
  • Just try it, see whether it works. I did a few hours ago, it did not. – MariusMatutiae Nov 24 '15 at 15:59
  • @MariusMatutiae I haven't see your route command, I don't know you network configuration... Try to ask a question then :P Yes your answer is better and even I - in opposition to you - upvoted you. – g2mk Nov 24 '15 at 16:04

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.