ip link set ‐ #networking - five4nets/Linux-Knowledgebase GitHub Wiki

Tutorial: Using the Linux ip link set Command

The ip link set command in Linux is used to configure network interfaces, such as enabling or disabling them, changing MTU sizes, or setting MAC addresses. It’s part of the iproute2 suite, a modern replacement for older tools like ifconfig. This tutorial explains the command’s purpose, options, and provides practical examples.

Prerequisites

  • A Linux system with iproute2 installed (most distributions include it by default).
  • Root or sudo privileges for most operations.
  • Basic understanding of network interfaces (e.g., eth0, wlan0).

Command Syntax

ip link set [INTERFACE] [OPTIONS]
  • [INTERFACE]: The network interface name (e.g., eth0, lo).
  • [OPTIONS]: Parameters like up, down, mtu, name, or address.

Common Options

  • up: Activates the interface.
  • down: Deactivates the interface.
  • mtu SIZE: Sets the Maximum Transmission Unit (MTU) size in bytes.
  • name NEW_NAME: Renames the interface.
  • address MAC_ADDRESS: Changes the interface’s MAC address.
  • promisc on|off: Enables or disables promiscuous mode.

Examples

1. Activating and Deactivating an Interface

To bring an interface online or offline:

sudo ip link set eth0 up

This activates the eth0 interface.

sudo ip link set eth0 down

This deactivates eth0.

Use Case: Enable a network card after configuration or disable it for maintenance.

2. Changing the MTU Size

To set a custom MTU (e.g., 9000 for jumbo frames):

sudo ip link set eth0 mtu 9000

Verify the change:

ip link show eth0

Output (partial):

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9000 ...

Use Case: Optimize network performance for high-throughput environments.

3. Renaming a Network Interface

To rename eth0 to lan0:

sudo ip link set eth0 name lan0

The interface must be down before renaming:

sudo ip link set eth0 down
sudo ip link set eth0 name lan0
sudo ip link set lan0 up

Verify:

ip link show lan0

Use Case: Standardize interface names in a multi-device setup.

4. Changing the MAC Address

To set a new MAC address:

sudo ip link set eth0 address 00:1A:2B:3C:4D:5E

Verify:

ip link show eth0

Output (partial):

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> ... ether 00:1A:2B:3C:4D:5E ...

Use Case: Spoof a MAC address for testing or bypassing restrictions.

5. Enabling Promiscuous Mode

To enable promiscuous mode (captures all packets):

sudo ip link set eth0 promisc on

Disable it:

sudo ip link set eth0 promisc off

Verify:

ip link show eth0

Output (with promiscuous mode on):

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP,PROMISC> ...

Use Case: Network monitoring with tools like Wireshark.

Notes

  • Changes made with ip link set are temporary and reset after a reboot unless persisted (e.g., via network configuration files).
  • Always verify interface names with ip link or ifconfig.
  • Incorrect configurations (e.g., invalid MAC or MTU) may disrupt connectivity.

References