-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup-network.sh
executable file
·48 lines (40 loc) · 1.36 KB
/
setup-network.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -e
if [ "$(sysctl --values net.ipv4.ip_forward)" -ne 1 ]; then
echo "IPv4 forwarding is not enabled, please ensure to enable it using the following command:" >&2
echo "$ sudo sysctl net.ipv4.ip_forward=1" >&2
echo "Then rerun this script." >&2
exit 1
fi
if [ "$(sysctl --values net.ipv6.conf.all.forwarding)" -ne 1 ]; then
echo "IPv6 forwarding is not enabled, please ensure to enable it using the following command:" >&2
echo "$ sudo sysctl net.ipv6.conf.all.forwarding=1" >&2
echo "Then rerun this script." >&2
exit 1
fi
nmcli connection add \
con-name "POC bridge" \
ifname pocbr0 \
type bridge \
autoconnect yes \
ipv4.method shared \
ipv6.method ignore
if [ -e /usr/libexec/qemu/qemu-bridge-helper ]; then
sudo setcap cap_net_admin+ep /usr/libexec/qemu/qemu-bridge-helper
fi
if [ -e /usr/lib/qemu/qemu-bridge-helper ]; then
sudo setcap cap_net_admin+ep /usr/lib/qemu/qemu-bridge-helper
fi
sudo mkdir --parents /etc/qemu
echo "allow pocbr0" | sudo dd of=/etc/qemu/bridge.conf
cat > /tmp/netdef.xml <<EOF
<network>
<name>poc-network</name>
<forward mode="bridge"/>
<bridge name="pocbr0"/>
</network>
EOF
trap "rm -f /tmp/netdef.xml" EXIT
virsh --connect qemu:///session net-define /tmp/netdef.xml
virsh --connect qemu:///session net-start poc-network
virsh --connect qemu:///session net-autostart poc-network