Why is router IP not listed in ifconfig?

5

4

I am looking for the address that I type into my browser to get to the router configuration file. It ended up being 192.168.1.1, as usual. But when I enter ifconfig into the command line, this IP address is not listed anywhere.

Why is this? Shouldn't ifconfig give me the IP address of the router?

If the router IP address were something else instead of 192.168.1.1, how would I find out what it is?

user192380123

Posted 2015-06-30T11:20:52.240

Reputation: 77

2ifconfig only displays information about local interfaces. The IP address of your gateway is part of the gateway's local interface information. – Larssend – 2015-06-30T11:26:02.950

1i think the easiest way to find the router IP is to use traceroute 8.8.8.8 - first one on the list will be your router's ip address. If this does not work it will also tell you that you do not have a valid connection established with router. (I'm ommiting situation when your router is blocking ICMP traffic on LAN which is rare configuration). – mnmnc – 2015-06-30T11:34:51.187

1@geewee bertieb commented and it should be put here too. (to the point that the public IP wont' be shown there). "OP's question asks about configuration page and mentions a private subnet IP, so the assumption is that he is looking for the LAN interface IP. The router's IPs - WAN or LAN - are not shown by a client ifconfig, hence the enquiry" - bertieb – barlop – 2015-06-30T14:31:31.717

@barlop: doesn't change the fact that the router's interface isn't local to the PC/host, hence beyond the scope of ifconfig. – Larssend – 2015-06-30T17:09:06.320

@geewee well, one of the router's interfaces is local, one isn't. He's referring to the private/local one though – barlop – 2015-06-30T17:36:13.573

Thanks for reposting that here @geewee, it made more sense in the context of the answer it was attached to. I think there is some confusion over "local" in the sense of 'to a machine' (as barlop means) and "local" in the sense of 'within a LAN'. I think OP is confused about output as ifconfig lists things additional things like broadcast address and subnet mask. Worth knowing about the routing table anyway! – bertieb – 2015-06-30T18:17:12.007

Well I mixed up @barlop and geewee in that comment! – bertieb – 2015-06-30T20:23:31.733

@barlop: you don't understand what is meant by 'local interface'. That's why you get confused. It has nothing to do with private/public interface. – Larssend – 2015-06-30T22:27:10.217

@geewee I see you didn't mean The interface that is on the same subnet as the computer. and you meant the strict definition of local - The interface that is part of the computer. I didn't realise ifconfig was so <ccough> that it doesn't show the default gateway only the local interfaces. I guess I bought too much into the claim often made by users of linux and windows, that ifconfig is the linux alternative to ipconfig(ipconfig of course does show both IPs of local interfaces and the IP of the default gateway) – barlop – 2015-06-30T22:56:40.433

Answers

5

If the router IP address were something else instead of 192.168.1.1, how would I find out what it is?

Assuming some flavour of Linux:

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

(note on some flavours like Debian, route is not in $PATH for a non-root user, and you may have to use /sbin/route, or you can invoke netstat -rn for the same info)

In most common home cases, the router will be listed as the gateway for 0.0.0.0- in this made-up example 192.168.2.1.

If you want to find out more about the meaning of the output of route, see the question over on unix.se:

Understanding the output of route -n

Shouldn't ifconfig give me the IP address of the router?

ifconfig does not show gateway information - use 'route' to view or manipulate routing info.

bertieb

Posted 2015-06-30T11:20:52.240

Reputation: 6 181

1

Issue the command: ip route to find the address of the router(s) configured on your system.

To learn how to use it, simply do ip route help to see all the options.

The command ip can give you a lot of information about the IP configuration. Keep in mind that ifconfigis being deprecated on Linux.

jcbermu

Posted 2015-06-30T11:20:52.240

Reputation: 15 868

0

netstat -nr

It will display directly the gateway address, which in the case of connections via router is the router IP address (example: 192.168.1.1).

Overmind

Posted 2015-06-30T11:20:52.240

Reputation: 8 562