Unix/Linux/MacOSx : Get local IP address

Problem :

How to find out my MacOSX/ Linux / UNIX system ip address, subnet and related networking information from a command prompt?

Solution :

Use this command :

  1. Ifconfig is used to configure the network interfaces during boot time.
  2. If no arguments are given to ifconfig command it displays the status of the current active interfaces.
  3. It displays Ethernet IP address, Mac address, subnet mask and other information.
  4. ifconfig tool is available to all *nix based OS.

Example output :

 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
  inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
  inet netmask 0xff000000
  inet6 ::1 prefixlen 128
 gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
 stf0: flags=0<> mtu 1280
  ether f8:d1:11:16:ea:34
  inet6 fe80::fad1:11ff:fe16:ea34%en0 prefixlen 64 scopeid 0x4
  inet netmask 0xffffff00 broadcast
  media: autoselect
  status: active

By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.