Linux Loopback adapter name

Is it safe to assume that the loopback network adapter on Linux will always be called "lo" - is it just a naming convention that may not be followed, or should it always be?

+2


source to share


6 answers


I don't know of any Linux system that has a loopback interface other than lo

. I would rely on this naming convention if I am writing a system script, but not when writing a portable program. For example, loopback on OSX is lo0

.

The reliable way in C is SIOCGIFCONF

ioctl

to call on a socket, iterate over the interfaces, call SIOCGIFFLAGS

ioctl

on each one and check which interfaces have a flag IFF_LOOPBACK

(see /usr/include/linux/if.h

).



SIOCGIFCONF

will also give you the names of the interfaces.

+7


source


In my experience, this is a common name, although you don't always have to believe it. Maybe enumerating interfaces and looking for an address with address 127.0.0.1 is the way to go?



+1


source


This is a pretty old convention, in fact I haven't seen a Linux box / distro yet that didn't call it "lo".

However, the device names on * nix systems are so varied that it can be assumed that they will change. Use standards if you want to port (in this case 127.0.0.1).

+1


source


Interfaces can be renamed to whatever, but anyone who renames the loopback interface is extremely stupid and deserves a broken system :)

Yes, you can enumerate interfaces and get their names. But it might just be that easy to assume it will be "lo".

+1


source


Using 127.0.0.1 is probably the fail-safe way to do this.

0


source


RFC3330 defines 127.0.0.0/8

to always be loopback subnets.

However, the usage localhost

defined on Windows on c:\windows\system32\drivers\etc\hosts

and Linux on /etc/hosts

is purely conditional. Also, the name lo

is a typical name given by the local interface in Linux.

If you are absolutely sure use 127.0.0.1

.

-1


source







All Articles