ip Command
The ip command is a powerful and modern replacement for traditional networking tools like ifconfig, route, and arp. It's part of the iproute2 package and provides comprehensive network configuration and monitoring capabilities.
Syntax
OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm | netns | l2tp | tcp_metrics | token | macsec }
Description
The ip command is the Swiss Army knife of Linux networking. It can configure network interfaces, manage IP addresses, set up routing tables, and much more. It's designed to be more powerful and flexible than the older net-tools commands.
Key features:
- Configure network interfaces and addresses
- Manage routing tables and rules
- Handle neighbor (ARP) tables
- Monitor network changes in real-time
- Support for advanced networking features
Common Objects
| Object | Description |
|---|---|
link |
Network device (interface) management |
addr |
Protocol (IP/IPv6) address management |
route |
Routing table management |
neigh |
Neighbor/ARP table management |
rule |
Routing policy database management |
tunnel |
Tunnel configuration |
monitor |
Monitor netlink messages |
Examples
Interface Management (ip link)
Show all network interfaces
Displays all network interfaces with their status
Show specific interface
Shows details for the eth0 interface only
Enable network interface
Brings the eth0 interface up (enables it)
Disable network interface
Brings the eth0 interface down (disables it)
Change MAC address
Changes the MAC address of eth0 interface
Set MTU size
Sets the Maximum Transfer Unit for eth0
Address Management (ip addr)
Show all IP addresses
Displays IP addresses for all interfaces
Show addresses for specific interface
Shows IP addresses only for eth0 interface
Add IP address
Adds IP address 192.168.1.100 with /24 netmask to eth0
Remove IP address
Removes the specified IP address from eth0
Add secondary IP address
Adds a secondary IP address with a label
Routing Management (ip route)
Show routing table
Displays the current routing table
Add default gateway
Sets 192.168.1.1 as the default gateway
Add specific route
Adds route to 10.0.0.0/8 network via 192.168.1.254
Delete route
Removes the route to 10.0.0.0/8 network
Show route to specific destination
Shows the route that would be used to reach 8.8.8.8
Neighbor Management (ip neigh)
Show ARP table
Displays the neighbor (ARP) table
Add static ARP entry
Adds a static ARP entry
Delete ARP entry
Removes an ARP entry
Monitoring (ip monitor)
Monitor all network changes
Monitors all network configuration changes in real-time
Monitor specific object
Monitors only routing table changes
Advanced Usage
Create VLAN interface
Creates a VLAN interface with ID 100
Create bridge interface
Creates a bridge and adds eth0 to it
Policy-based routing
Creates policy-based routing for specific subnet
Show statistics
Shows interface statistics including packet counts
ip vs Traditional Commands
| Traditional Command | ip Command Equivalent |
|---|---|
ifconfig |
ip addr show |
ifconfig eth0 up |
ip link set eth0 up |
ifconfig eth0 192.168.1.1 |
ip addr add 192.168.1.1/24 dev eth0 |
route -n |
ip route show |
route add default gw 192.168.1.1 |
ip route add default via 192.168.1.1 |
arp -a |
ip neigh show |
netstat -i |
ip -s link |
Common Use Cases
When to Use ip Command
- Network Configuration - Configure interfaces and addresses
- Routing Management - Set up complex routing scenarios
- Network Troubleshooting - Diagnose connectivity issues
- Advanced Networking - VLANs, bridges, tunnels
- Automation - Scripting network configurations