114

This is in regard to linux, but if anyone knows of a general *nix method that would be good.

I booted a system yesterday with an ethernet cable plugged in. "NetworkManager" is not installed, so once it started I went to look for the name of the ethernet interface with ifconfig to start a DHCP client manually, but it did not show anything other than lo.

The NIC was listed via lspci, and the appropriate kernel driver was loaded. The system normally uses wifi, and I could remember the interface name for that was wlan0. When I tried ifconfig wlan0 up, wlan0 appeared. But the only ethernet interface names I could remember were eth[N] and em[N] -- neither of which worked.

This document refers to "predictable interface names" but does not do a good job of explaining what they might be in simple terms. It does refer to a piece of source code which implies the name in this case might be deduced from the the PCI bus and slot numbers, which seems like an unnecessarily complicated hassle.

Other searching around led me to believe that this might be determined by systemd in conjunction with udev, but there are almost 100 files in /usr/lib/udev/rules.d and spending an hour trying to determine where (and if) there's a systemd config file for this also seems ridiculous.

It would also be nice to know for certain that they are available, not just how they might be named if they are, so I can rule out hardware problems, etc. Isn't there a simple way to find the names of available network interfaces on linux?

2
  • In the question you state that you used ip link but then you accept an answer that suggests ip link show which does the exactly same thing. Why? Apr 23, 2014 at 16:07
  • The manual pages for iproute2 are quite good nowadays, I guess you're using and older version of the package. Apr 25, 2014 at 17:12

6 Answers 6

109

The simplest method I know to list all of your interfaces is

ifconfig -a

EDIT

If you're on a system where that has been made obsolete, you can use

ip link show
16
  • 3
    If I'd just looked at the man page! Be interesting to know if ip has a parallel, since supposedly ifconfig is being "obsoleted" in favour of that (IMO) more obtuse and less user friendly command.
    – goldilocks
    Apr 18, 2014 at 15:05
  • 3
    First thing in my man ifconfig: "NOTE This program is obsolete! For replacement check ip..." That may be specific to linux. Hopefully they have to retain it for backward compatibility with something.
    – goldilocks
    Apr 18, 2014 at 15:09
  • 7
    ifconfig has been deprecated, TMK, so we should be trying to show examples using ip. See the ifconfig wikipedia article: en.wikipedia.org/wiki/Ifconfig.
    – slm
    Apr 18, 2014 at 16:35
  • 4
    @slm Although the question is (was) linux specific, an example using both seems good as BSD users may be in the habit of looking at "linux" pages anyway -- in fact I'll take linux out of the title and edit a bit (originally this was self-answered and I did not think there was a portable method).
    – goldilocks
    Apr 18, 2014 at 16:44
  • 7
    ifconfig deprecated? come on. This command has been around for like 30 years. Apr 18, 2014 at 18:02
89

The kernel lists them by name in /sys, both separately in (e.g.) the tree of PCI devices -- although finding them there if you don't know where they are to start with is not simple -- and together via symlinks in /sys/class/net. E.g.:

> ls /sys/class/net
em1 lo wlp6so

Another example:

> ls /sys/class/net
lo p6s1 wlan0

If you are not sure which is which, you could just put them all up with either:

ifconfig [name] up 

Or:

ip link set [name] up

And then look at the (fairly clear) clues listed by ifconfig (with no arguments). The systemd source code linked from the Freedesktop.org document also refers to:

Two character prefixes based on the type of interface:
 *   en -- ethernet
 *   sl -- serial line IP (slip)
 *   wl -- wlan
 *   ww -- wwan

Although in one of the cases above (p6s1) there is no prefix.

4
  • The prefix I get for ethernet is eth. I believe en is for wireless lan. Jan 23, 2015 at 13:36
  • 4
    @kaushalmodi eth is a linux kernel thing; systemd implements via udev Freedesktop.org's predictable interface names -- the kernel ones are not predictable in the same sense, which is the cause of all the confusion. The quote above is explicitly cut n' pasted from here. There's more to it than that, since I don't have any systemd machines using en for ethernet; the closest is em, others are completely different. You can read the Freedesk.org link in the question yourself for more explanation.
    – goldilocks
    Jan 23, 2015 at 16:27
  • 4
    [Later] Sometime in the past year Fedora or systemd corrected that? My PCI ethernet is now eno1.
    – goldilocks
    Jan 8, 2016 at 13:36
  • @goldilocks &c: you can override that by the kernel command line options: biosdevname=0 net.ifnames=0. I never found the systemd way 'predictable' and eth as a prefix seemed reasonable to me so I have always had that. Anyway there it is: you can have it the pseudo-random way (i.e. systemd) or the other way depending on kernel options.
    – Pryftan
    Nov 2, 2019 at 12:14
13

I always do cat /proc/net/dev it's simple and easy to memorize

1
  • 5
    but that only gives active interfaces, not all the interfaces Sep 27, 2018 at 23:39
6

ifconfig = Solaris
ipconfig = Windows
ip = Linux

That I know, but am certainly open to additions and corrections.

6
  • 2
    Huh? ifconfig is Linux also.
    – fpmurphy
    Apr 27, 2016 at 20:57
  • 5
    @fpmurphy1 Read the first paragraph (after the synopsis) of man ifconfig on a linux system.
    – goldilocks
    Apr 27, 2016 at 21:21
  • @fpmurphy ifconfig(8) is also deprecated under Linux. Please see the sections NOTES and BUGS. This has been the case for years now. So although ifconfig works under Linux it's not the correct way.
    – Pryftan
    Nov 15, 2019 at 18:54
  • @Pryftan. Just because a utility is depreciated, does not mean that the utility does not work for your requirements. Correct way? Sorry but Linux does not mandate correct ways.
    – fpmurphy
    Nov 26, 2019 at 8:51
  • @fpmurphy For some uses however it does not work. Yes it can work but using deprecated ways is - for many cases - just silly. Why would anyone want to use the old way that for all you know could be removed in the future? It's been deprecated for many many years now! Anyway for ifconfig what's the point of using it? ip is more than sufficient. But hey if you like it so be it. I'm just saying that there are reasons it's deprecated!
    – Pryftan
    Dec 2, 2019 at 12:55
1

When there is no ifconfig, ip available in the system one way that helped me getting IP address on Ubuntu was:

hostname -i

As pointed out in the comments, this mechanism relies on DNS hostname reolution and will not provide authorative results for all available network interfaces.

Still, this command might be helpful in troubleshooting scenarios with containers (Docker, LXC), where system tools are often not available. And at least in some cases it shows container IP which might be helpful depending on your goal.

3
  • Probably not a great methodology as this is done via DNS resolution and on systems with hostname localhost (eg., likely most PC users), it will yield 127.0.0.1. None the less may be useful on whatever oddball system it is that doesn't have [/usr]/sbin/ip.
    – goldilocks
    Jun 30, 2022 at 13:59
  • I thought that as well. But in fact in my containers I'm getting their IP in that way. I think, in some cases that command may be useful. Jun 30, 2022 at 14:15
  • 1
    Makes sense -- I didn't think of that. You might want to edit details into the answer for people who's search terms include (eg) docker or lxc.
    – goldilocks
    Jun 30, 2022 at 14:42
0
ip -br a

short and easy to remember thanks to a silly clothing mnemonic.

prints something like:

lo               UNKNOWN        127.0.0.1/8 ::1/128 
enp0s32f6        DOWN           
wlp0s10f3        UP             192.168.3.144/24 ge80::f074:13c4:50e1:41a8/64 
docker1          DOWN           172.17.3.1/16 

You must log in to answer this question.

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