Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loopback adapter name in Linux

Is it safe to assume that the loopback network adapter on a Linux system will always be called 'lo' - is this just a naming convention that may not be adhered to, or must it always be the case?

like image 362
codebox Avatar asked Dec 17 '22 05:12

codebox


2 Answers

I don't know of any Linux system that has a loopback interface anything other than lo. I would rely on this naming convention, if I write a system-specific script, but not when writing a portable program. For example loopback in OSX is lo0.

A reliable way in C is calling a SIOCGIFCONF ioctl on a socket, iterating over the interfaces, calling SIOCGIFFLAGS ioctl on each one, and checking which interfaces have a IFF_LOOPBACK flag set (see /usr/include/linux/if.h).

SIOCGIFCONF will also give you interface names.

like image 105
Alex B Avatar answered Dec 19 '22 18:12

Alex B


In my experience it is a common name, although you shouldn't always trust in it being so. Maybe enumerating the interfaces and looking for the one with an address of 127.0.0.1 would be the way to go?

like image 25
ZombieSheep Avatar answered Dec 19 '22 18:12

ZombieSheep