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

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

The ip link command is used to manage network interfaces in Linux. It provides a way to view information about network interfaces, bring them up or down, assign meaningful names, change MAC addresses, and modify the Maximum Transmission Unit (MTU) size. This article will illustrate each of these use cases with examples.

Use case 1: Show information about all network interfaces

Code:

ip link

Motivation: This use case is helpful when you want to quickly view information about all the network interfaces on your system. It provides a summary of each interface, including its name, state, and MAC address.

Explanation: The command ip link without any arguments displays information about all network interfaces present on the system.

Example output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:44:bd:fb brd ff:ff:ff:ff:ff:ff

Use case 2: Show information about a specific network interface

Code:

ip link show ethN

Motivation: Sometimes you need detailed information about a specific network interface, including its state, IP address, MAC address, MTU size, and more. This use case allows you to focus on a particular interface.

Explanation: Replace ethN with the name of the network interface you want to view the information for. For example, if you want to view details about the interface named eth0, the command would be ip link show eth0.

Example output:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:44:bd:fb brd ff:ff:ff:ff:ff:ff

Use case 3: Bring a network interface up or down

Code:

ip link set ethN up|down

Motivation: This use case allows you to control the state of a network interface. You can bring an interface up if it is currently down or vice versa.

Explanation: Replace ethN with the name of the network interface you want to bring up or down. Use up to bring the interface up and down to bring it down.

Example output: None. The command will execute silently.

Use case 4: Give a meaningful name to a network interface

Code:

ip link set ethN alias "LAN Interface"

Motivation: Network interfaces are often named with generic names like eth0, eth1, etc. Giving a meaningful name to a network interface can improve readability and make it easier to identify the purpose of the interface.

Explanation: Replace ethN with the name of the network interface you want to assign a meaningful name to. Use the alias option followed by the desired name in quotes.

Example output: None. The command will execute silently.

Use case 5: Change the MAC address of a network interface

Code:

ip link set ethN address ff:ff:ff:ff:ff:ff

Motivation: Changing the MAC address of a network interface can be useful in scenarios where you want to spoof the MAC address for anonymity or security reasons.

Explanation: Replace ethN with the name of the network interface you want to change the MAC address for. Use the address option followed by the new MAC address in the format xx:xx:xx:xx:xx:xx.

Example output: None. The command will execute silently.

Use case 6: Change the MTU size for a network interface to use jumbo frames

Code:

ip link set ethN mtu 9000

Motivation: Jumbo frames are network frames with an MTU greater than the standard 1500 bytes. Enabling jumbo frames can increase network performance and throughput in certain scenarios, such as data transfer between servers.

Explanation: Replace ethN with the name of the network interface you want to change the MTU size for. Use the mtu option followed by the desired MTU size in bytes.

Example output: None. The command will execute silently.

Conclusion:

The ip link command is a versatile tool for managing network interfaces in Linux. With it, you can view information about interfaces, bring them up or down, assign names, change MAC addresses, and modify the MTU size. Understanding these use cases will empower you to configure and control your network interfaces effectively.

Related Posts

How to use the command uwfmgr (with examples)

How to use the command uwfmgr (with examples)

The uwfmgr command is used to manage and configure the Unified Write Filter (UWF) on Windows systems.

Read More
How to use the command 'apt-add-repository' (with examples)

How to use the command 'apt-add-repository' (with examples)

The ‘apt-add-repository’ command is used to manage apt repository definitions on Debian-based systems.

Read More
How to use the command 'dropbearkey' (with examples)

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

The ‘dropbearkey’ command is used to generate SSH keys in Dropbear format.

Read More