Can't find netplan yaml file

I need to setup a network bridge for my qemu vm. Most all the info that I found refers to set it up using netplan, basically modifying the yaml file. It suppose to be located in /etc/netplan directory but the directory is empty. I run netplan get but shows nothing, but if I run netplan status then it shows all the interfaces and its configuration.
Where does netplan gets the configuration? Where is located the yaml file?

Hi and welcome.

" QEMU Network Bridge Setup

To set up a network bridge for a QEMU VM, you need to configure both the host and the VM to use the bridge. Here’s a step-by-step guide:

  1. Create a Bridge Interface :
  • First, ensure you have the bridge-utils package installed.
  • Use the following commands to create a bridge interface:
sudo brctl addbr virtbr0
sudo brctl addif virtbr0 enp3s0
sudo ip addr add 192.168.0.20/24 dev virtbr0
sudo ip link set virtbr0 up
  • Replace enp3s0 with the name of your Ethernet interface and 192.168.0.20 with an appropriate IP address for your network.
  1. Configure iptables :
  • Add the following iptables rule to allow traffic across the bridge:
sudo iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
  • This rule ensures that traffic is forwarded across the bridge interface.
  1. Modify VM Configuration :
  • When creating a VM, use the -net nic and -net bridge options with QEMU:
qemu-system-x86_64 -net nic,model=virtio,macaddr=52:54:00:00:00:01 -net bridge,br=virtbr0
  • Replace 52:54:00:00:00:01 with a unique MAC address and virtbr0 with the name of your bridge interface.
  1. Persistent Configuration :
  • To make the bridge configuration persistent across reboots, create a systemd service file:
[Unit]
Description=Setup qemu network bridging
After=network-online.target

[Service]
Type=oneshot
Restart=on-failure
ExecStart=/usr/bin/brctl addbr virtbr0
ExecStart=/usr/bin/brctl addif virtbr0 enp3s0
ExecStart=/usr/bin/ip addr add 192.168.0.20/24 dev virtbr0
ExecStart=/usr/bin/ip link set virtbr0 up
ExecStart=/usr/bin/iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT

[Install]
WantedBy=multi-user.target
  • Save this file as /lib/systemd/system/qemu-startup.service and enable it with sudo systemctl enable qemu-startup.service .

If you are using virt-install to create the VM, you can specify the network bridge as follows:

virt-install --network network=hostbridge

Ensure that the hostbridge network is defined and started using virsh commands:

virsh net-define /path/to/my/kvm-hostbridge.xml
virsh net-start hostbridge
virsh net-autostart hostbridge

Replace /path/to/my/kvm-hostbridge.xml with the path to your network definition file.

If you cannot find a YAML file for network configuration, you can manually create a configuration file for the bridge in /etc/netplan . For example:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp4s0:
      dhcp4: no
  bridges:
    br0:
      interfaces: [ enp4s0 ]
      dhcp4: no
      addresses: [192.168.2.15/24]
      gateway4: 192.168.2.1
      nameservers:
        addresses: [1.1.1.1]
      dhcp6: no
      link-local: [ ]
      parameters:
        stp: true
        forward-delay: 4

Replace enp4s0 with your Ethernet interface name and adjust the IP addresses as necessary.

If you are using NetworkManager instead of netplan , you can configure the bridge using nmcli or the NetworkManager GUI.

By following these steps, you should be able to set up a network bridge for your QEMU VM.

AI-generated answer. Please verify critical facts."