Log In

How to Use the ip Command in Linux: A Comprehensive Tutorial

How to Use the ip Command in Linux: A Comprehensive Tutorial
08.07.2024
Reading time: 3 min
Hostman Team
Technical writer

The ip command in Linux is a powerful utility used for network management. It allows administrators to manage and configure various aspects of network interfaces, IP addresses, and routing tables. This tutorial will provide a comprehensive guide on using the ip command, illustrating its importance in network management and offering practical examples.

Importance of Network Management

Efficient network management is crucial for maintaining the performance and security of a system. The ip command offers a versatile set of options to monitor and configure network settings, making it an essential tool for system administrators.

Basic ip Command Syntax

The ip command syntax generally follows this structure:

ip [ OPTIONS ] OBJECT { COMMAND | help }
  • OPTIONS: Optional flags to modify the behavior of the command.

  • OBJECT: Specifies the type of network object to operate on (e.g., link, addr, route).

  • COMMAND: The action to perform on the object (e.g., add, delete, show).

Viewing Network Interfaces

To view the current network interfaces on your system, use the following command:

ip link show

This command displays detailed information about all available network interfaces.

Output:

Image1

Configuring IP Addresses

You can use the ip command for managing IP addresses.

Viewing IP Addresses

To view IP addresses assigned to all network interfaces, use:

ip addr show

Image3

Adding an IP Address

To add an IP address to a network interface, use:

sudo ip addr add 192.168.1.100/24 dev eth0

Removing an IP Address

To remove an IP address from a network interface, use:

sudo ip addr del 192.168.1.100/24 dev eth0

Managing Routes

Examples of using the ip command for managing routes.

Viewing Routing Table

To view the routing table, use:

ip route show

Image2

Adding a Route

To add a new route, use:

sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0

Deleting a Route

To delete an existing route, use:

sudo ip route del 192.168.2.0/24

Practical Examples of ip Command Usage

Let's look at a few practical examples of using the ip command.

Example 1: Configuring a Static IP Address

1. Check current IP addresses:

ip addr show

2. Add a new static IP address:

sudo ip addr add 192.168.1.50/24 dev eth0

3. Verify the new IP address:

ip addr show dev eth0

Example 2: Setting Up a Default Gateway

1. View current routes:

ip route show

2. Add a new default gateway:

sudo ip route add default via 192.168.1.1

3. Verify the new route:

ip route show

Example 3: Deleting an IP Address

1. View current IP addresses:

ip addr show

2. Remove the specific IP address:

sudo ip addr del 192.168.1.50/24 dev eth0

3. Verify the removal:

ip addr show dev eth0

Conclusion

The ip command in Linux is an indispensable tool for network management, offering extensive capabilities to configure and manage network settings efficiently. By understanding and utilizing the various functionalities of the ip command, system administrators can maintain robust network environments.


Share