How to get the primary IP address of the local machine on Linux and OS X? [closed]

Use grep to filter IP address from ifconfig: ifconfig | grep -Eo ‘inet (addr:)?([0-9]*\.){3}[0-9]*’ | grep -Eo ‘([0-9]*\.){3}[0-9]*’ | grep -v ‘127.0.0.1’ Or with sed: ifconfig | sed -En ‘s/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p’ If you are only interested in certain interfaces, wlan0, eth0, etc. then: ifconfig wlan0 | … You can alias the command in your .bashrc … Read more