getifaddrs - Linux


getifaddrs is a Linux command that retrieves and displays information about the network interfaces on a system. It can be used to list IP addresses, MAC addresses, and other network configuration details for each interface.


getifaddrs [OPTION]...


  • -a, –all: Display all active and inactive interfaces. (Default)
  • -d, –display: Display additional information, including MAC addresses and MTU.
  • -f FAMILY: Display information for a specific network interface family (e.g., -f inet for IPv4).
  • -h, –help: Display usage information.
  • -L, –label: Display interface names with labels.
  • -M, –mask: Display subnet masks for IPv4 addresses.
  • -n, –numeric: Display IP addresses in numeric format (no DNS lookup).
  • -p, –port: Display port numbers for UDP and TCP sockets.
  • -u, –up: Display only active interfaces.


List all active and inactive interfaces:


Display additional information, including MAC addresses and MTU:

getifaddrs -d

Display only active interfaces:

getifaddrs -u

Display IP addresses in numeric format:

getifaddrs -n

Common Issues

  • No output: Ensure that the command is run with root privileges (using sudo).
  • Incorrect IP addresses: Verify that DNS resolution is configured properly. Use the -n option to display IP addresses in numeric format.
  • Permission denied: Check file permissions and ensure that the current user has read access to the /proc/net/if_inet6 file.


getifaddrs can be combined with other commands to obtain detailed network information, such as:

  • grep: Filter the output by specific criteria (e.g., getifaddrs | grep eth0).
  • awk: Parse the output and extract specific fields (e.g., getifaddrs | awk '{print $1, $4}').
  • xargs: Pass the output to another command for further processing (e.g., getifaddrs -d | xargs ping).

Related Commands

  • ifconfig: Displays network interface configuration and statistics.
  • ip: Provides advanced network management and configuration options.
  • netstat: Shows network connections, routing tables, and statistics.