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:
Delete the current default route
sudo route del default
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.