add remove bridge function.
This commit is contained in:
parent
20380fbd50
commit
9d27a4590d
1 changed files with 36 additions and 22 deletions
58
set-tap.sh
58
set-tap.sh
|
@ -17,20 +17,19 @@ PARAMETTER available
|
||||||
|
|
||||||
|
|
||||||
OPTION available
|
OPTION available
|
||||||
--bridge-id=<bridge-id> Set the name for the new bridge interface, usually it is br0, br1, etc
|
--add-br-id=<bridge-id> Set the name for the new bridge interface, usually it is br0, br1, etc
|
||||||
|
--rm-br-id=<bridge-id> Remove a bridge interface. Be carefull, it do no verification wheither bridge-id is a real interface or a bridge interface.
|
||||||
--addr=<address> Set an external address on the bridge. The external address have to be on the same network as one of the host network interface. e.g. if eth0, wlan0, etc is on 192.168.0.2/24, you should put the address on the network 192.168.0.0/24. Please not that the CIDR notation have to be use. #TODO
|
--addr=<address> Set an external address on the bridge. The external address have to be on the same network as one of the host network interface. e.g. if eth0, wlan0, etc is on 192.168.0.2/24, you should put the address on the network 192.168.0.0/24. Please not that the CIDR notation have to be use. #TODO
|
||||||
--replace=<interface> In case you want to replace the main connexion of your computer so that only the vm will be able to reach the external network, replace interface by the interface you want to replace, and make sure that the --addr is set to one of the ip on the interace. Please not that it will be possible for your host to lost all connection to the external internet with this parametter.
|
--replace=<interface> In case you want to replace the main connexion of your computer so that only the vm will be able to reach the external network, replace interface by the interface you want to replace, and make sure that the --addr is set to one of the ip on the interace. Please not that it will be possible for your host to lost all connection to the external internet with this parametter.
|
||||||
"
|
"
|
||||||
Version="1.0"
|
Version="1.0"
|
||||||
|
|
||||||
|
|
||||||
main() {
|
add_bridge() {
|
||||||
echo "Enter main function."
|
|
||||||
echo "add bridge interface ${bridge}"
|
echo "add bridge interface ${bridge}"
|
||||||
read -p "use ctrl-C to cancel, or any other key to continue." jaaj
|
|
||||||
${rooter} ip link add ${bridge} type bridge
|
${rooter} ip link add ${bridge} type bridge
|
||||||
|
|
||||||
echo "no interface to link with bridge ${bridge}"
|
#echo "no interface to link with bridge ${bridge}"
|
||||||
#$rooter ip link set dev wlan0 master br0
|
#$rooter ip link set dev wlan0 master br0
|
||||||
|
|
||||||
echo "authorise qemu to use as interface ${bridge} as bridge"
|
echo "authorise qemu to use as interface ${bridge} as bridge"
|
||||||
|
@ -43,12 +42,19 @@ main() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "activate bridge ${bridge}"
|
echo "activate bridge ${bridge}"
|
||||||
read -p "use ctrl-C to cancel, or any other key to continue." jaaj
|
|
||||||
${rooter} ip link set dev ${bridge} up
|
${rooter} ip link set dev ${bridge} up
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rm_bridge() {
|
||||||
|
echo "rm bridge interface ${bridge}"
|
||||||
|
${rooter} ip link del ${bridge}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# detect the parametters
|
# detect the parametters
|
||||||
for i in $@; do
|
for i in $@; do
|
||||||
|
@ -65,12 +71,34 @@ for i in $@; do
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# check if sudo is installed
|
||||||
|
if which doas &> /dev/null
|
||||||
|
then
|
||||||
|
echo "use doas"
|
||||||
|
rooter=$(which doas)
|
||||||
|
elif which sudo &> /dev/null
|
||||||
|
then
|
||||||
|
echo "use sudo"
|
||||||
|
rooter=$(which sudo)
|
||||||
|
else
|
||||||
|
echo "no command to give access to root is given. Abandon" >&2
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# detect the options
|
# detect the options
|
||||||
for i in $@; do
|
for i in $@; do
|
||||||
case "${i%=*}" in
|
case "${i%=*}" in
|
||||||
"--bridge-id")
|
"--add-br-id")
|
||||||
bridge="${i#*=}"
|
bridge="${i#*=}"
|
||||||
echo "${bridge}"
|
echo "${bridge}"
|
||||||
|
add_bridge
|
||||||
|
;;
|
||||||
|
"--rm-br-id")
|
||||||
|
bridge="${i#*=}"
|
||||||
|
echo "${bridge}"
|
||||||
|
rm_bridge
|
||||||
;;
|
;;
|
||||||
"--addr")
|
"--addr")
|
||||||
address="${i#*=}"
|
address="${i#*=}"
|
||||||
|
@ -89,25 +117,11 @@ done
|
||||||
|
|
||||||
if [ "${bridge}" == "" ]
|
if [ "${bridge}" == "" ]
|
||||||
then
|
then
|
||||||
echo "Error, --bridge-id have to be specified to make the bridge" >&2
|
echo "Error, --bridge have to be specified to make the bridge" >&2
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# check if sudo is installed
|
|
||||||
if which doas &> /dev/null
|
|
||||||
then
|
|
||||||
echo "use doas"
|
|
||||||
rooter=$(which doas)
|
|
||||||
elif which sudo &> /dev/null
|
|
||||||
then
|
|
||||||
echo "use sudo"
|
|
||||||
rooter=$(which sudo)
|
|
||||||
else
|
|
||||||
echo "no command to give access to root is given. Abandon" >&2
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
main
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue