# QEMU+macvtap network problem

## alnash

Hi,

I have a laptop wirelessly connected to a home router which has a DHCP-server leasing local IPs like 192.168.1.XXX

On the laptop I have a VM with Ubuntu-18.04

Default NAT network works Ok, the VM has internet connection.

I've expected that with macvtap the VM will talk to the router directly, get its own local IP 192.168.1.YYY and will be seen as yet another machine on the local net.

But then I switch to macvtap in virt-manager -- there's no connection to the internet, no matter macvtap being bridge, vepa or private (passthrough refuses to work too, but it's because "the device is busy")

However, with 'ip link' and 'ifconfig -a' I can see 'macvtap0@wlp3s0' interface is up. Strangely, it gets a 169.254.x.x IP

As far as I can understand the macvtap interface works, but the VM doesn't see the router at all.

I don't see any errors in the logs and can't understand what else it wants...

Maybe besides macvtap and tun/tap  some other kernel options must be enabled too? (I have a custom kernel with the most options switched off)

----------

## alamahant

Hi,

You should instead create and use a bridge if you wish to share the Host's network with the VM

Macvtap's do not seem to work.

Even Virtual Manager advises you that they might not work.

BUT you can not easily bridge wifi.

So you will need an ethernet iface to achieve this.

If you do then use the following:

```

nmcli con add autoconnect yes type bridge con-name br0 ifname br0 ip4 <ip-of bridge> gw4 <your-router>

nmcli con mod  br0 ipv4.dns <router-or-prefered-dns-ip> ipv4.method manual

nmcli con add autoconnect yes type bridge-slave con-name br0-slave1 ifname <device-name> master br0 

```

Of course you need iptables and ebtables installed and enabled in the kernel AND

ip forwarding ALSO ENABLED in 

/etc/sysctl.d

 :Very Happy: 

----------

## Ionen

 *alamahant wrote:*   

> Of course you need iptables and ebtables installed and enabled in the kernel

 I don' t know for network manager, but you can do this with nftables and neither of those nowadays, most guides haven't updated to it though (Gentoo wiki included, although it does give a short summary for bridge+NAT networking, you could also try to setup a bridge directly open to the outside but that can be messy, and also insecure).

Personally I prefer to use a host dhcp server (with dnsmasq which I also use for DNS caching anyway) to assign my VMs' an IP address (plus I want them to use dnsmasq for DNS queries). And I allow their internet connection only on-demand with a nftable rule I "nft replace" on/off. If you're using IP-based forwarding rules, forwarding to a outside dhcp may also be a problem because they won't have an IP assigned yet for the rule to work  :Smile:  169.254.0.0/16 range is a fallback when the dhcp client couldn't find a server.

But that aside I don't use macvtap, or any kind of virtual/network managers (nor know how they set things up), so I probably can't help with those.

----------

## nvaert1986

MAC VTAP in combination with bridge mode works (for IPv4) and virt-manager if you compiled the correct kernel modules (it'll warn you about missing items when compiling Qemu and libvirt. Re-emerge them and it'll perform the checks.

----------

