There's an approach, described here, that is intended to allow virtual machines and host to communicate with each other over the network. It consists in setting a macvlan interface in the host machine, and the script assigns the same IP address as the physical adapter it binds to.

In fact this script was failing me because of dhcp (I posted here: Script to create macvlan bridge on the host doesn't work unless it's run twice - Unix.SE) but that's sorted out.

Now I found out that port forwarding to the host machine was not working. I just solved it by disabling rp_filter for the macvlan interface (from How to make iptables DNAT work with macvlan - Serverfault).

[Update] The port forwarding issue is still present when using a different ip address for the macvlan0 interface, and thus it's not related to the question.

Still, I'm now unsure if I shoud continue using the same IP address as the physical adapter (enp10s0), or a different one. Information seems to differ: An answer at Guest and host cannot see each other using linux-kvm and macvtap (Superuser) says

The solution is to configure a macvlan interface on the hypervisor, with the same IP address than the real hardware interface (very important), and to configure routing on the host to use it. (...)

while another answer at Two IP address on one network adapter over macvlan (Serverfault) says

(...) However, it is not best practice to assign the same subnet/IP to virtual interfaces, I'd suggest to use separate vlan like 192.168.2.x

So... which advice should be followed?

(Note: my current script creates the macvlan0 device at boot with a predefined MAC address - not the same address as the physical adapter).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.