Skip to content

Instantly share code, notes, and snippets.

@elico
Created July 20, 2024 17:09
Show Gist options
  • Save elico/815734fbe2665c287f75ccf29d9c7ced to your computer and use it in GitHub Desktop.
Save elico/815734fbe2665c287f75ccf29d9c7ced to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
IPVERSION="$1"
INTERFACE="$2"
case ${IPVERSION} in
4|v4|ipv4|ip4|6|v6|ipv6|ip6)
;;
*)
echo "Missing ip version to remove: 4 or 6"
exit 1
;;
esac
if [ -z "${INTERFACE}" ]
then
INTERFACES_LIST=$( ip -o l |awk '{print $2}' |sed -e 's@:@@' |grep -v "lo")
echo "## missing interface name, these are the available interfaces:"
echo "${INTERFACES_LIST}"
exit 2
fi
case ${IPVERSION} in
4|v4|ipv4|ip4)
ip -o a|grep "${INTERFACE}\ "|grep "inet\ "|awk '{print $4}'|xargs -I{} ip address del {} dev ${INTERFACE}
;;
6|v6|ipv6|ip6)
ip -o a|grep "${INTERFACE}\ "|grep "inet6\ "|awk '{print $4}'|xargs -I{} ip address del {} dev ${INTERFACE}
;;
*)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment