Skip to content

Instantly share code, notes, and snippets.

@deric
Created July 22, 2017 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deric/cb304384e76a6cdcbf69ae8f8e59cbb0 to your computer and use it in GitHub Desktop.
Save deric/cb304384e76a6cdcbf69ae8f8e59cbb0 to your computer and use it in GitHub Desktop.
DC/OS ip-detect script for "deterministic network interfaces naming"
#!/usr/bin/env bash
set -o nounset -o errexit
export PATH=/usr/sbin:/usr/bin:$PATH
function msg { out "$*" >&1 ;}
function out { printf '%s\n' "$*" ;}
function showint {
msg $(ip addr show $1 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
}
if [[ -d /sys/class/net/eth0 ]]; then
showint "eth0"
else
# udev names network devices by their MAC addresses
# chooses first enp device (so far best heuristic)
showint $(ls -d /sys/class/net/enp* | tail -n +1 | cut -d \/ -f 5)
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment