Do I have to change the default Gateway all the time, when changing connection type?

Asked by Gabriel Čenkei

See this post please, my question is in relation with it.
https://answers.launchpad.net/ubuntu/+question/33895

Hi guys,
I have an additional question. I had the same problem and thanks to this post I was able to solve it.
But one thing causes me some headache.
* I use cable/wifi connection mentioned above by default.
* This only works for me when I apply the "sudo route add default gw my_ip"
* Alternately I need to connect sometimes with gprs modem on my nokia 6300.
* Can use my nokia somehow without removing the default gw of my cable/wifi connection?
It is pretty annoying all the time removing it and then puting it back.
* Can you see some workaround for this?

Thanks for reading my post.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Henning Eggers
Solved:
Last query:
Last reply:
Revision history for this message
Henning Eggers (henninge) said :
#1

So this is a Notebook, right? You move around with it in different networks?

Are you ever connected to two networks at the same time? Because that would be the reason why you should change the gateway.

Revision history for this message
Gabriel Čenkei (gabox) said :
#2

No it's a desktop but it doesn't matter. It could be notebook.
The main reason is:
* My wifi connection is quick but terribly unstable. If it sometimes breaks (ISPs fault) I need to switch to mobile GPRS so I can send an e-mail or upload a file.
* I need to do this quite often, maybe once twice a week.
* It is not problem to change the default gw for me. But a newcomer can definitely hang on this.
* And your right, if it was a notebook it should be a bigger problem, because the switch cycle between networks could be higher.
* Is there any "default gw auto changer" or something?
* Anyway I do not understand, why I must put the default gw for my wifi/cable connection manually in terminal. Otherwise my network not works.

Thank you for som answers.

Revision history for this message
Henning Eggers (henninge) said :
#3

Please send me the output of the command

netstat -rn

On the following occasions:
#1 while standard connection through ISP works
#2 after the ISP connecion breaks
#3 after you make the GPRS connection
#4 after you enter the default gw command

Revision history for this message
Gabriel Čenkei (gabox) said :
#4

#1
gabo@gabov-desktop:~$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.10.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 vnet0
0.0.0.0 10.10.11.254 0.0.0.0 UG 0 0 0 eth1

#2
gabo@gabov-desktop:~$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.10.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 vnet0
0.0.0.0 10.10.11.254 0.0.0.0 UG 0 0 0 eth1

#3
gabo@gabov-desktop:~$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.6.6.6 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
10.10.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 vnet0
0.0.0.0 10.10.11.254 0.0.0.0 UG 0 0 0 eth1

gabo@gabov-desktop:~$ sudo route del default gw 10.10.11.254

#4
gabo@gabov-desktop:~$ netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.6.6.6 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
10.10.11.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 vnet0
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp0

PS: The vnet0 is a vmware virtual ethernet, I think it's is not important in this case.

Revision history for this message
Gabriel Čenkei (gabox) said :
#5

BTW: Thank You for Your effort. I just mention a fact that for my standard wifi/cable connection is set up a static IP 10.10.11.2
It is connected like this: (1) <-- wifi --> (2) <-- cable --> (3) <--cable--> (4.)

1.) ISP's transmitter
2.) Antenna on my roof
3.) Access Point somwhere on roof near antenna.
     I do not have access to it.
     I can switch it on and off in my room with AC Adaptor.
4.) Wired ethernet on my PC (eth1)

I think my ISP have some "double assigned the same IP" for some security reason.
I think the same IP is assigned for my eth1 and so for AP.
In the days of Ubuntu 7.04 there was no problem with gw.
It worked out of the box. For 7.10 and 8.04 I must put the default gw manually:
"sudo route add default gw 10.10.11.254" if I want to get net working.

Revision history for this message
Gabriel Čenkei (gabox) said :
#6

Just speculating: Maybe the root of my problem is, the eth1 is setup with static IP (not roaming mode) and my ISP not offer dynamic assigned IPs ?

Revision history for this message
Best Henning Eggers (henninge) said :
#7

Yes, the problem is quite clearly that although the standard connection is down as in not letting anything through(in #2), the interface itself (eth1) is still up and the default route to that interface remains. When you connect through ppp0, the pppd sees that existing default route and does not add a new default rotue of its own, let alone removing the old route.

The solution would be to take down eth1 before connecting through GPRS. You do this using "sudo ifdown eth1" and you bring up again by doing "sudo ifup eth1". Obviously, this is just as annoying as having to change the default gateway all the time but it is the cleaner approach.

The solution for not having to type in any command all the time is either to add a script to the /etc/ppp/ip-up.d that removes and adds default routes or to put the sequence "ifdown eth1 - connect ppp - ifup eth1" into a script tht you call when you want to connect.

Yes, the root of the problem is the static IP on that ISP connection because it leaves you with a useless default route when it breaks. From the OS's point of view the computer is connected to two networks once you bring up the GPRS connection and you need to tell it explicitly in which of the two it can find the default gateway.

Hope you find a solution that works for you.

Revision history for this message
Henning Eggers (henninge) said :
#8

BTW, the sequence "ifdown eth1 - connect ppp - ifup eth1" is not meant literally, that is not a valid shell script!

Revision history for this message
Gabriel Čenkei (gabox) said :
#9

Thank You for explaining this situation. We can leave it as some "case study". Positive is that this case is described and the root of the problem is recognized.

Revision history for this message
Henning Eggers (henninge) said :
#10

It would be great, though, if you could still mark my answer as "This solved my problem", if you feel like it. I just crave karma... ;-)

Revision history for this message
Gabriel Čenkei (gabox) said :
#11

Thanks Henning Eggers, that solved my question.