or, I can’t remember what the commands are. I promise to write them down this time...
Before we get into the amazingness of the
ip command, I want to tell you who this guide isn’t for. It’s not for those who deliberately install a Linux operating system that strips out
systemd or eschews other technical Linux advancements — but let’s face it, I’ll probably write a guide for that sometime. It’s also not for those that want a GUI only way to find this information — that’s highly dependent on your desktop environment of choice.
This guide is for people on modern Linux desktops or servers that just happen to find themselves in the terminal when they decide networking information is needed.
ip -br -c a
This command is likely the one you’re looking for. This command and the later
ip commands break down like this.
ip queries the IP stack,
-br (brief) requests the information be formatted and slimmed down as much as possible,
-c (color) adds a splash of color, and finally
a (notice there’s no
-) is short for “address.”
ip -br -c l
This command, like the previous command asks
ip to be brief, and colorize, but instead of querying the addresses, it asks for the data link information with
l. In other words, what’s my MAC address?
ip -br -c n
A little into the weeds, but this command can be really useful if you need to know the IP or MAC addresses of the devices your computer has been in contact with. The router will, no doubt, be on the list, but so will others in many cases. STALE in the output here just means my machine hasn’t communicated with this entry in a while, while FAILED is where things end up after prolonged non-contact.
ip -c r
This command answers the age old question of “What’s my default gateway?” This is also called “router” or “default route” in some cases. Regardless, it will show the IP address that your router uses to forward your traffic out to the internet. You get this with the
r at the end. Keep your eye on that first line. It starts with
default via. That’s your default gateway.
Now we’ve come to the real reason I wrote the disclaimer above. Without
systemd you won’t have
resolvectl. So if you’re on Devuan or you’ve built from Arch and opted for SysV init, well, you’re out of luck. But if you’re doing that kind of thing, you don’t need a guide like this. For literally everyone else starting in about 2014, the command above will show you your configured DNS servers on each interface.
Gross. Have you seen the output?
Sure, it’s faster to type. That’s about all it’s got going for it. This is like a get-off-my-lawn-but-backwards issue. Let’s embrace adding color and formatting. You can do it the hard way if you want. The command’s right there, but I’m not responsible for the multiple wasted seconds trying to parse all that.