Last active
May 24, 2021 11:17
-
-
Save s-zeid/1a7748207cacb2738990cec829bef1e0 to your computer and use it in GitHub Desktop.
/etc/network/if-up.d/ script to set extra IP addresses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ADDRESSES=' | |
eth0=2001:db8::2 eth0=2001:db8:2::1 | |
eth0=192.0.2.2 eth0=198.51.100.2 eth0=203.0.113.2 eth0=233.252.0.2 | |
' | |
################################################################################ | |
set -e | |
EXAMPLE_PREFIXES='' | |
EXAMPLE_PREFIXES="$EXAMPLE_PREFIXES"'^2001:0\?[dD][bB]8:' | |
EXAMPLE_PREFIXES="$EXAMPLE_PREFIXES"'\|192\.0\?0\?0\.0\?0\?2\.' | |
EXAMPLE_PREFIXES="$EXAMPLE_PREFIXES"'\|198\.0\?51\.100\.' | |
EXAMPLE_PREFIXES="$EXAMPLE_PREFIXES"'\|203\.0\?0\?0\.113\.' | |
EXAMPLE_PREFIXES="$EXAMPLE_PREFIXES"'\|233\.252\.0\?0\?0\.' | |
for spec in $ADDRESSES; do | |
if (printf '%s\n' "$spec" | grep -q -e '='); then | |
interface=${spec%%=*} | |
address=${spec#*=} | |
if [ x"$IFACE" = x"$interface" ]; then | |
if ! (printf '%s\n' "$address" | grep -q -e "$EXAMPLE_PREFIXES"); then | |
/sbin/ip addr add dev "$interface" "$address" || true | |
fi | |
fi | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment