LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Change dynamically internet default interface (https://www.linuxquestions.org/questions/linux-networking-3/change-dynamically-internet-default-interface-4175442873/)

Tekiano 12-25-2012 03:39 AM

Change dynamically internet default interface
 
Hi,

I use my pc as a router for other equipments, I have these interfaces that can connect my pc to internet :
ppp0 and wlan0,
so I want that the system routes internet packets throw wlan0 when wlan connection is available otherwise via ppp0,
I tried to configure this using metric settings but it failed :

Code:

ifconfig wlan0 metric 1
ifconfig: SIOCSIFMETRIC: Operation not supported

ifconfig ppp0 metric 10
ifconfig: SIOCSIFMETRIC: Operation not supported


$route
default      *              0.0.0.0        U    0      0        0 ppp0
X.X.X.0      *              255.255.255.255 UH    0      0        0 ppp0
192.168.1.0  *              255.255.255.0  U    0      0        0 wlan0

could you please tell me how to configure this using the metric, and is it the best way to do it ?

Thank you

Ser Olmy 12-25-2012 08:03 PM

A metric is associated with a route, not an interface. You can add a default route using the ip route command:
Code:

ip route add 0.0.0.0/0 dev ppp0 metric 50
Or you can use the route command:
Code:

route add -net 0.0.0.0 netmask 0.0.0.0 metric 50 dev ppp0
If the wlan0 interface gets an address and gateway via DHCP and the metric value is lower then the one specified for the default route via ppp0, the former will take precedence.

Tekiano 12-26-2012 04:10 AM

Thanks for your reply,
I tried your command, here the results :

Code:

$ip route add 0.0.0.0/0 dev ppp0 metric 50
$route
default        *              0.0.0.0        U    0      0        0 ppp0
default        *              0.0.0.0        U    50    0        0 ppp0
10.25.25.25    *              255.255.255.255 UH    0      0        0 ppp0
192.168.0.0    *              255.255.255.0  U    0      0        0 eth0
192.168.253.0  *              255.255.255.0  U    0      0        0 tap0
192.168.254.0  *              255.255.255.0  U    0      0        0 wlan0

$traceroute www.google.com
traceroute to www.google.com (173.194.70.147), 30 hops max, 38 byte packets
 1  10.203.11.14 (10.203.11.14)  67.985 ms  59.632 ms  49.820 ms
....

I see that even if wlan0 is connected to internet the route is throw ppp,
I need that connection to internet must be through wlan, and I also need to keep my vpn connection that was established through ppp0
Does any one have an idea how to do this ?

Ser Olmy 12-26-2012 04:46 AM

As you can see, you still have a default route through ppp0 with a metric of 0 in addition to the route you added manually. Also, you don't actually have a default route through a gateway on the wlan0 network.

The default route through ppp0 is probably added by a connection script. Exactly how do you activate the ppp0 connection?

Tekiano 12-26-2012 04:54 AM

I just use the followin command :
Code:

pppd call ppconfig
and then the interface ppp0 is up automatically

after that I launch openvpn to establish the tunnel.

Ser Olmy 12-26-2012 05:10 AM

You should find a configuration file called "ppconfig" in /etc/ppp/peers/. It should contain the keyword "defaultroute", which causes pppd to create a default route with a metric of 0. You will need to remove or modify that route.

The ideal solution would be to have pppd create a default route with a higher metric. There was a proposed patch to pppd which added a "defaultroute-metric" option, but I don't think it was ever accepted into the official pppd project.

You could change the "defaultroute" option to "nodefaultroute" and add an "ip route add" command to /etc/ppp/ip-up, or you could leave "defaultroute" and use "ip route change" in /etc/ppp/ip-up instead.

Of course, none of this will make any difference as long as you don't have an alternative default route through the wlan0 network.


All times are GMT -5. The time now is 04:19 PM.