Skip to content

Instantly share code, notes, and snippets.

@yujunz
Last active September 12, 2017 02:41
Show Gist options
  • Save yujunz/4684c4157adc661ab668a7cb325feac0 to your computer and use it in GitHub Desktop.
Save yujunz/4684c4157adc661ab668a7cb325feac0 to your computer and use it in GitHub Desktop.
HOST_IFACE=$(ip route | grep "^default" | head -1 | awk '{ print $5 }')
LOCAL_IP=$(ip addr | awk "/inet/ && /${HOST_IFACE}/{sub(/\/.*$/,\"\",\$2); print \$2}")
cat << EOF | sudo tee -a /etc/hosts
${LOCAL_IP} $(hostname)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment