2

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.

UPDATE


Output of netstat -rn

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

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

Internet6:
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

2 Answers2

1

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
levy
  • 176
0

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.

#!/bin/bash

## 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
cat<<EOF
IP      : $ip
Gateway : $gateway
Netmask : $mask
DNS     : $dns
EOF

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
terdon
  • 54,564