For a long time I've used ipconfig in Windows, and ifconfig in Unix to find out my local IPv4, for different purposes.

There are times when your screen is small, or you have an extensive amount of network adapters connected to your computer, making this list really extensive. I know you can pipe it into less, in order to avoid scrolling, and filter with grep, but that's rather cumbersome.

I was wondering if there was an easier way to find the basic information your DHCP provides you (gateway, IPv4, and subnet mask), without having to squint your eyes in order to find the numbers you are looking for, and without having to look up a command in your notes or Google.

  • 1
    It is unclear how this is answerable. "squinting eyes" is not an objective criterion, lots of network interfaces to report on would be lots of output however one generates it, and any other tool would presumably have to be looked up in notes too. The question moreover makes no mention of how many of said "extensive amount of network adapters" are allocated addresses via DHCP. If it is all of them, how, logically, do you expect to make a list shorter than all of the relevant adapters?
    – JdeBP
    Mar 4, 2019 at 1:14
  • 1
    Answer: No. You might as well ask, "How can I get everything by knowing nothing, and doing nothing?" However: the DHCP info is likely written to a log file on your system. On my system (Debian Stretch), I can get my IP & CIDR with journalctl | grep -Ei 'probing address'. I didn't have to squint my eyes, but I did have to make some effort to find this. Please read this, then edit your question.
    – Seamus
    Mar 4, 2019 at 8:12
  • @JdeBP If the only thing you're interested in is your host address, your gateway, and your subnet mask, then there is a lot of unnecessary information when doing an ifconfig request. Usually, all your NIC are listed, including those who are not in use right now. In most cases, you're looking for one IPv4 for your host, and one IPv4 for your gateway. I posted a solution myself with a better solution than ifconfig.
    – mazunki
    Mar 4, 2019 at 10:02
  • 1
    what address? any machine or interface can have any number of addresses. if you're after the address you're using to connect to "the Internet", you can use ip route as here -- change dev to src in the grep part (or get rid of grep entirely).
    – user313992
    Mar 4, 2019 at 10:08
  • 1
    ?? You said, route actually provided me with the details I was looking for, yet you've selected another answer as the solution. Your business though... Wrt your Q to me: I use dhcpcd on my system, so your results may vary. All I did was query the log w/ a dhcpcd grep filter, and found an entry that had both my IP address and subnet in CIDR notation. But again, that didn't meet your requirement: "find the numbers you are looking for, and without having to look up a command". You seem to have what you need now, so I'll butt out.
    – Seamus
    Mar 4, 2019 at 11:48

2 Answers 2


ip addr - list IPv4 and IPv6 addresses

ip -4 addr - list only IPv4 addresses (ip -c -4 addr for color)

ip -6 addr - list only IPv6 addresses (ip -c -6 addr for color)

ip route - IPv4 routing table

ip -6 route - IPv6 routing table

  • Can you explain what the "objects" between IPv4/mask and broadcast address with ip route stand for? Maybe provide a link for reference?
    – mazunki
    Mar 4, 2019 at 10:16
  • The broadcast address doesn't display in 'ip route'. See man ip-route for definitions of the various fields, such as dev (device).
    – user84215
    Mar 4, 2019 at 15:57
  • You can also specify the network interface for ip addr ... to further reduce the amount of output.
    – dirkt
    Mar 5, 2019 at 8:05

An easy way to see your IPv4 addresses is:

ip -c address -- The -c parameter adds colour to the IP addresses, so you can easily find it. It's easy to remember, and short.

I usually use ip -4 -c -o address, since I am only interested in IPv4s, and not IPv6, and I personally prefer to see each adapter in one line. This also facilitates piping into grep without much trouble.

You can calculate your subnet mask out from the (default) /24 after the IP, but I don't know if there is any easy way to see it. The same goes for the default gateway, if it is known that it is located on the first IP address, as it usually is.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .