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

ip [OPTIONS] OBJECT { COMMAND | help }

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

ip link show

Displays all network interfaces with their status

Show specific interface

ip link show eth0

Shows details for the eth0 interface only

Enable network interface

sudo ip link set eth0 up

Brings the eth0 interface up (enables it)

Disable network interface

sudo ip link set eth0 down

Brings the eth0 interface down (disables it)

Change MAC address

sudo ip link set eth0 address 00:11:22:33:44:55

Changes the MAC address of eth0 interface

Set MTU size

sudo ip link set eth0 mtu 1500

Sets the Maximum Transfer Unit for eth0

Address Management (ip addr)

Show all IP addresses

ip addr show

Displays IP addresses for all interfaces

Show addresses for specific interface

ip addr show eth0

Shows IP addresses only for eth0 interface

Add IP address

sudo ip addr add 192.168.1.100/24 dev eth0

Adds IP address 192.168.1.100 with /24 netmask to eth0

Remove IP address

sudo ip addr del 192.168.1.100/24 dev eth0

Removes the specified IP address from eth0

Add secondary IP address

sudo ip addr add 192.168.1.101/24 dev eth0 label eth0:1

Adds a secondary IP address with a label

Routing Management (ip route)

Show routing table

ip route show

Displays the current routing table

Add default gateway

sudo ip route add default via 192.168.1.1

Sets 192.168.1.1 as the default gateway

Add specific route

sudo ip route add 10.0.0.0/8 via 192.168.1.254

Adds route to 10.0.0.0/8 network via 192.168.1.254

Delete route

sudo ip route del 10.0.0.0/8

Removes the route to 10.0.0.0/8 network

Show route to specific destination

ip route get 8.8.8.8

Shows the route that would be used to reach 8.8.8.8

Neighbor Management (ip neigh)

Show ARP table

ip neigh show

Displays the neighbor (ARP) table

Add static ARP entry

sudo ip neigh add 192.168.1.50 lladdr 00:11:22:33:44:55 dev eth0

Adds a static ARP entry

Delete ARP entry

sudo ip neigh del 192.168.1.50 dev eth0

Removes an ARP entry

Monitoring (ip monitor)

Monitor all network changes

ip monitor

Monitors all network configuration changes in real-time

Monitor specific object

ip monitor route

Monitors only routing table changes

Advanced Usage

Create VLAN interface

sudo ip link add link eth0 name eth0.100 type vlan id 100 sudo ip link set eth0.100 up

Creates a VLAN interface with ID 100

Create bridge interface

sudo ip link add name br0 type bridge sudo ip link set br0 up sudo ip link set eth0 master br0

Creates a bridge and adds eth0 to it

Policy-based routing

sudo ip rule add from 192.168.1.0/24 table 100 sudo ip route add default via 192.168.2.1 table 100

Creates policy-based routing for specific subnet

Show statistics

ip -s link show eth0

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

See also