How to route traffic over specific interface on linux (debian)?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I would like to route traffic over usb0 (a cellular modem) when it is available instead of eth0. The ip address for usb0 may change over time. How do I create a route in this scenario since the ip address may change?
I tried: ip route add default dev usb0
but when I do this, I am able to ping from usb0 but no longer through eth0. Any thoughts why?
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.24.1.1 0.0.0.0 UG 10 0 0 eth0
172.19.200.136 * 255.255.255.252 U 0 0 0 usb0
172.24.1.0 * 255.255.255.0 U 0 0 0 eth0
linux iptables ping route iproute
add a comment |Â
up vote
1
down vote
favorite
I would like to route traffic over usb0 (a cellular modem) when it is available instead of eth0. The ip address for usb0 may change over time. How do I create a route in this scenario since the ip address may change?
I tried: ip route add default dev usb0
but when I do this, I am able to ping from usb0 but no longer through eth0. Any thoughts why?
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.24.1.1 0.0.0.0 UG 10 0 0 eth0
172.19.200.136 * 255.255.255.252 U 0 0 0 usb0
172.24.1.0 * 255.255.255.0 U 0 0 0 eth0
linux iptables ping route iproute
Usually whatever is used to set the variable IP address for theusb0
interface (maybe a DHCP client of some kind?) can provide the default route information too, when requested to do so. If there are other routes already present, you may need to explicitly configure it to add a new default route with a lower metric value than the already-existing one.
â telcoM
May 17 at 6:32
udhcpc set the ip but unfortunately it doesn't seem to create a new default route to the internet. It also does not provide the gateway ip address I'm guessing since this is cellular and can change. Is "ip route add default dev usb0 metric 0" the proper way of setting a new default route when gateway ip is not known?
â Felix
May 17 at 13:34
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to route traffic over usb0 (a cellular modem) when it is available instead of eth0. The ip address for usb0 may change over time. How do I create a route in this scenario since the ip address may change?
I tried: ip route add default dev usb0
but when I do this, I am able to ping from usb0 but no longer through eth0. Any thoughts why?
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.24.1.1 0.0.0.0 UG 10 0 0 eth0
172.19.200.136 * 255.255.255.252 U 0 0 0 usb0
172.24.1.0 * 255.255.255.0 U 0 0 0 eth0
linux iptables ping route iproute
I would like to route traffic over usb0 (a cellular modem) when it is available instead of eth0. The ip address for usb0 may change over time. How do I create a route in this scenario since the ip address may change?
I tried: ip route add default dev usb0
but when I do this, I am able to ping from usb0 but no longer through eth0. Any thoughts why?
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.24.1.1 0.0.0.0 UG 10 0 0 eth0
172.19.200.136 * 255.255.255.252 U 0 0 0 usb0
172.24.1.0 * 255.255.255.0 U 0 0 0 eth0
linux iptables ping route iproute
asked May 17 at 1:32
Felix
62
62
Usually whatever is used to set the variable IP address for theusb0
interface (maybe a DHCP client of some kind?) can provide the default route information too, when requested to do so. If there are other routes already present, you may need to explicitly configure it to add a new default route with a lower metric value than the already-existing one.
â telcoM
May 17 at 6:32
udhcpc set the ip but unfortunately it doesn't seem to create a new default route to the internet. It also does not provide the gateway ip address I'm guessing since this is cellular and can change. Is "ip route add default dev usb0 metric 0" the proper way of setting a new default route when gateway ip is not known?
â Felix
May 17 at 13:34
add a comment |Â
Usually whatever is used to set the variable IP address for theusb0
interface (maybe a DHCP client of some kind?) can provide the default route information too, when requested to do so. If there are other routes already present, you may need to explicitly configure it to add a new default route with a lower metric value than the already-existing one.
â telcoM
May 17 at 6:32
udhcpc set the ip but unfortunately it doesn't seem to create a new default route to the internet. It also does not provide the gateway ip address I'm guessing since this is cellular and can change. Is "ip route add default dev usb0 metric 0" the proper way of setting a new default route when gateway ip is not known?
â Felix
May 17 at 13:34
Usually whatever is used to set the variable IP address for the
usb0
interface (maybe a DHCP client of some kind?) can provide the default route information too, when requested to do so. If there are other routes already present, you may need to explicitly configure it to add a new default route with a lower metric value than the already-existing one.â telcoM
May 17 at 6:32
Usually whatever is used to set the variable IP address for the
usb0
interface (maybe a DHCP client of some kind?) can provide the default route information too, when requested to do so. If there are other routes already present, you may need to explicitly configure it to add a new default route with a lower metric value than the already-existing one.â telcoM
May 17 at 6:32
udhcpc set the ip but unfortunately it doesn't seem to create a new default route to the internet. It also does not provide the gateway ip address I'm guessing since this is cellular and can change. Is "ip route add default dev usb0 metric 0" the proper way of setting a new default route when gateway ip is not known?
â Felix
May 17 at 13:34
udhcpc set the ip but unfortunately it doesn't seem to create a new default route to the internet. It also does not provide the gateway ip address I'm guessing since this is cellular and can change. Is "ip route add default dev usb0 metric 0" the proper way of setting a new default route when gateway ip is not known?
â Felix
May 17 at 13:34
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
In the comments, you mentioned you're using udhcpc
as your DHCP client.
udhcpc
will pass the gateway address (or addresses, if there are several) to the script it runs (by default, /usr/share/udhcpc/default.script
) in a variable named router
. This script should then set the default gateway accordingly.
I'm guessing that the default script omits setting the default gateway if there is one already set.
Please see: https://udhcp.busybox.net/README.udhcpc
You cannot just shove packets out any old network interface. If the interface emulates Ethernet, like your usb0
probably does, the package needs a valid Layer-2 destination address. The system can get that automatically by doing an ARP request for the gateway's IP address... but that gateway IP address must be known first.
What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
â Felix
May 17 at 19:33
If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
â telcoM
May 18 at 5:25
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
In the comments, you mentioned you're using udhcpc
as your DHCP client.
udhcpc
will pass the gateway address (or addresses, if there are several) to the script it runs (by default, /usr/share/udhcpc/default.script
) in a variable named router
. This script should then set the default gateway accordingly.
I'm guessing that the default script omits setting the default gateway if there is one already set.
Please see: https://udhcp.busybox.net/README.udhcpc
You cannot just shove packets out any old network interface. If the interface emulates Ethernet, like your usb0
probably does, the package needs a valid Layer-2 destination address. The system can get that automatically by doing an ARP request for the gateway's IP address... but that gateway IP address must be known first.
What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
â Felix
May 17 at 19:33
If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
â telcoM
May 18 at 5:25
add a comment |Â
up vote
0
down vote
In the comments, you mentioned you're using udhcpc
as your DHCP client.
udhcpc
will pass the gateway address (or addresses, if there are several) to the script it runs (by default, /usr/share/udhcpc/default.script
) in a variable named router
. This script should then set the default gateway accordingly.
I'm guessing that the default script omits setting the default gateway if there is one already set.
Please see: https://udhcp.busybox.net/README.udhcpc
You cannot just shove packets out any old network interface. If the interface emulates Ethernet, like your usb0
probably does, the package needs a valid Layer-2 destination address. The system can get that automatically by doing an ARP request for the gateway's IP address... but that gateway IP address must be known first.
What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
â Felix
May 17 at 19:33
If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
â telcoM
May 18 at 5:25
add a comment |Â
up vote
0
down vote
up vote
0
down vote
In the comments, you mentioned you're using udhcpc
as your DHCP client.
udhcpc
will pass the gateway address (or addresses, if there are several) to the script it runs (by default, /usr/share/udhcpc/default.script
) in a variable named router
. This script should then set the default gateway accordingly.
I'm guessing that the default script omits setting the default gateway if there is one already set.
Please see: https://udhcp.busybox.net/README.udhcpc
You cannot just shove packets out any old network interface. If the interface emulates Ethernet, like your usb0
probably does, the package needs a valid Layer-2 destination address. The system can get that automatically by doing an ARP request for the gateway's IP address... but that gateway IP address must be known first.
In the comments, you mentioned you're using udhcpc
as your DHCP client.
udhcpc
will pass the gateway address (or addresses, if there are several) to the script it runs (by default, /usr/share/udhcpc/default.script
) in a variable named router
. This script should then set the default gateway accordingly.
I'm guessing that the default script omits setting the default gateway if there is one already set.
Please see: https://udhcp.busybox.net/README.udhcpc
You cannot just shove packets out any old network interface. If the interface emulates Ethernet, like your usb0
probably does, the package needs a valid Layer-2 destination address. The system can get that automatically by doing an ARP request for the gateway's IP address... but that gateway IP address must be known first.
answered May 17 at 13:57
telcoM
10.2k11032
10.2k11032
What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
â Felix
May 17 at 19:33
If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
â telcoM
May 18 at 5:25
add a comment |Â
What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
â Felix
May 17 at 19:33
If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
â telcoM
May 18 at 5:25
What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
â Felix
May 17 at 19:33
What happens if the cellular modem connects to a different gateway on its own later on , will that cause issues with routing table since it's using the initial gateway ip? Or would it automatically modify the routing table with the new gateway ip? You were right about udhcpc. It wasn't setting the default gateway because eth0 was already the default. I deleted the default before runnin udhcpc and it set it correctly.
â Felix
May 17 at 19:33
If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
â telcoM
May 18 at 5:25
If your default gateway changes, then your IP address is likely to change at the same time too. It's quite complex at the cellular network side of things, but basically the network should make sure you keep your IP+gateway while you have an active connection... but if you drop out of the cellular network completely, then your IP + gateway address may change. But that should be something that your DHCP client handles automatically after seeing that the network link was lost and then came back again.
â telcoM
May 18 at 5:25
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444271%2fhow-to-route-traffic-over-specific-interface-on-linux-debian%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Usually whatever is used to set the variable IP address for the
usb0
interface (maybe a DHCP client of some kind?) can provide the default route information too, when requested to do so. If there are other routes already present, you may need to explicitly configure it to add a new default route with a lower metric value than the already-existing one.â telcoM
May 17 at 6:32
udhcpc set the ip but unfortunately it doesn't seem to create a new default route to the internet. It also does not provide the gateway ip address I'm guessing since this is cellular and can change. Is "ip route add default dev usb0 metric 0" the proper way of setting a new default route when gateway ip is not known?
â Felix
May 17 at 13:34