Why doesn't ifconfig show the default gateway?

Asked by LEGOManiac

I've run into a mess of problems with two Ubuntu PCs which have me looking closely at the network config.

Is there a logical reason why ifconfig doesn't show something as important as the default gateway on a given interface? I've been trying to figure out how to display it from the command line.

I did manage to check it via the GUI and discovered it had been set to 0.0.0.0, although how, I don't know. It's been working for weeks.

At any rate, is there a command-line utility that will provide *all* the interface config information in one place?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
costi
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
LEGOManiac (bzflaglegomaniac) said :
#1

I've discovered:

cat /etc/network/interfaces

On one machine this shows my IP, mask and gateway.

On this PC, however, it just shows:

cat /etc/network/interfaces
auto lo
iface lo inet loopback

That puzzles me. I had expected to see my network information. It occurred to me that it might indicate an address that's provided by DHCP so I checked and I have in fact set it manually.

Obviously I can't rely on cat /etc/network/interfaces to give me the information I was looking for w.r.t. default gateways.

As an aside to my main question, why is /etc/network/interfaces giving me completely different information on two different computers with static IPs?

Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#2

Might be the "ip" command give you some info about the default gateway and other infos.

Hope this helps

Revision history for this message
LEGOManiac (bzflaglegomaniac) said :
#3

I hadn't heard of the "ip" command. Thanks for that. I've played with it now and it still doesn't seem to be as comprehensive as Windows' "ipconfig".

Revision history for this message
Thomas Krüger (thkrueger) said :
#4

Well, you ask why ifconfig does not show the default gateway of an interface.
There is nothing like a default gateway on a interface. It is set globally over all interface in the routing table, there can also be multiple or no at all. So the default gateway is not a matter of interface configuration but of the routing. Showing it is just not the job of an interface configuration tool.
To see the routing table use "route -n", "ip route show" or look into /proc/net/route.

Revision history for this message
LEGOManiac (bzflaglegomaniac) said :
#5

Technically, I disagree on this point. Each network interface (generally) has one or more IP addresses associated with it. Each IP address must belong to a valid network (ie. 192.168.57.0 is not a valid IP for a host) and each network must have a default gateway if anything on that network is to find it's way to another. Hence, the default gateway is an integral part of the network definition. Failure to define it properly renders a port useless for traffic outside of the LAN.

The problem I encountered was strongly suggestive of a network interface that doesn't have a default gateway associated with it. Yes, I realize this is not programmed into the interface itself, but, as the gateway information is critical to fully utilizing a given interface, it is logical to include that information when showing the IP and netmask info as IPCONFIG does but IFCONFIG doesn't.

Here's where it gets a bit mysterious: I tried your suggestions and only 'route -n' shows the IP, netmask and default gateway - supposedly.

What bothers me is that I'm sending this information from that machine, which clearly is using a default gateway and yet both 'route -n' and 'ip route show' both say that my gateway is 0.0.0.0 which, if true, would render this computer incapable of internet access, barring a dedicate routing table entry to launchpad.net which, needless to say, I haven't set up.

