Commit 804fb4fb authored by Nick Sandford's avatar Nick Sandford Committed by Konstantinos Tsakalozos
Browse files

Use netstat to get the default interface name (#279)

parent 0207ff3e
......@@ -22,7 +22,7 @@ do
systemctl is-active --quiet snap.microk8s.daemon-apiserver.service
then
# Get current IP
DEFAULT_INTERFACE="$(ip route | gawk '/default/ { print $5 }' | head -1)"
DEFAULT_INTERFACE="$(netstat -rn | grep '^0.0.0.0' | awk '{print $NF}' | head -1)"
IP_ADDR="$(ifconfig "$DEFAULT_INTERFACE" | grep 'inet ' | gawk '{print $2}' | sed -e 's/addr://')"
USED_IP_ADDR=$(cat "${SNAP_DATA}"/external_ip.txt)
if ! [ "$IP_ADDR" == "$USED_IP_ADDR" ]
......
......@@ -45,7 +45,7 @@ then
if ip route | grep default &> /dev/null
then
DEFAULT_INTERFACE="$(ip route | gawk '/default/ { print $5 }' | head -1)"
DEFAULT_INTERFACE="$(netstat -rn | grep '^0.0.0.0' | awk '{print $NF}' | head -1)"
IP_ADDR="$(ifconfig "$DEFAULT_INTERFACE" | grep 'inet ' | gawk '{print $2}' | sed -e 's/addr://')"
mkdir -p ${SNAP_DATA}/var
echo ${IP_ADDR} > ${SNAP_DATA}/external_ip.txt
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment