1

I setup a macvtap interface like this:

ip link add link eth0 vlan type macvlan mode bridge ip address add 10.0.0.17 dev vlan ip link set dev vlan up ip route flush dev eth0 ip route flush dev vlan ip route add 10.0.0.0/24 dev vlan metric 0 ip route add default via 10.0.0.1 ip link add link eth0 name vtap address xx:xx:xx:xx:xx:xx type macvtap mode bridge ip link set vtap up ip address flush eth0 ip address flush vtap dhclient -v vtap ip address flush vtap 

And it works fine for a couple of hours. But after that, any connections to the DHCP (macvtap) IP will start going to the host machine instead. So if I connect to the IP at port 80 for example, I will see a page served by the host instead of the VM.

I am trying to understand why it stops working. At first I thought maybe the DHCP lease expired, and dhclient is not renewing it. But the leasetime is 24 hours, and this problem starts earlier than that, sometimes in less than 10 hours.

So what can be causing the macvtap interface to stop working?

7
  • If you isolate the macvlan interface, including the dhclient invocation, in its own separate network namespace, does it also happen? Commented May 2, 2023 at 18:04
  • @A.B The only reason for that macvlan part is that it allows the host machine to also reach the vtap IP. If I remove that part of the code, then the vtap ip is reachable from any other machine, except from the host. But I'm a complete network newbie, so I am not sure how to isolate something in a network namespace like you suggested. Could you provide some example code? Commented May 2, 2023 at 23:28
  • Maybe I can remove all the code related to macvlan if there is a simpeler/better way to allow the host to communicate with the macvtap IP. I only added it as a workaround. Commented May 2, 2023 at 23:35
  • What is "But after that, any connections to the DHCP IP will go to 10.0.0.17 instead." supposed to mean? ARP requests are answered with the wrong MAC address? Commented May 2, 2023 at 23:47
  • @HaukeLaging I am not sure? What I observe is that when I connect to port 80 for example, for many hours it shows the page served by the VM on the vtap device, and after that suddenly it shows a page served by the host machine. So yes, it looks like the MAC address for that IP becomes wrong suddenly. I also observed that it does make a difference from which device I try it. From my mobile phone it will start showing the page served by the host. But sometimes from other devices I can still see the page served by the VM, even though I connect to exactly the same IP. Maybe ARP requests are cached Commented May 3, 2023 at 0:23

1 Answer 1

1

When dhclient was started, it was the only one using the macvtap interface. But when dhclient was sending a packet in order to renew the lease after many hours, it broke macvtap because by that time the guest was also using the interface. And both host and guest cannot use the same interface simultanously.

If a totally different program had just sended a random packet over that interface from the host, for example a simple ping, the same would have happened. So this problem was not related to DHCP in any way.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.