Skip to content

Instantly share code, notes, and snippets.

@rakheshster
Created August 24, 2020 14:55
Show Gist options
  • Save rakheshster/b1bfd047f2ed2344241ba2be0ce93add to your computer and use it in GitHub Desktop.
Save rakheshster/b1bfd047f2ed2344241ba2be0ce93add to your computer and use it in GitHub Desktop.
This is just a script for me to quickly create a macvlan network.
#!/bin/bash
# Usage ./createmacvlan.sh <subnet> <gateway> <interface> [network name]
# This is just a script for me to quickly create a macvlan network.
# if the first or second arguments are missing give a usage message and exit
if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
echo "Usage ./createmacvlan.sh <subnet> <gateway> <interface> [network name]"
exit 1
else
SUBNET=$1
GATEWAY=$2
INTERFACE=$3
fi
if [[ -z "$4" ]]; then
# network name not specified, default to bridge
NETWORK="my_macvlan_network"
else
NETWORK=$4
fi
docker network create -d macvlan \
--subnet="$SUBNET" \
--gateway="$GATEWAY" \
-o parent="$INTERFACE" \
"$NETWORK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment