Linux: Disable loopback interface from kernel

Yes, it is possible, if:

  • You recompile Linux without network support. (none at all)
  • You edit the kernel source.

Just removing it from a configuration appears less trivial then expected. Removing it from /usr/src/linux/drivers/net/Makefile (line 68 in the 3.2.29 kernel) is a good start, but is not enough for succesful compilation. And /usr/src/linux/net/core/dev.c (lines 6606 till 6614) indicate that the loopback device is expected to always exist if the network part is selected. (As indicated by this comment in the code):

/* The loopback device is special if any other network devices
 * is present in a network namespace the loopback device must
 * be present. Since we now dynamically allocate and free the
 * loopback device ensure this invariant is maintained by
 * keeping the loopback device as the first device on the
 * list of network devices.  Ensuring the loopback devices
 * is the first device that appears and the last network device
 * that disappears.
*/

So: Yes, it is possible. But not entirely trivial.


Of course it's possible. Linux is open source; with enough hacking in the build system and/or source code, you can do anything. You could definitely compile Linux without a TCP/IP stack at all; in that case, you wouldn't be able to have any network interfaces because the kernel would have no concept of "network".

This isn't normally something you can disable from the GUI or from the command line on a standard Linux distribution such as Ubuntu or Debian or Fedora, because the loopback interface is hard-wired into the particular kernel build they ship; but that doesn't mean that you can't recompile a kernel with it removed.

Also, if you don't have any particular need to do this, and are "just wondering", I would advise that you not ask this sort of question -- the reason being, we try to discourage trivial or "just for fun" questions on SU. Please only ask a question if you have a real problem.