Skip to content

Instantly share code, notes, and snippets.

@stypr
Last active February 22, 2025 23:02
Show Gist options
  • Save stypr/db7ab01d1d3d511f57dc48be1e6c598b to your computer and use it in GitHub Desktop.
Save stypr/db7ab01d1d3d511f57dc48be1e6c598b to your computer and use it in GitHub Desktop.
Oracle OCI IPv6 autodiscovery
# /etc/systemd/system/configure-ipv6.service
[Unit]
Description=Configure IPv6 address and Add IPv6 Default Route via Script
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/configure_ipv6.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
#!/bin/bash
# /usr/local/bin/configure_ipv6.sh
if [[ $EUID -ne 0 ]]; then
echo "Error: This script must be run as root" 1>&2
exit 1
fi
INTERFACE="enp0s6"
# find gateway
dhclient -6 $INTERFACE
output=$(rdisc6 $INTERFACE 2>/dev/null)
ipv6_gateway=$(echo "$output" | grep -oP 'fe80::[0-9a-f:]{1,39}')
if [[ -z "$ipv6_gateway" ]]; then
echo "Error: Could not find IPv6 gateway address from rdisc6 output."
exit 1
fi
echo "Found IPv6 gateway: $ipv6_gateway"
# set route
ip -6 route del default
ip -6 route add default via "$ipv6_gateway" dev "$INTERFACE"
if [[ $? -eq 0 ]]; then
echo "Successfully added default IPv6 route via $ipv6_gateway on $INTERFACE."
else
echo "Error: Failed to add default IPv6 route."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment