LinuxCommandLibrary

ip-address

Show or manipulate network interfaces and addresses

TLDR

List network interfaces and their associated IP addresses

$ ip [[a|address]]
copy

Filter to show only active network interfaces
$ ip [[a|address]] [[s|show]] up
copy

Display information about a specific network interface
$ ip [[a|address]] [[s|show]] [ethX]
copy

Add an IP address to a network interface
$ sudo ip [[a|address]] [[a|add]] [ip_address] dev [ethX]
copy

Remove an IP address from a network interface
$ sudo ip [[a|address]] [[d|delete]] [ip_address] dev [ethX]
copy

Delete all IP addresses in a given scope from a network interface
$ sudo ip [[a|address]] [[f|flush]] [ethX] scope [global|host|link]
copy

SYNOPSIS

ip [ OPTIONS ] OBJECT { COMMAND | help }

Common OBJECTS:
link: Network device configuration (e.g., up/down, MAC address).
addr: IP address configuration (e.g., add/delete IP addresses).
route: IP routing table management (e.g., add/delete routes).
neigh: Neighbor table (ARP/NDP cache) management.
rule: Routing policy database rules.
netns: Network namespaces.

Common COMMANDS (depend on OBJECT):
show (or list): Display information.
add: Add a new entry.
del: Delete an existing entry.
set: Modify an existing entry.
get: Retrieve specific information.

PARAMETERS

-V, --version
    Displays the version of the ip utility.

-s, --stats, --statistics
    Outputs more verbose information, especially statistics for objects like network links.

-d, --details
    Outputs even more detailed information than -s.

-r, --resolve
    Attempts to resolve hostnames instead of displaying raw IP addresses where applicable.

-o, --oneline
    Outputs each record on a single line, replacing linefeeds with \ characters.

-f, --family {inet | inet6 | bridge | link}
    Specifies the protocol family to use (e.g., IPv4, IPv6). If not specified, the default is inet (IPv4) or determined by the object.

-N, --netns {NAME | PID}
    Switches to the specified network namespace before executing the command. This allows managing network configurations within isolated environments.

-a, --all
    Applies the command to all objects of the specified type (e.g., all interfaces, all addresses).

-t, --timestamp
    Displays the current time before the output, useful for scripting or logging.

-p, --pretty
    Outputs the information in a more human-readable or machine-parsable format (e.g., JSON if supported by the iproute2 version).

DESCRIPTION

The ip command is the fundamental utility for configuring and managing network interfaces, IP addresses, routing tables, and various other networking parameters on Linux systems. It is part of the iproute2 suite, a modern replacement for older, less capable tools like ifconfig, route, and arp. ip provides a unified and powerful interface for almost all network-related operations, offering richer functionality, better performance, and a more consistent syntax than its predecessors. It is essential for tasks ranging from displaying network statistics to setting up complex routing rules, managing network namespaces, and configuring tunnels.

CAVEATS

ip requires root privileges (or sudo) for most configuration changes and some display operations.

Its comprehensive functionality results in a hierarchical and sometimes complex syntax, which can have a steeper learning curve compared to older tools.

Specific syntax and available commands can vary slightly between different versions of the iproute2 package.

COMMON USE CASES

Here are some common examples of how the ip command is used:

Display all IP addresses:
ip addr show

Bring a network interface up:
ip link set eth0 up

Add an IP address to an interface:
ip addr add 192.168.1.10/24 dev eth0

Delete an IP address from an interface:
ip addr del 192.168.1.10/24 dev eth0

Show the default route:
ip route show default

Add a default route via a gateway:
ip route add default via 192.168.1.1 dev eth0

Display neighbor (ARP) cache:
ip neigh show

Show statistics for all links:
ip -s link show

HIERARCHICAL STRUCTURE

The ip command follows a hierarchical structure where an OBJECT is specified first, followed by a COMMAND specific to that object. For example, to manage IP addresses, you use ip addr, and then subcommands like add, del, or show apply to addresses. This design allows for a consistent and extensible syntax across diverse networking functionalities.

HISTORY

The ip command is the flagship utility of the iproute2 suite, which was primarily developed by Alexey Kuznetsov starting in the late 1990s. Its creation was motivated by the limitations of the existing net-tools package (which included ifconfig, route, netstat, etc.) in fully leveraging modern Linux kernel networking features. iproute2 was designed to support advanced functionalities like policy routing, multiple routing tables, network namespaces, and sophisticated Quality of Service (QoS) mechanisms. It has gradually superseded net-tools as the standard and recommended way to manage networking on Linux, offering a unified, powerful, and more efficient approach.

SEE ALSO

ifconfig(8), route(8), arp(8), netstat(8), ss(8)

Copied to clipboard