How-To Linux

What’s My IP, Again?

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.”

The typing is worth it. I promise.

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?

Because who doesn’t love layer 2?

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.

Won’t you be my neighbor?

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.

Sometimes you just gotta know your path to the net

resolvectl dns

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.

It’s always DNS

What about ip a?

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.

Leave a Reply

Your email address will not be published. Required fields are marked *