Mastering the linux command line ip address workflow is essential for any system administrator or developer managing modern infrastructure. The `ip` command serves as the primary utility for inspecting, manipulating, and troubleshooting network interfaces, routing tables, and neighbor caches directly from the terminal. Unlike the older and more limited `ifconfig` tool, the `ip` suite from the `iproute2` package provides a consistent and powerful syntax for handling complex network configurations. This guide provides a practical breakdown of how to discover, query, and manage IP addresses using the command line.
Viewing Current IP Address Information
The most common task is simply checking the current IP address assigned to your machine. The `ip addr` or `ip address` subcommand displays protocol (IP) and link (MAC) layer information for all available network interfaces. Running this command provides a snapshot of active interfaces, their state, and their assigned addresses, including both IPv4 and IPv6 details.
Basic Address Listing
To see a concise list of interfaces and their IP addresses, you can use the `show` keyword. This outputs the interface name, state, MTU, and the associated IP prefix length.
Filtering by Specific Interface
On systems with numerous network interfaces—such as virtual machines with multiple NICs or containers—you can narrow the output to a specific device. Replacing `interface_name` with the actual name, such as `eth0`, `ens33`, or `wlan0`, isolates the details to that single network adapter.
Targeted Commands
This approach reduces clutter and makes scripting easier when you need details about a particular connection, whether it is wired, wireless, or a virtual tunnel.
ip addr show eth0
ip address dev wlan0
ip a s docker0
Identifying the Default Gateway
Understanding the path traffic takes to reach external networks is critical for troubleshooting connectivity issues. The routing table maintains rules that determine where packets are forwarded. To view the default gateway, which is the exit point for unknown destinations, you utilize the `ip route` command.
Route Inspection
The `ip route` command shows the kernel’s routing table. Looking for the line that specifies `default` or `0.0.0.0/0` reveals the gateway IP address your system uses to access the internet.
Common Route Commands
These commands help you identify the next hop for your traffic.
ip route : Displays the full routing table.
ip route show default : Filters output to show only the default route.
ip route get 8.8.8.8 : Traces the specific path to an external IP address.
Managing IP Addresses Dynamically
Beyond viewing, the `ip` command allows you to add or remove addresses on the fly without restarting network services. This is particularly useful for temporary configurations, testing environments, or applying secondary addresses to a single interface.