Bash function for getting local IP on OSX

Below is a handy little bash function that returns your local IP address on OSX (and maybe elsewhere). Just pop the following in your .profile.

### Get local IP ###
function ip {
  ipconfig getifaddr en1

Published by


Hi, I am the Managing Director of SonicIQ Limited in the UK. I have been working in the web development industry since 1999 and have been running SonicIQ since 2001. Currently Ruby On Rails is my preferred development platform. I am experienced in designing with web standards, HTML5, CSS3 and Javascript.

One thought on “Bash function for getting local IP on OSX”

  1. The function, as written, failed to return the IP address of my MBP running OS X 10.9.1. After poking around a bit, I was able to modify the function to work. Also, rather than inserting the snippet into .profile, I added it to .bash_profile. This is working for me:

    function ip {
    ifconfig en0

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>