How to route traffic over specific interface on linux (debian)?

The name of the pictureThe name of the pictureThe name of the pictureClash 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






share|improve this question



















  • 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














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






share|improve this question



















  • 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












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






share|improve this question











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








share|improve this question










share|improve this question




share|improve this question









asked May 17 at 1:32









Felix

62




62











  • 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
















  • 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















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










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.






share|improve this answer





















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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






























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.






share|improve this answer





















  • 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














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.






share|improve this answer





















  • 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












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.






share|improve this answer













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.







share|improve this answer













share|improve this answer



share|improve this answer











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
















  • 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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay