Inspecting network addresses and routes with ip
- Version
- unversioned
- Review
- Draft
Summary#
ip inspects and configures network interfaces, addresses and routes on Linux. Use the read-only forms here to see which addresses are assigned and which path the kernel selects.
Syntax#
ip link show
ip -4 address show dev eth0
ip -4 -o address show dev lo to 127.0.0.1/32
ip route show
ip route get 127.0.0.1
dev selects an interface by name. -4 limits the results to IPv4 and -o puts each address record on one line.
Example#
On a Linux system with the standard IPv4 loopback address, print the interface and address, then the first four fields of the route lookup.
(
set -eu
ip -4 -o address show dev lo to 127.0.0.1/32 |
awk '{ print $2, $4 }'
ip -4 route get 127.0.0.1 |
awk 'NR == 1 { print $1, $2, $3, $4 }'
)
Expected output#
lo 127.0.0.1/8
local 127.0.0.1 dev lo
Common mistakes#
ip route show lists routes from the main table by default. Use ip route get ADDRESS for a lookup that applies the kernel’s routing rules. A successful lookup identifies a route and does not test whether a remote host responds.
Version applicability#
This entry describes ip from Linux iproute2. BSD and macOS normally use tools such as ifconfig and route for these tasks.
Sources#
- Attribution
- DevLookup contributors
- License
- CC-BY-4.0