Linux Loopback adapter name
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.
source to share
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
.
source to share