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

This writeup 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 and are unfamiliar with ifconfig or would rather use its successor, ip.

ip -br -c a

This command is likely the one you’re looking for. It 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 the a at the end (notice there’s no -) is short for “address.”

An image of a terminal window with the output of the command: ip -br -c a
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?

An image of a terminal window with the output of the command: ip -br -c l
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.

An image of a terminal window with the output of the command: ip -br -c n
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.

An image of a terminal window with the output of the command: ip -c r
Sometimes you just gotta know your path to the net

resolvectl dns

Sometimes you need to know what your current DNS provider is before making any changes. The command above will show you these DNS servers on each interface.

An image of a terminal window with the output of the command: resolvectl dns
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. Let’s add 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.

ifconfig is Dead

Most distributions have moved to the iproute2 package for networking tools, and ifconfig is slowly fading away.

Leave a Reply

Your email address will not be published.