-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathadd-bridge-l2.sh
executable file
·54 lines (49 loc) · 1.2 KB
/
add-bridge-l2.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
49
50
51
52
53
54
#!/bin/bash
# For educational purposes : http://linux.goffinet.org/
# This script create a L2 bridge that connects a physical NIC
name=${1}
bridge=$name
interface=${2}
parameters=$#
path="/tmp"
check_parameters () {
# Check the number of parameters given and display help
if [ "$parameters" -eq 0 ] ; then
echo "Description : This script create a L2 bridge that connects a physical NIC"
echo "Usage : $0 <name> <interface name>"
echo "Example : '$0 internet enp2s0'"
exit
fi
}
check_bridge () {
# Check if the bridge interface name given is in use and display help
if [ -e /run/libvirt/network/${name}.xml ] ; then
echo "This bridge name ${name} is already in use"
echo "Change the bridge name or do 'virsh net-destroy ${name}' : exit"
exit
fi
}
bridged () {
cat << EOF > ${path}/${name}.xml
<network>
<name>${name}</name>
<forward mode="bridge">
<interface dev="${interface}"/>
</forward>
</network>
EOF
}
create_bridge () {
# Bridge creation
#cat ${path}/${name}.xml
virsh net-destroy ${name} 2> /dev/null
virsh net-undefine ${name} 2> /dev/null
virsh net-define ${path}/${name}.xml
virsh net-autostart ${name}
virsh net-start ${name}
virsh net-list
}
check_parameters
check_bridge
bridged
create_bridge