Checking the GUI (System->Preferences->Network Connections->Wired->Wired Connection 1->edit->ipv4 settings, it shows that my system has the default gateway of 192.168.0.1, which is correct.

I was looking for a command line tool that would have told me the same thing and, indeed, I'm puzzled as to why both the route and ip commands say it's 0.0.0.0, which is clearly wrong.

Can anyone shed some light on why there is a desparity between what the GUI says and what the command line says?

For that matter, is there a command that will give me reliable info?

For reference sake, I've pasted the output from the three commands below:

legomaniac@PentiumD64:/etc/squid$ ip route show
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.200
169.254.0.0/16 dev eth0 scope link metric 1000
legomaniac@PentiumD64:/etc/squid$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
legomaniac@PentiumD64:/etc/squid$ cat /proc/net/route
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
eth0 0039A8C0 00000000 0001 0 0 0 00FFFFFF 0 0 0
eth0 0000FEA9 00000000 0001 0 0 1000 0000FFFF 0 0 0

Revision history for this message
LEGOManiac (bzflaglegomaniac) said :
#6

Technically, I disagree on this point. Each network interface (generally) has one or more IP addresses associated with it. Each IP address must belong to a valid network (ie. 192.168.57.0 is not a valid IP for a host) and each network must have a default gateway if anything on that network is to find it's way to another. Hence, the default gateway is an integral part of the network definition. Failure to define it properly renders a port useless for traffic outside of the LAN.

The problem I encountered was strongly suggestive of a network interface that doesn't have a default gateway associated with it. Yes, I realize this is not programmed into the interface itself, but, as the gateway information is critical to fully utilizing a given interface, it is logical to include that information when showing the IP and netmask info as IPCONFIG does but IFCONFIG doesn't.

Here's where it gets a bit mysterious: I tried your suggestions and only 'route -n' shows the IP, netmask and default gateway - supposedly.

What bothers me is that I'm sending this information from that machine, which clearly is using a default gateway and yet both 'route -n' and 'ip route show' both say that my gateway is 0.0.0.0 which, if true, would render this computer incapable of internet access, barring a dedicate routing table entry to launchpad.net which, needless to say, I haven't set up.

Checking the GUI (System->Preferences->Network Connections->Wired->Wired Connection 1->edit->ipv4 settings, it shows that my system has the default gateway of 192.168.0.1, which is correct.

I was looking for a command line tool that would have told me the same thing and, indeed, I'm puzzled as to why both the route and ip commands say it's 0.0.0.0, which is clearly wrong.

Can anyone shed some light on why there is a desparity between what the GUI says and what the command line says?

For that matter, is there a command that will give me reliable info?

For reference sake, I've pasted the output from the three commands below:

legomaniac@PentiumD64:/etc/squid$ ip route show
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.200
169.254.0.0/16 dev eth0 scope link metric 1000
legomaniac@PentiumD64:/etc/squid$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
legomaniac@PentiumD64:/etc/squid$ cat /proc/net/route
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
eth0 0039A8C0 00000000 0001 0 0 0 00FFFFFF 0 0 0
eth0 0000FEA9 00000000 0001 0 0 1000 0000FFFF 0 0 0

Revision history for this message
Best costi (kyky) said :
#7

Your /etc/network/interfaces is so empty because that part is taken care of by NetworkManager.
And yes, the gateway is NOT a global setting of the machine but it does pertain to the interface. Why it does not appear in the output of ifconfig it's not clear to me either.
Back to the initial issue, I just configured a desktop system with 2 interfaces, and just like you I discovered that the interfaces were not listed in /etc/network/interfaces. That and reading that NetworkManager has some issues with static IP addressing has led me to uninstall NetworkManager and add the relevant lines in /etc/network/interfaces (Maybe this is a good solution for you as well). Mine now looks like this:

auto lo
iface lo inet loopback

#primary
auto eth0
iface eth0 inet static
        address 192.168.2.100
        netmask 255.255.255.0
        network 192.168.2.0
        broadcast 192.168.2.255
        gateway 192.168.2.1

#secondary
auto eth1
iface eth1 inet static
        address 192.168.2.101
        netmask 255.255.255.0
        network 192.168.2.0
        broadcast 192.168.2.255

I indeed do not have any gateway on the second interface but that is because both are configured on the same subnet. A more typical scenario would be one where eth1 is on the public internet and the config file would look like this:

auto lo
iface lo inet loopback

#primary
auto eth0
iface eth0 inet static
        address 192.168.2.100
        netmask 255.255.255.0
        network 192.168.2.0
        broadcast 192.168.2.255
        gateway 192.168.2.1

#secondary
auto eth1
iface eth1 inet static
        address 216.171.15.2
        netmask 255.255.255.252
        network 216.171.15.0
        broadcast 216.171.15.15
        gateway 216.171.15.1
Note that in this case each interface has a different gateway and both have it defined. Yes, the concept of gateway is tightly connected to that of routing but it is basically saying: this particular interface communicates with other networks through the device at.....
Hope this helps.

Revision history for this message
LEGOManiac (bzflaglegomaniac) said :
#8

Thanks costi, that solved my question.

Revision history for this message
John Ward (automail) said :
#9

As far as I know what "route -n" shows is not incorrect, confusing, but in terms of the networking specification and language it's not completely incorrect. If you've ever set up static routes in Linux or Windows the "destination" network is specified as the device that helps you get there - the default gateway. It's odd but not necessarily wrong. If you do advanced networking courses it all starts to make sense. Actually I've just realised "Costi" said that.

I do agree that ifconfig should show Default Gateway, or possibly a new Linux command that shows all relevant IP info. such as IP address, Subnet Mask, DNS servers, Auth. DHCP server, and Default Gateway.

Lets call it "ipinfo".