Score:0

Using host loopback device into VMs

mp flag

While deciding what IP address to assign to a local VM a question arose into my mind: why can't I just assign an address of the 127.0.0.0/8 net (so I can avoid any kind of IP clashing)? After all, it is possible to bind HTTP server/whatever to localhost; why can't I do it to VMs? When I tried that, virt-manager said "This network is already in use".

Afterwards, in my quest to use the loopback device, I asked myself another question: can I create a bridged network to the host loopback device? When I tried this with the ip tool from iproute2 with the command ip l set lo master bridge0 I got RTNETLINK answers: Invalid argument.

Is it ignorance on my side about how stuff should work in theory or did I misconfigure something? Thanks in advance. :)

Score:3
za flag

Because VM is another computer. It runs its own OS with its own networking stack and so on. From the networking standpoint, on the L1 (physical) it is tied to the host, but on the L2 (channel) and all above levels this additional computer is absolutely independent from the "host" one. Just another machine. This is a grey area for containers, because containers actually are the same OS (kernel) as "host". If a container has independent network namespace it will have independent presence on the network, its own loopback and so on, just as a VM. If you imagine a container without a separate netns, that container will be, from the networking standpoint, the same thing as "host" (it will "see and share" host's network interfaces and configuration).

You can't use loopback addresses for VMs for the exactly same reason why you can't use them for another computer: these are loopback, e.g. synonymous with "myself", and each system has its own "self".

Linux's bridge driver is Ethernet bridge. One of the reasons why you can't "bridge" loopback with anything is because loopback is not Ethernet. Actually this is consequence of a reason I gave in previous paragraph.

To avoid any kind of IP clashing you have to plan and account your networks. There is no other way. One particular advice is to never use "common"/"default" networks: 192.168.0.0/24, 192.168.1.0/24 (both are defaults on myriad of SOHO hardware), 192.168.88.0/24 (Mikrotik default), 192.168.112.0/24 (libvirt default, AFAIK), ones that Docker use by default and so on. There are plenty left; use them.

Score:0
ru flag

why can't I just assign an address of the 127.0.0.0/8 net?

Of course you can. But then again, the only party able to communicate with the 127.0.0.0/8 loopback network is the local host (VM) itself...

VM or physical host doesn't matter.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.