bash – How to get the primary IP address of the local machine on Linux and OS X? – Stack Overflow
Posted by jpluimers on 2021/02/05
[WayBack] bash – How to get the primary IP address of the local machine on Linux and OS X? – Stack Overflow (thanks [WayBack] Collin Anderson!):
I tried on OS X 10.13.6 (macOS High Sierra) and these two work fine:
ip route get 1 | awk '{print $NF;exit}'
and
ip route get 8.8.8.8 | head -1 | cut -d' ' -f8
The first one needs the $
back-slash escaped as bash alias; the second does not need that.
Related:
- [WayBack] scripts/internalip.md at master · rsp/scripts · GitHub
- [WayBack] internalip
- [WayBack] GitHub – rsp/scripts: Random shell scripts for different tasks
- [WayBack] Get Started | Public DNS | Google Developers
- [WayBack] linux – How can I get my external IP address in a shell script? – Unix & Linux Stack Exchange
- [WayBack] networking – How do I find my internal ip address? – Ask Ubuntu
–jeroen
Leave a Reply