How to Use the ip Command to Manage Networks in Linux

The ip command is used to manage network interfaces in Linux. The command is versatile and can be used to manage several aspects of IP networking, such as addresses, routes, tunnels, and more. The ip command can be run on the command line interface of a Linux system, making it an essential tool for any Linux system administrator.
In this article, we will explore how to use the ip command to manage networks in Linux.
1. Displaying Network Interfaces
Before we start managing network interfaces, we need to know which network interfaces are in use. To display the network interfaces on your Linux system, use the following command:
$ ip link
This command displays the network interfaces along with their MAC addresses, state, and other information.
2. Configuring IP Addresses
Once you have identified the network interface you want to configure, the next step is to configure the IP address. To configure the IP address, use the following command:
$ ip addr add / dev
For example, to set the IP address of the enp0s3 interface to 192.168.1.10, use the following command:
$ ip addr add 192.168.1.10/24 dev enp0s3
Here, the /24 represents the subnet mask.
3. Setting Up Routes
To set up a route, use the following command:
$ ip route add / via dev
For example, to set up a route for the network 192.168.1.0/24, use the following command:
$ ip route add 192.168.1.0/24 via 192.168.1.1 dev enp0s3
Here, 192.168.1.1 is the IP address of the gateway.
4. Enabling and Disabling Network Interfaces
To enable or disable a network interface, use the following commands:
$ ip link set up (to enable a network interface)
$ ip link set down (to disable a network interface)
For example, to disable the enp0s3 interface, use the following command:
$ ip link set enp0s3 down
5. Creating Virtual Interfaces
We can also create virtual interfaces using the ip command. Virtual interfaces are useful when we need to create multiple IP addresses on a single physical interface. To create a virtual interface, use the following command:
$ ip link add type
For example, to create a virtual interface named enp0s3:0, use the following command:
$ ip link add enp0s3:0 type bridge
6. Managing Tunnels
The ip command can also manage tunnel interfaces. Tunnel interfaces are used to send network traffic over an IP-based network. To create a tunnel interface, use the following command:
$ ip tunnel add mode remote
For example, to create a tunnel interface named tun0, use the following command:
$ ip tunnel add tun0 mode gre remote 10.10.10.1
Here, gre is the tunnel mode, and 10.10.10.1 is the IP address of the remote system.
Conclusion
The ip command is a powerful tool for managing network interfaces in Linux. It provides several features, such as configuring IP addresses, setting up routes, enabling and disabling network interfaces, creating virtual interfaces, and managing tunnels. By understanding these commands, you can manage your Linux network interfaces efficiently.