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.