Skip to content

Instantly share code, notes, and snippets.

@vertexvaar
Last active November 26, 2019 08:10
Show Gist options
  • Select an option

  • Save vertexvaar/3ae4f32157cf1cc9035b8cdb2bebf064 to your computer and use it in GitHub Desktop.

Select an option

Save vertexvaar/3ae4f32157cf1cc9035b8cdb2bebf064 to your computer and use it in GitHub Desktop.
Get primary IP address
#!/bin/bash
echo "The hostname way"
echo $(hostname --all-ip-addresses | cut -d' ' -f1)
echo "more complicated but stable"
echo $(ifconfig $(/sbin/ip route | grep -v tun | awk '/default/ { print $5 }') | awk -F ' *|:' '/inet /{print $3}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment