kaze72
Posts: 2
Joined: Thu Oct 30, 2014 3:36 pm

Cannot get default gateway to work

Thu Oct 30, 2014 3:52 pm

Hi,

I log in to the Pie using SSL, so my LAN connection works properly. I have configured my router (ASUS RT-N56U) to always give me a certain ip (192.168.1.20). I can reach everything in my LAN. The problem is that there is no default gateway set. Shouldn't dhcp give that? When I do:

Code: Select all

sudo route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
I can see that the gateway is missing. If I do an ip refresh, everything starts to work:

Code: Select all

[email protected] /etc/network $ sudo dhclient
RTNETLINK answers: File exists
[email protected] /etc/network $ sudo route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
[email protected] /etc/network $
It's annoying to have to go through this every reboot, and also, not having Internet when booting up, for ntp (clock setting) etc.

Manually adding the default gateway also works:

Code: Select all

sudo route add default gw 192.168.1.1
But only until next reboot.

This is what my /etc/network/interfaces looks like:

Code: Select all

auto lo

iface lo inet loopback
iface eth0 inet dhcp
up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 metric eth0

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
I'm not using the wireless connection, just a cable to the router.

What can cause this problem? I have spent hours trying different combinations and configurations. Any help would really be appreciated.

User avatar
DougieLawson
Posts: 35364
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Cannot get default gateway to work

Thu Oct 30, 2014 4:00 pm

Try adding

Code: Select all

auto eth0
to your interfaces file. Get rid of the UP statement.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

kaze72
Posts: 2
Joined: Thu Oct 30, 2014 3:36 pm

[SOLVED] Re: Cannot get default gateway to work

Thu Oct 30, 2014 4:15 pm

Oh my god, it worked! You would not believe how many form posts etc I've been through today, and no one has mentioned this before.

Thank You!

User avatar
Shoka
Posts: 143
Joined: Sat Jul 12, 2014 8:35 pm
Location: Manchester, UK

Re: Cannot get default gateway to work

Thu Oct 30, 2014 9:20 pm

If you are wondering what was wrong with that route add command, several things come to mind:


up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 metric eth0

1) In effect that command will run after the interface comes up... and you were not telling the interface to come up..
2) You can target an interface, or a next hop, but not normally both
2) More importantly than the detail of the command however that route as specified would only send out traffic for your local ip network. That route is added by default when you add an IP address to an interface in any case, so is completely redundant

What I think you wanted was to match all destination addresses and send that traffic out to 192.168.1.1.

That would be -net 0.0.0.0 netmask 0.0.0.0 though the route command provides a "default" statement that is a synonym for that route.

from the route manpage

route add default gw mango-gw
Cheers Harry

jimer
Posts: 3
Joined: Tue Oct 01, 2013 7:02 am

Re: Cannot get default gateway to work

Wed Feb 11, 2015 5:11 pm

This can also be caused by a weak network connection. I have a wired network but connected to a wi-fi hub, where the network is obtained from the wifi and then sent to the wired hub. The signal strength is poor and it keeps dropping out. When the RPi starts up it never seams to get the gateway - a stronger signal cured this.

wrinklytech
Posts: 1
Joined: Tue Mar 03, 2015 8:54 pm

Re: Cannot get default gateway to work

Tue Mar 03, 2015 9:01 pm

In case anyone is still looking for a solution to this issue, I've just had the same experience with a new RPI2. I set this machine up headless using the cmdline.txt trick (adding a static IP to this file in /boot). This allowed access from my LAN, but I couldn't get internet access without adding the default route manually after each reboot. After half a day fruitlessly trying various suggestions found on the web, it occurred to me to take the static ip entry out of cmdline.txt, and lo and behold the default route appeared in the routing table after rebooting. HTH someone :)

KenOh92
Posts: 2
Joined: Sat Sep 12, 2015 6:07 pm

Re: Cannot get default gateway to work

Mon Sep 14, 2015 1:44 am

Hello all..

My case is similar to him

When i command

route

It returns:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface

It is all blank. It provides no information about all these parameters

Return to “Raspbian”