6

This question already has an answer here:

I know that udev manages devices in /dev and I expected to find information about available network cards (hardware) or at least network interfaces (software) there.

ifconfig output shows me eth0 and lo, but /dev/net is empty. Well, almost empty:

$ ls -la /dev/net
total 0
drwxr-xr-x  2 root root      60 Dec 13 09:37 .
drwxr-xr-x 15 root root    4300 Dec 15 12:12 ..
crw-rw-rw-  1 root root 10, 200 Dec 13 09:38 tun

Why there is no info about network interfaces in udev?
I'd really like to avoid executing ifconfig in my server process.

It is irrelevant to the question, but I expected to find ids ("lo", "eth0") and IP addresses there.

marked as duplicate by Gilles, jasonwryan, slm, rahmu, Chris Down Dec 17 '13 at 3:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

udev doesn't create any /dev files for network cards because network cards don't have device files. Network interfaces are one of the exceptions to everything is a file.

You can, however, look in /sys/class/net. That's maintained by the kernel directly, and should show you all the network interfaces on the system. You can also get the list out of /proc (e.g., /proc/net/dev). These are Linux-specific.

If you're working in C, you can use if_nameindex and friends.

  • It is said that udev is a device manager for the Linux kernel. It is not said that it is only for devices that have device files (what are those files anyway?). So, I don't get it - why information from /sys/class/net can not be available in /dev/net/by-id? – anatoly techtonik Dec 16 '13 at 17:36
  • Device files in /dev are supposed to be directly read from/written to. This works perfectly fine for block-devices, but is impossible for the way network interfaces work. A block device just provides access to raw chunks of data, while a network device needs way more information than simply the raw payload. – Elias Probst Dec 16 '13 at 19:49
  • 1
    @techtonik, you are correct that udev does many things, however, /dev has historically been solely for block- and character-special files, used to control, read from, or write to devices. udev appears to honor this tradition, and doesn't place ordinary files there. Unix and its relatives have evolved, and there are now other places to place files to control, read from, or write to devices, such as /sys and /proc, but /dev still almost exclusively contains block- and character-special files. – Mark Plotnick Dec 16 '13 at 19:52
  • @techtonik see also unix.stackexchange.com/questions/23199/… – derobert Dec 16 '13 at 19:56
  • Ok. Thanks. That makes historical perspectives clear. I wish there was a place like stackexchange to discuss proposals for a change. =) – anatoly techtonik Dec 17 '13 at 6:32
2

Most likely, the TUN/TAP driver is the only thing that uses that directory. Grepping the 3.11 kernel source Documentation/ directory, tuntap.txt is the only real reference to it, and that was written 12+ years ago. I notice /dev/net does not exist on a system here where I've configured TUN/TAP out of the kernel.

Not the answer you're looking for? Browse other questions tagged or ask your own question.