ip Command: Tutorial & Examples
Display and configure network interfaces and routing information
The ip
command is a powerful and versatile networking utility on Linux systems used to display and manipulate network interfaces, addresses, routing tables,
and tunnels. It was introduced as a modern replacement for the older ifconfig
command, offering a more consistent syntax and
support for a wider range of networking features. The ip
command is essential for managing network configuration on servers and virtual machines through
the command line, providing detailed control over how the system communicates on a network.
With ip
, you can view the current state of network interfaces, assign and remove IP addresses, bring interfaces up or down, manage routing tables, and inspect
neighbor information. This tutorial covers the basics and advanced usage of the ip
command with practical examples to help you manage Linux network interfaces
effectively.
What The ip Command Does
The ip
command allows you to:
- Display information about network interfaces and their IP addresses
- Add, modify, or delete IP addresses assigned to interfaces
- Bring network interfaces up or down
- Display and manipulate the routing table
- Show and manage neighbor (ARP) entries
- Control tunnels and network namespaces (advanced usage)
It combines functionality that used to be spread across multiple older commands (ifconfig
, route
, arp
) into a single, consistent tool.
How ip Works And Its Subcommands
The ip
command uses a hierarchical syntax based on objects and actions. The general form is:
ip OBJECT COMMAND [OPTIONS]
where
- OBJECT specifies the networking object to operate on, such as
link
,address
,route
,neigh
. - COMMAND is the action to perform, such as
show
,add
,del
,flush
,replace
. - OPTIONS provide additional parameters.
Common objects include:
link
— network interfaces and their physical/link-layer propertiesaddress
— IP addresses assigned to interfacesroute
— routing table entriesneigh
— neighbor (ARP) table entries
This structure enables powerful and flexible network management.
Basic Usage Examples
Show Network Interfaces and IP Addresses
To display all network interfaces and their IP addresses, use:
ip address show
Typical output looks like:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:1a:4b:16:01:59 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::21a:4bff:fe16:159/64 scope link
valid_lft forever preferred_lft forever
This shows interface eth0
with IP address 192.168.1.10
and subnet mask /24
.
You can shorten the command to:
ip a
Show Network Interfaces Only
To show only interfaces without IP info, use:
ip link show
Example output:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 00:1a:4b:16:01:59 brd ff:ff:ff:ff:ff:ff
Configuring Network Interfaces
Assigning An IP Address
To add an IP address to an interface, run:
sudo ip address add 192.168.1.20/24 dev eth0
This assigns the IP 192.168.1.20
with subnet mask /24
to eth0
. You need superuser privileges (sudo
) for this.
Removing An IP Address
To remove an IP address:
sudo ip address del 192.168.1.20/24 dev eth0
Bringing An Interface Up Or Down
To activate (bring up) an interface:
sudo ip link set dev eth0 up
To deactivate (bring down) an interface:
sudo ip link set dev eth0 down
This is useful for restarting interfaces or disabling unused ones.
Enabling Promiscuous Mode
Promiscuous mode allows the interface to receive all packets on the network segment. To enable it:
sudo ip link set dev eth0 promisc on
To disable:
sudo ip link set dev eth0 promisc off
This is often used for network monitoring or packet capturing.
Managing Routing Table
To view the current routing table:
ip route show
Example output:
default via 192.168.1.1 dev eth0 proto dhcp metric 100
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10 metric 100
To add a default gateway:
sudo ip route add default via 192.168.1.1 dev eth0
To delete a route:
sudo ip route del default
Neighbor Table Management
The neighbor table contains Layer 2 (MAC) addresses corresponding to IP addresses on the local network (ARP cache). To view neighbors:
ip neigh show
Example output:
192.168.1.1 dev eth0 lladdr 00:11:22:33:44:55 REACHABLE
To delete a neighbor entry:
sudo ip neigh del 192.168.1.1 dev eth0
Common Parameters And Options
show
— Display information about the objectadd
— Add a new entry or configurationdel
— Delete an existing entryreplace
— Add or replace an entryflush
— Remove all entries for an object type
You can specify options like dev
(device/interface), IP address with prefix (e.g., /24
), scope, and more.
Troubleshooting And Common Errors
- Permission Denied: Most configuration commands require running as root (
sudo
). - Device Not Found: Ensure the interface name is correct (check with
ip link show
). - Address Already Exists: You cannot add duplicate IP addresses; delete existing ones first.
- Route Conflicts: Conflicting routes can cause connectivity issues; check with
ip route show
.
Tips And Best Practices
- Use
ip
instead of deprecatedifconfig
androute
. - Always check interface state with
ip link show
. - Scripts that manipulate network interfaces should check for errors.
- Use
ip monitor
to watch changes in network configuration in real time. - For persistent configuration, use your distribution's network configuration files.
Scripting And Automation Example
To bring up interface eth0
and assign an IP address in a script:
#!/bin/bash
sudo ip link set dev eth0 up
sudo ip address add 192.168.10.10/24 dev eth0
Save and run this script to automate interface setup during system initialization or in containers.
Possible Alternatives
ifconfig
— Older tool, deprecated but still available on some systems.
See Also
Further Reading
- Linux for Networking Professionals by Rob Vandenbrink (partner link)
- Understanding Linux Network Internals by Christian Benvenuti (partner link)
- Linux Networking Cookbook by Carla Schroder (partner link)
As an Amazon Associate, I earn from qualifying purchases.