Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bootrino/956d75063a594db98a3d70bbd1c16f4d to your computer and use it in GitHub Desktop.
Save bootrino/956d75063a594db98a3d70bbd1c16f4d to your computer and use it in GitHub Desktop.
systemd network config fr bridged kvm
andrewstuart@homecloud:~$ for file in /etc/systemd/network/*; do echo $file; cat $file; done
/etc/systemd/network/31-tap1.netdev
[NetDev]
Description="This is a tap device for a VM or a container"
Name=tap1
Kind=tap
[Tap]
/etc/systemd/network/31-tap1.network
[Match]
Name=tap1
[Link]
RequiredForOnline=no
[Network]
Description="This is a tap device for a VM or a container"
LinkLocalAddressing=no
LLMNR=no
IPv6AcceptRA=no
Bridge=br0
/etc/systemd/network/br0.netdev
[NetDev]
Name=br0
Kind=bridge
/etc/systemd/network/br0.network
[Match]
Name=br0
[Network]
DHCP=no
DNS=8.8.8.8
DNS=8.8.4.4
Address=192.168.1.87/24
Gateway=192.168.1.1
/etc/systemd/network/eth0.network
[Match]
Name=enp38s0
[Network]
Bridge=br0
andrewstuart@homecloud:~$ networkctl status -a
● 1: lo
Link File: /usr/lib/systemd/network/99-default.link
Network File: n/a
Type: loopback
State: carrier (unmanaged)
HW Address: 00:00:00:00:00:00
MTU: 65536
QDisc: noqueue
IPv6 Address Generation Mode: eui64
Queue Length (Tx/Rx): 1/1
Address: 127.0.0.1
::1
● 2: enp38s0
Link File: /usr/lib/systemd/network/99-default.link
Network File: /etc/systemd/network/eth0.network
Type: ether
State: enslaved (configured)
Path: pci-0000:26:00.0
Driver: r8169
Vendor: Realtek Semiconductor Co., Ltd.
Model: RTL8125 2.5GbE Controller
HW Address: d8:bb:c1:8d:7b:82
MTU: 1500 (min: 68, max: 9194)
QDisc: pfifo_fast
Master: br0
IPv6 Address Generation Mode: none
Queue Length (Tx/Rx): 1/1
Auto negotiation: yes
Speed: 1Gbps
Duplex: full
Port: tp
● 3: br0
Link File: /usr/lib/systemd/network/99-default.link
Network File: /etc/systemd/network/br0.network
Type: bridge
State: degraded-carrier (configured)
Driver: bridge
HW Address: ea:57:6f:56:5c:88
MTU: 1500 (min: 68, max: 65535)
QDisc: noqueue
IPv6 Address Generation Mode: eui64
Forward Delay: 15s
Hello Time: 2s
Max Age: 20s
Ageing Time: 5min
Priority: 32768
STP: no
Multicast IGMP Version: 2
Cost: 2000
Port State: disabled
Queue Length (Tx/Rx): 1/1
Auto negotiation: no
Speed: 1Gbps
Address: 192.168.1.87
fe80::e857:6fff:fe56:5c88
Gateway: 192.168.1.1 (TP-LINK TECHNOLOGIES CO.,LTD.)
DNS: 8.8.8.8
8.8.4.4
DHCP6 Client DUID: DUID-EN/Vendor:0000ab119d8d0bc303cf56130000
● 5: tap1
Link File: /usr/lib/systemd/network/99-default.link
Network File: /etc/systemd/network/31-tap1.network
Type: ether
State: no-carrier (configured)
Driver: tun
HW Address: da:e2:6d:4d:c3:73
MTU: 1500 (min: 68, max: 65521)
QDisc: pfifo_fast
Master: br0
IPv6 Address Generation Mode: none
Queue Length (Tx/Rx): 1/1
Auto negotiation: no
Speed: 10Mbps
Duplex: full
Port: tp
andrewstuart@homecloud:~$
andrewstuart@homecloud:~$ cat startvm.sh
# credit: https://jvns.ca/blog/2021/01/23/firecracker--start-a-vm-in-less-than-a-second/
set -eu
sudo setfacl -m u:${USER}:rw /dev/kvm
# download a kernel and filesystem image
#[ -e hello-vmlinux.bin ] || wget https://s3.amazonaws.com/spec.ccfc.min/img/hello/kernel/hello-vmlinux.bin
#[ -e hello-rootfs.ext4 ] || wget -O hello-rootfs.ext4 https://github.com/firecracker-microvm/firecracker-demo/raw/fea3897ccfab0387ce5cd4fa2dd49d869729d612/xenial.rootfs.ext4
#[ -e hello-id_rsa ] || wget -O hello-id_rsa https://raw.githubusercontent.com/firecracker-microvm/firecracker-demo/ec271b1e5ffc55bd0bf0632d5260e96ed54b5c0c/xenial.rootfs.id_rsa
TAP_DEV="tap1"
# set up the kernel boot args
MASK_LONG="255.255.255.0"
MASK_SHORT="/24"
TAP_IP="192.168.1.1"
FC_IP="192.168.1.88"
FC_MAC="02:FC:00:00:00:05"
DNS1="8.8.8.8"
DNS2="8.8.4.4"
KERNEL_BOOT_ARGS="ro console=ttyS0 noapic reboot=k panic=1 pci=off nomodules random.trust_cpu=on"
KERNEL_BOOT_ARGS="${KERNEL_BOOT_ARGS} ip=${FC_IP}::${TAP_IP}:${MASK_LONG}::eth0:off nameserver=${DNS1} nameserver=${DNS2}"
# set up a tap network interface for the Firecracker VM to user
#ip link del "$TAP_DEV" 2> /dev/null || true
#ip tuntap add dev "$TAP_DEV" mode tap
#sysctl -w net.ipv4.conf.${TAP_DEV}.proxy_arp=1 > /dev/null
#sysctl -w net.ipv6.conf.${TAP_DEV}.disable_ipv6=1 > /dev/null
#ip addr add "${TAP_IP}${MASK_SHORT}" dev "$TAP_DEV"
#ip link set dev "$TAP_DEV" up
# make a configuration file
cat <<EOF > vmconfig.json
{
"boot-source": {
"kernel_image_path": "hello-vmlinux.bin",
"boot_args": "$KERNEL_BOOT_ARGS"
},
"drives": [
{
"drive_id": "rootfs",
"path_on_host": "hello-rootfs.ext4",
"is_root_device": true,
"is_read_only": false
}
],
"network-interfaces": [
{
"iface_id": "eth0",
"guest_mac": "$FC_MAC",
"host_dev_name": "$TAP_DEV"
}
],
"machine-config": {
"vcpu_count": 2,
"mem_size_mib": 1024
}
}
EOF
# start firecracker
./firecracker --no-api --config-file vmconfig.json
andrewstuart@homecloud:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment