-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisolated-ifup
executable file
·50 lines (44 loc) · 1.23 KB
/
isolated-ifup
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
#!/bin/bash
# Author: www.byte-edu.com
# Description: To Create a isolated network model for the virtual machine instances.
BridgeName=v-switch0
VirtNic=$1
# 安装 btctl 工具
InstallBrctl(){
which brctl > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "brctl has been installed."
else
yum install bridge-utils -y > /dev/null 2>&1
[ $? -eq 0 ] && echo "brctl was successfully installed" || (echo "brctl installation failed" && exit 1)
fi
}
# 创建虚拟桥
CreateSwitch(){
ip link show ${BridgeName} > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "The Bridge:[${BridgeName}] is exist."
else
brctl addbr ${BridgeName} && echo "The Bridge:[${BridgeName}] was created successfully." || (echo "The Bridge:[${BridgeName}] was created failed." && exit 1)
ip link set ${BridgeName} up
fi
}
# 添加虚拟机实例网卡到虚拟桥
AttachVirNic(){
if [ "${VirtNic}" ];then
ip link set ${VirtNic} up
sleep 0.5s
brctl addif ${BridgeName} ${VirtNic}
[ $? -eq 0 ]&& echo "Attach Tap nic to ${BridgeName} succeeded." || (echo "Attach Tap nic to ${BridgeName} failed." && exit 1)
else
echo "The tap nic is not exist"
exit 1
fi
}
# 配置主函数
MAIN(){
InstallBrctl
CreateSwitch
AttachVirNic
}
MAIN