ip Command in Linux

Learn via video courses
Topics Covered

Overview

The ip command in Linux is a versatile tool used to manage network interfaces, routing tables, and IP addresses. It is part of the iproute2 package and has largely replaced the old ifconfig command, offering more features and flexibility. This command is essential for anyone dealing with networking in Linux.

Syntax of ip Command in Linux

The basic syntax of the ip command in Linux is as follows:

Where:

  • options: This can be various flags that modify the behavior of the command.
  • OBJECT: This refers to the type of object we are interacting with, such as 'address', 'route', 'link', etc.
  • command: The action to be performed on the object. Some examples include 'add', 'del', 'show', etc.
  • arguments: These are additional parameters needed for the command to execute.

Options in ip Command in Linux

  1. -s, --statistics: This option makes the command output more detailed information.

    For example -

    Output:

    This command will provide detailed statistics such as the number of received and transmitted packets, errors, dropped packets, etc.

  2. -4, -6: These options force the ip command to use either IPv4 (-4) or IPv6 (-6).

    For example -

    Output:

    This command allows the user to specifically interact with IPv4 addresses.

  3. -o, --oneline: This option makes the output to be printed on one line, which is very useful when dealing with multiple entries.

    For example -

    Output:

    This command makes it easier to read or parse the output.

Example Usages

  • To display all network interfaces:

    Output:

    Explanation: This command provides a list of all active and inactive network interfaces on the system.

  • To add a new IP address to an interface:

    Output:

    Explanation: This command is useful when configuring a new network interface.

Tips

  • To make changes permanent across reboots, you should put these commands in a startup script or use the Network Manager interface.

  • While using 'ip command linux' for network troubleshooting, the '-s' (statistics) option can provide useful detailed information.

Advanced Use Cases of ip Command in Linux

  • Setting up a new static route:

    Output:

    Explanation: This command is necessary when you want to manually manage the routing table.

  • Deleting an IP address:

    Output:

    Explanation: This command is useful when you want to remove an IP address from an interface.

  • Displaying all IP addresses on your machine in a concise way:

    Output:

    Explanation: This command makes it easier to get a quick overview of the IP configuration on the system.

Conclusion

  • The 'ip command linux' is a powerful tool for managing networking in Linux.

  • It can be used to configure and modify network interfaces, IP addresses, and routing tables.

  • The output of the ip command can be made more detailed or concise with various options.