0

I am trying to create a QEMU VM within a GCP VM. I want the QEMU VM to use TAP network device to communicate with the host and external world.

My desired set up looks like below.

    +-------------------+        +-----------------+
    | Physical Ethernet |        | Virtual Machine |
    | Interface (ens4)  |        |     (qemu)      |
    +---------+---------+        +--------+--------+
              |                           |
              |                           |
              |                           |
+-------------v------------+              |
|        Bridge (br0)      |              |
+-------------+------------+              |
              |                           |
              |                           |
              |                           |
    +---------v---------+        +--------v--------+
    | TAP Device (tap0) |        | Virtual NIC in  |
    |                   |<------>|   VM (e.g.      |
    |                   |        |  virtio-net)    |
    +-------------------+        +-----------------+

I used below steps:

# Step 1: Create a TAP device:
sudo ip tuntap add dev tap0 mode tap user $(whoami)
sudo ip link set tap0 up

# Step 2: Create a network bridge
sudo ip link add name br0 type bridge
sudo ip link set dev br0 up

# Step 3: Add the host's physical ethernet device ens4 to the bridge
sudo ip link set dev ens4 master br0

# Step 4: Add the TAP device to the bridge
sudo ip link set dev tap0 master br0

I noticed that my GCP VM lost internet connection after step 3. At this point, my network looks like this:

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc mq master br0 state UP group default qlen 1000
    link/ether 42:01:0a:80:0f:cb brd ff:ff:ff:ff:ff:ff
    altname enp0s4
    inet 10.128.15.203/32 metric 100 scope global dynamic ens4
       valid_lft 730sec preferred_lft 730sec
    inet6 fe80::4001:aff:fe80:fcb/64 scope link 
       valid_lft forever preferred_lft forever
3: tap0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master br0 state DOWN group default qlen 1000
    link/ether 12:ec:b9:f2:0a:70 brd ff:ff:ff:ff:ff:ff
4: br0: <BROADCAST,MULTICAST> mtu 1460 qdisc noop state DOWN group default qlen 1000
    link/ether 7a:fc:a9:79:fb:4f brd ff:ff:ff:ff:ff:ff

10.128.15.203 is the IP address assigned to the GCP VM. Internet was working fine before adding ens4 to br0.

Any help is appreciated.

onlygo
  • 101
  • 1
    Refer to [Setting up Qemu with a tap interface](https://gist.github.com/extremecoders-re/e8fd8a67a515fee0c873dcafc81d811c) and [Using Virtual Machine TAP Networking](https://docs.windriver.com/bundle/Wind_River_Linux_Platform_Virtualization_Features_Guide_9_1/page/tfx1501099048400.html), which may help to resolve your issue. – Veera Nagireddy May 01 '23 at 07:00
  • Hi @onlygo, Have you tried the above comment and the issue is resolved? – Veera Nagireddy May 02 '23 at 04:49
  • Unfortunately neither of them worked – onlygo May 02 '23 at 08:56

0 Answers0