How to use the command 'ip' (with examples)

How to use the command 'ip' (with examples)

The ip command suite is a versatile toolkit used on Linux systems to manage and review various network settings. It provides utilities for displaying and modifying network interface configurations, routing, policy-based routing, and tunnels. This command is part of the iproute2 package, which is preferred over older tools like ifconfig and route. With ip, network administrators gain powerful insight and control over network environments, allowing for on-the-fly adjustments and detailed reporting on network conditions. The command’s flexibility stems from its multitude of subcommands and options, tailored for precise network management tasks.

List interfaces with detailed info

Code:

ip address

Motivation: Knowing the exact network configurations of each network interface is crucial for troubleshooting and network setup. By using ip address, you can review interfaces in depth, which includes IP addresses, network masks, and more information about each network item.

Explanation: The ip address command reveals comprehensive details about all network interfaces. ‘address’ prompts the ip command to focus on network-level attributes like IP addresses.

Example output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::aabb:ccff:fedd:efff/64 scope link 

List interfaces with brief network layer info

Code:

ip -brief address

Motivation: Sometimes you need a quick view of your network interfaces without overwhelming details. The -brief flag offers a succinct glance at the essential network information, perfect for quick status checks.

Explanation: The -brief argument provides a streamlined output with minimal information. This command still captures crucial points like the interface name, state, and IP address, but omits deeper configuration details that might clutter quick checks.

Example output:

lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0             UP             192.168.1.10/24 fe80::aabb:ccff:fedd:efff/64 

Code:

ip -brief link

Motivation: The link layer status is vital for understanding the physical properties of the network interfaces. This command can quickly confirm whether links are active, which aids in diagnosing connectivity issues.

Explanation: Here, -brief streamlines the output to focus on the link layer aspects, related to physical connections, bypassing extensive diagnostics to give just the interface’s state.

Example output:

lo               UNKNOWN        
eth0             UP             

Display the routing table

Code:

ip route

Motivation: Routing tables determine how packets are directed through the network. By examining the routing table, network administrators can verify paths and troubleshoot routing issues.

Explanation: Simply using ip route displays the kernel’s current routing table. This overview shows which network traffic is forwarded to which interfaces based on destination IP addresses.

Example output:

default via 192.168.1.1 dev eth0 
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10 

Show neighbors (ARP table)

Code:

ip neighbour

Motivation: The Address Resolution Protocol (ARP) table maps IP addresses to MAC addresses, facilitating local network communication. Understanding ARP entries helps in resolving network connectivity issues.

Explanation: ip neighbour reveals the ARP table, detailing IP addresses and their associated MAC addresses of connected devices. This is essential for resolving issues when devices do not appear to connect correctly over a local network.

Example output:

192.168.1.1 dev eth0 lladdr 00:11:22:33:44:55 STALE

Make an interface up/down

Code:

ip link set eth0 up

or to bring down:

ip link set eth0 down

Motivation: Network interfaces must be correctly managed to enable and disable connections intentionally, which is essential during maintenance or network setup.

Explanation:

  • link set: Specifies modifying a link (interface) property.
  • eth0: Identifies the target interface.
  • up/down: Commands to activate or deactivate the interface, controlling data flow.

Example output for up:

(no output; success is implied)

Example output for down:

(no output; success is implied)

Add/Delete an IP address to an interface

Code:

Add an IP:

ip addr add 192.168.1.11/24 dev eth0

Delete an IP:

ip addr del 192.168.1.11/24 dev eth0

Motivation: Adjusting IP addresses on interfaces can be necessary when reconfiguring a network or moving devices across networks, ensuring the proper address within the network’s range.

Explanation:

  • addr add/del: Commands the addition or removal of an IP.
  • 192.168.1.11/24: Specifies the IP and subnet.
  • dev eth0: Highlights the target interface for this change.

Example output for add:

(no output; success is implied)

Example output for delete:

(no output; success is implied)

Add a default route

Code:

ip route add default via 192.168.1.1 dev eth0

Motivation: Establishing a default route is fundamental to network configuration; it guides packets to external networks, typically through the network’s gateway.

Explanation:

  • route add: Indicates a route addition.
  • default: Specifies the default routing rule.
  • via 192.168.1.1: Maintains the gateway address.
  • dev eth0: Indicates the interface utilized for this default route.

Example output:

(no output; success is implied)

Conclusion:

The ip command suite serves as an invaluable resource for Linux network management, offering a variety of subcommands to display and alter network configurations efficiently. From diagnosing routing issues to interface configurations and controlling IP allocations, ip is a powerful tool for any network administrator. Its flexibility and depth make it a cornerstone in Linux network management, providing precise control over network operations.

Tags :

Related Posts

Understanding the 'postconf' Command in Postfix (with examples)

Understanding the 'postconf' Command in Postfix (with examples)

The postconf utility is an essential tool for managing the configuration of the Postfix mail transfer agent (MTA).

Read More
How to Use the Command 'agetty' (with Examples)

How to Use the Command 'agetty' (with Examples)

agetty is an alternative to the widely used getty command in Linux systems.

Read More
How to Use the Command 'debsecan' (with Examples)

How to Use the Command 'debsecan' (with Examples)

Debsecan, or Debian Security Analyzer, is a tool designed to help maintain the security of a Debian-based system by listing potential vulnerabilities in the installed packages.

Read More