i have a board with linux-3.20 and it have 4G modules. when i startup i can run "pppd call quectel-ppp &" get a ppp0 interface.i also have eth0/eth1 interface,eth0 can connect to the Internet,now i want connect to the Internet by eth0(priority) or ppp0,my route show

Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth1 10.64.64.64 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

now if i want use eth0 connect to the Internet, i should execute route del -net 0.0.0.0 netmask 0.0.0.0 dev eth0 and route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.2.1 dev eth0 , if i want use ppp0,i should execute route del default and route add default dev ppp0

so i create a shell script

while true do #eth0 can ping,use eth0 route del -net 0.0.0.0 netmask 0.0.0.0 dev eth0 route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.2.1 dev eth0 ping -c 1 -w1 -I eth0 unix.stackexchange.com if [[ $? != 0 ]];then #eth0 error,use ppp0 if ppp0 up if ifconfig |grep ppp0;then route del default route add default dev ppp0 fi fi sleep 10; done

it does work,but it will make net pack lose a lot also,so can i create route table with connect the internet by eth0 priority and ppp0 second(if eth0 not link or eth0 cant connect internet) automatic?

  • That's a FAQ. No, you cannot. See other variants of this question for more detail. – dirkt Aug 10 at 11:32

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.