-
Notifications
You must be signed in to change notification settings - Fork 38
/
virt-create-net.sh
executable file
·46 lines (40 loc) · 1.61 KB
/
virt-create-net.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
#!/bin/bash
# Create a libvirt virtual network called 'test-net' configured
# to assign sno1.test-cluster.redhat.com/192.168.126.10 to
# DHCP requests from 52:54:00:ee:42:e1
# libvirt will also configure dnsmasq (listening on 192.168.126.1)
# to respond to DNS queries for several hosts under
# test-cluster.redhat.com with the 192.168.126.10 address.
# This dnsmasq is also configured to not forward unresolved requests
# within the test-cluster.redhat.com domain to upstream DNS servers.
# Finally, we configure NetworkManager to send any DNS queries
# on this machine for api.test-cluster.redhat.com to the libvirt
# configured dnsmasq on 192.168.126.1
# Warn terminal users about dns changes
if [ -t 1 ]; then
function ask_yes_or_no() {
read -p "$1 ([y]es or [N]o): "
case $(echo "$REPLY" | tr '[A-Z]' '[a-z]') in
y|yes) echo "yes" ;;
*) echo "no" ;;
esac
}
echo "This script will make changes to the DNS configuration of your machine, read $0 to learn more"
if [[ -f .dns_changes_confirmed || "yes" == $(ask_yes_or_no "Are you sure you want to continue?") ]]; then
touch .dns_changes_confirmed
else
exit 1
fi
fi
if [ -z ${NET_XML+x} ]; then
echo "Please set NET_XML"
exit 1
fi
# Only create network if it does not exist
if ! sudo virsh net-dumpxml $NET_NAME | grep -q "<uuid>$NET_UUID</uuid>"; then
sudo virsh net-define "${NET_XML}"
sudo virsh net-autostart $NET_NAME
sudo virsh net-start $NET_NAME
fi
echo -e "[main]\ndns=dnsmasq" | sudo tee /etc/NetworkManager/conf.d/bip.conf
sudo systemctl reload NetworkManager.service