Skip to content

Instantly share code, notes, and snippets.

@ryanrankin
Created July 29, 2019 17:42
Show Gist options
  • Select an option

  • Save ryanrankin/bfaac3bd94da3d2e71922846c022d467 to your computer and use it in GitHub Desktop.

Select an option

Save ryanrankin/bfaac3bd94da3d2e71922846c022d467 to your computer and use it in GitHub Desktop.
#!/bin/sh -e
##
# CREATES A TAP INTERFACE AND ADDS TO NETWORK BRIDGE "virb0"
#
##
# Default tap0 is down
TAP_INTERFACE_DOWN=1;
if [[ `grep 'tap0' /proc/net/dev` ]]; then
TAP_INTERFACE_DOWN=0;
fi
##
# Create tap0 if not already
#
if [[ "$TAP_INTERFACE_DOWN" = 1 ]]; then
echo -e "[ `date -u` ] [ NETWORK ] Creating tap interface and adding to bridge" \
&& sudo ip tuntap add dev tap0 mode tap \
&& sudo ip link set tap0 up promisc on \
&& sudo ip link set tap0 master virbr0 \
&& echo -e "[ `date -u` ] [ NETWORK ] Done! tap0 was added to virbr0";
else
echo -e "[ `date -u` ] [ NETWORK ] Using existing network tap tap0 and bridge virb0";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment