The Ultimate Guide to Linux IP Command

linux ip command

The IP command is one of the most important and powerful tools in Linux. It allows you to manage network interfaces, routing tables, and various other network-related tasks. In this article, we will explore the Linux IP command and its various options, along with code examples and related concepts.

What is the Linux IP Command?

The IP command is a command-line tool that is used to manage network interfaces, routing tables, and other network-related tasks on Linux systems. It is a part of the iproute2 package and provides a powerful set of options to manage network interfaces and routing tables.

Basic Usage of the IP Command

The basic syntax of the IP command is as follows:

ip [OPTIONS] OBJECT {COMMAND | help}

Here, OPTIONS are the various options available for the IP command, OBJECT is the network object to be managed (such as link or address), COMMAND is the operation to be performed on the object (such as add or delete), and help is used to display the help message.

Managing Network Interfaces with IP Command

One of the primary uses of the IP command is to manage network interfaces. The following are some of the most commonly used commands for managing network interfaces:

1. List Network Interfaces

To list all the network interfaces on your system, use the following command:

ip link show

This command will display a list of all the network interfaces on your system, along with their status, MAC address, and other information.

2. Bring Up a Network Interface

To bring up a network interface, use the following command:

ip link set dev eth0 up

Here, eth0 is the name of the network interface that you want to bring up.

3. Bring Down a Network Interface

To bring down a network interface, use the following command:

ip link set dev eth0 down

Here, eth0 is the name of the network interface that you want to bring down.

4. Assign an IP Address to a Network Interface

To assign an IP address to a network interface, use the following command:

ip address add 192.168.1.10/24 dev eth0

Here, 192.168.1.10/24 is the IP address that you want to assign to the network interface eth0.

5. Remove an IP Address from a Network Interface

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

ip address del 192.168.1.10/24 dev eth0

Here, 192.168.1.10/24 is the IP address that you want to remove from the network interface eth0.

Managing Routing Tables with IP Command

Another important use of the IP command is to manage routing tables. The following are some of the most commonly used commands for managing routing tables:

1. Show Routing Table

To display the routing table, use the following command:

ip route show

This command will display the routing table, which consists of a list of network destinations and their associated routes.

2. Add a Route to the Routing Table

To add a route to the routing table, use the following command:

ip route add 192.168.1.0/24 via 192.168.0.1 dev eth0

Here, 192.168.1.0/24 is the network destination that you want to add to the routing table, 192.168.0.1 is the gateway for the network, and eth0 is the network interface that should be used to reach the network.

3. Remove a Route from the Routing Table

To remove a route from the routing table, use the following command:

ip route del 192.168.1.0/24 via 192.168.0.1 dev eth0

Here, 192.168.1.0/24 is the network destination that you want to remove from the routing table, 192.168.0.1 is the gateway for the network, and eth0 is the network interface that was used to reach the network.

Conclusion

In conclusion, the Linux IP command is a powerful tool for managing network interfaces and routing tables on Linux systems. It provides a wide range of options and commands that can be used to manage various network-related tasks. By using the IP command, you can easily bring up or down network interfaces, assign or remove IP addresses, and add or remove routes from the routing table. With this guide, you should now have a better understanding of how to use the Linux IP command in your professional setting.