Skip to content

Instantly share code, notes, and snippets.

@jakelodwick
Created January 7, 2013 18:28
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 jakelodwick/4477243 to your computer and use it in GitHub Desktop.
Save jakelodwick/4477243 to your computer and use it in GitHub Desktop.
Simple shell script to get your machine's current local IP.
# type this in a terminal window to get your current local ip address:
ifconfig | grep 192 | awk '{print $2}'
# add this to whatever file runs when you open a new shell
# (~/.profile on OS X)
alias ip="ifconfig | grep 192 | awk '{print \$2}'"
# now you can type "ip" in a terminal window to get your local ip.
# note: you can replace "ip" with whatever you want.
@jackrusher
Copy link

I recommend:

ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{ print $2 }'

... as you might not be on a 192.x subnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment