How can I tell if my multiple network interfaces are working ok?
The reason why your bind does not work has nothing to with bind, a trick I use too, and everything to do with the fact that you have only one default gateway, on the usb0
NIC, while you should have one on either NIC, otherwise connection to WAN sites from wlan0
will not be routed.
Linux allows the existence of multiple gateways (one per interface, virtual or not), under the regimen of policy-based routing
. What you need to do is to have two separate routing tables, one for usb0
and one for wlan0
, and a rule telling the kernel which one to use; then binding
an application to either interface will allow you to reach WAN sites.
You handle two routing tables as follows: First, create two tables (Replace and with sensible names, same with IP1, DEV1, and so on):
echo 200 <NAME1> >> /etc/iproute2/rt_tables
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 <NAME1>
ip route add <NET2> dev <DEV2> src <SRC2> table <NAME2>
Then a default route:
ip route add default via <IP1> table <NAME1>
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 <NAME1>
ip rule add from <IP2> table <NAME2>
Now you can bind application to either interface.