10

I configured my RPi to connect to a 3G dongle on boot by setting ppp and wvdial on

/etc/network/interfaces

The Pi boots up and I have internet connection. Perfect.

Now my problem is that whenever I connect the Pi to my computer via ethernet (using this tutorial) the internet connection is lost. Even after disconnecting from my computer it stills doesn't connect, I need to reboot so it can get internet connection again.

Is there a way to make the Pi stay connected to the internet through the dongle's interface instead of it trying to make it through the connection to my computer?

  • Do both connections use DHCP ? – Lawrence Apr 11 '14 at 8:44
  • What does your ifconfig output look like? – Bex Apr 11 '14 at 14:20
  • Setting a higher metric on eth0 than ppp0 should achieve what you want. The lower metric is the higher priority one. – Lawrence Apr 14 '14 at 4:38
6

Assuming your working with linux (raspian, debian, etc...):

Your asking two different questions, First I'll answer the title question:

Force Raspberry to get internet from specific network

I'm going to lock onto your word "network" (as opposed to "interface") and answer this in a pure IP sense:

If you have multiple connections that could provide the internet, you control which will be used via the route table.

To the view the routing table I normally use netstat -rn (-r is for "show routing", -n is for "show me numbers, don't try and do DNS lookups, which might hang if my internet isn't configured right"). A really simple example would look like this:

pi@homeServer ~ $ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.9.1     0.0.0.0         UG        0 0          0 eth0
192.168.9.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
172.20.10.0     0.0.0.0         255.255.255.240 U         0 0          0 wlan0
pi@homeServer ~ $ 

The line in that output that shows which way IP packets will go is the line with a dest of 0.0.0.0 and a genmask of 0.0.0.0, that is normally known as the default route (a mask of 0.0.0.0 is all wildcard, thats really the marker of a default route), and as it currently points to a specific address in the `192.168.9' range, internet traffic will go via ethernet interface.

If I want to switch my internet to the other network I would (as root) use the route command, and in this case, given that my wifi connection isn't point-to-point I must know the ip address of the router that can forward traffic out of that network (In my case that is 172.20.10.1) so I would do:

  1. Delete the current default route

    sudo route del default
    
  2. Add a new default route for the other network

    sudo route add default gw 172.20.10.1
    

FYI while route is what I use, I see the some consider it deprecated and instead recommend using the ip route command, see @Fred 's comment below for syntax. reference for deprecation

Is there a way stay connected through the dongle's interface

Its been a while since I've worked with ppp and wvdial, and without configs (or at least references to the guides you followed in setting them up) its really hard to guess which problems your running into, but as a few ideas:

  • Is the connection really down or did you just lose your default route when your eth0 came up?
    • Check this in both netstat -rn and ifconfig.
    • Is an interface in netstat -rn? if so, is there a default route to it?
    • In ifconfig do you see interface for the dongle (likely ppp)? is it UP?
  • I can't remember where ppp/wvdial log, but that should be checked. That log will tell you connection state, and should let you know if the whole system has shut down for some reason
  • If you see an interface, try to ping something (... anything ...) on it, and see if the connection comes up.
    • I know the ppp/wvdial combo has some automatic connection capability (depending on configuration)
      • So if the connection came up with a ping (or the connection has stayed up the whole time): it could be the (ppp) default route got lost when you brought up the ethernet.
      • If this is the problem you would just need to add a default route and the whole system would come back online.
  • 2
    ip route doesn't quite use the same syntax. However, you can copy and paste it's output to use as input. For example, if it shows default via 192.168.9.1 dev eth0, you can remove that route simply by executing ip route del default via 192.168.9.1 dev eth0. You can easily use the output as a template to add new commands, e.g. ip route add default via 172.20.10.1 dev wlan0. – Fred Apr 11 '14 at 20:02

protected by Ghanima May 1 '17 at 15:29

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.