Is there a command for the OS X Terminal that shows you only the most vital IP configuration information about your machine? I know there is "ifconfig" but that brings up a bunch of (in most cases) unnecessary information. I just want to know my current IP, subnet mask, default gateway and DNS.


Output of netstat -rn

Axels-MacBook-Air:~ axelkennedal$ netstat -rn
Routing tables

Destination        Gateway            Flags        Refs      Use   Netif Expire
default         UGSc           75        0     en0
10.164.192/19      link#4             UCS             3        0     en0       c0:62:6b:e2:7a:c0  UHLWIir        76       20     en0   1150          UHS             0       25     lo0     ff:ff:ff:ff:ff:ff  UHLWbI          0       14     en0
127                UCS             0        0     lo0          UH              4      644     lo0
169.254            link#4             UCS             0        0     en0

Destination                             Gateway                         Flags         Netif Expire
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::7ed1:c3ff:fef1:9b1f%en0           7c:d1:c3:f1:9b:1f               UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en0/32                           link#4                          UmCI            en0
  • Could you show us the output of ifconfig on your machine? The details are different on different OSs. Does ifconfig show your DNS and default gateway? Mar 4, 2014 at 16:19
  • @terdon Sure! gyazo.com/ecd50ef22bc0393a87fff8136386fa4a The thing is though that as you can tell by the name "ifconfig" is "InterFaceconfig" meaning it only states addressing for interfaces on the machine running the terminal. Mar 4, 2014 at 16:21
  • What machines would you want it to state addresses for? Of course it returns information for the machine it's running on. Anyway, thanks for the output but please just copy paste it into your question. I need to be able to copy it to my terminal to test and I can't use an screenshot. Mar 4, 2014 at 16:30
  • The script in my answer has not been tested on OSX. Please let me know if you get any errors. Mar 4, 2014 at 16:57
  • I only want info concerning my own machine, I just said that to clarify that it didnt show info about other devices (like the DNS server) @terdon Mar 4, 2014 at 17:16

2 Answers 2


As far as I know, there is no single command that will give you all the info you want. You will need to run a few different ones. The easiest approach is probably to create a little script that does this for you. I am writing this on Linux using the ipconfig command which is not available on Linux so this will likely have some errors, please let me know and I'll try and work them out.


## Get the ip
ip=$(ipconfig getifaddr en0)

## Get the DNS server(s), this assumes Wi-Fi
dns=$(networksetup -getdnsservers Wi-Fi)

## Get the gateway
gateway=$(netstat -rn | awk 'NR==3{print $2}')

## And the netmask
mask=$(netstat -rn | awk 'NR==4{print $3}')

## Pretty print
IP      : $ip
Gateway : $gateway
Netmask : $mask
DNS     : $dns

Save that script as netinfo.sh or whatever in a directory that is in your $PATH (/usr/local/bin for example), make it executable (chmod a+x /usr/local/bin/netinfo.sh) and then run it:

$ netinfo.sh
  • I tried it, but unfortunately I get an error: Axels-MacBook-Air:~ axelkennedal$ chmod a+x netinfo.sh Axels-MacBook-Air:~ axelkennedal$ netinfo.sh -bash: netinfo.sh: command not found I think the "chmod" part is where the error is..? I've never done something like this though @terdon Mar 4, 2014 at 17:17
  • @AxelKennedal-TechTutor OK first, the $ just indicates your prompt, you should not actually write it. Just save the script in the /usr/local/bin directory and then run chmod a+x /usr/local/bin/netinfo.sh. Mar 4, 2014 at 17:27
  • I know... And that's what I did @terdon Mar 4, 2014 at 17:31
  • @AxelKennedal-TechTutor not sure what is going wrong. Try running the script like this bash netinfo.sh in the directory where you saved the script. Mar 4, 2014 at 20:52
  • That actually works! Nice job man! The only thing is that the gateway is not displayed at all and the netmask is displayed as "Flags" @terdon Mar 4, 2014 at 22:06

Hope this helps. I don't think there's one command to show that info.

ifconfig en1 | grep inet && scutil --dns | grep nameserver && netstat -nr | grep default

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.