[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: preferring wired over wireless



On Saturday 05 November 2005 16:06, François TOURDE wrote:
> Le 13092ième jour après Epoch,
>
> Luca Pireddu écrivait:
> > When both my wireless and wired networking devices are connected, how can
> > I get my laptop to use the wired device and ignore the wireless one?  I
> > tried specifying a higher metric for my wired device (via ifconfig
> > metric), but it doesn't seem to have an effect.
>
> If both interfaces are on same network, metric can't help you... You
> must use "ip rule" and "ip route" without default route to solve your
> problem.

That would explain the behaviour I was seeing.

>
> man ip
>
> and contact me (us) again if you have problems.
>
> For example:
>
> # eth1 = wired
> # eth2 = wireless
>
> /sbin/ip rule add prio 50 table main
> /sbin/ip route del default table main
>
> /sbin/ip rule add prio 201 from <wired_ip>/32 table 201
> /sbin/ip route add default via <wired_gateway> dev eth1 src <wired_ip>
> proto static table 201 /sbin/ip route append prohibit default table 201
> metric 1 proto static
>
> /sbin/ip rule add prio 202 from <wireless_ip>/32 table 202
> /sbin/ip route add default via <wireless_gateway> dev eth2 src
> <wireless_ip> proto static table 202 /sbin/ip route append prohibit default
> table 202 metric 1 proto static
>
> /sbin/ip rule add prio 222 table 222
> /sbin/ip route add default table 222 proto static nexthop via
> <wired_gateway> dev eth1 weight 2 nexthop via <wireless_gateway> dev eth2
> weight 1

Thanks for the tip on using routing rules and your example.  I think I have a 
solution (it seems to work!).  I'll post it here in case anyone is 
interested.

I wrote these two little scrips:

1. route_up

#!/bin/sh

set +e

if [ $IFACE == "eth0" ]; then
  # wired
  table=201
  priority=50
elif [ $IFACE == "eth1" ]; then
  # wireless
  table=202
  priority=100
fi

ip rule add priority $priority table $table
ip route add default via $IF_GATEWAY dev $IFACE proto static table $table

exit 0

-------------------------------------------------
2. route_down

#!/bin/sh

set +e

if [ $IFACE == "eth0" ]; then
  # wired
  table=201
elif [ $IFACE == "eth1" ]; then
  # wireless
  table=202
fi

ip rule delete table $table

exit 0
-----------------------------------------------------

I placed route_up in /etc/network/if-up.d and route_down 
in /etc/network/if-post-down.d.  Because of the differing priorities of the 
wired and wireless rules, the system always chooses the wired connection when 
they're both up---all without any manual intervention :-)

Thanks for all the replies.  I appreciate your help.

Luca



Reply to: