Why does VirtualBox create 2 interfaces on host-only adapter?

6/3/2019

I'm setting up minikube using VirtualBox as the VM driver using a NAT adapter and a host-only adapter. After the VM is created, I run a few pods one of which is Kafka (the messaging queue). I have issues using Kafka properly because the VM creates 2 network interfaces eth0 which points to 10.0.2.15 and eth1 which points to 192.168.99.100 which is the IP the host-only adapter is set up with.

I'm running this on a Mac, so I've tried using HyperKit instead, which seems to work differently. So, when using HyperKit I get one interface eth0 which points to 192.168.99.100 and everything works just fine.

Why does VirtualBox create 2 interfaces, i.e. eth0 and eth1?

|           Host           |   |          VM           |
|--------------------------|   |-----------------------|
| vboxnet0 (192.168.99.100)|   | eth0 (10.0.2.15)      | <--- why is this created?
|           ...            |   | eth1 (192.168.99.100) |

As a side note, Kafka is using PLAINTEXT://:9092 in the listeners setting, which makes it start the server using eth0 and as a result 10.0.2.15. This IP is later advertised to any consumer connecting to it. This IP seems to be accessible only within the VM, which makes impossible to connect from the outside, e.g. the host. To be precise, a consumer connects to Kafka, then Kafka sends the advertised listeners, i.e. 10.0.2.15 and then it cannot send any messages, because it tries to connect to 10.0.2.15.

-- ipinak
kubernetes
minikube
virtualbox

2 Answers

6/11/2019

I have been using the default config, so instead I've overridden the following properties, when starting Kafka. This worked just fine.

bin/kafka-server-start.sh config/server.properties \
     --override zookeeper.connect=zookeeper:2181 \
     --override advertised.listeners=PLAINTEXT://192.168.99.100:9092
-- ipinak
Source: StackOverflow

6/3/2019

| eth0 (10.0.2.15) | <--- why is this created?

Basically, VirtualBox needs 2 interfaces because it uses the vboxnet0 eth0 interface to talk to the outside world using NAT and the other interface eth1 on the 192.168.99.x net so that your machine can talk to the VM. 192.168.99.100 is used by minikube ssh. You can try it directly by running ssh -i private_key docker@192.168.99.100 and getting the private key from running minikube ssh-key

HyperKit doesn't need two interfaces because as you noticed it has 192.168.99.100 which minikube also uses to connect through ssh. HyperKit VMs don't necessarily need an interface to connect to the outside. For that, it generally uses a different mechanism based on VPNKit.

My suggestion is to use the advertised.host.name option in your Kafka configs. Another alternative is to upstream an option in minikube that allows you to change the order of the ethernet interfaces on VirtualBox, but that would be more work.

-- Rico
Source: StackOverflow