Modify MAC address in Linux

        In Linux systems, you can modify the MAC address of the network card through some commands. Two common methods are introduced below, one is to permanently modify the MAC address, and the other is to temporarily modify the MAC address.

        Please note that before performing these operations, make sure you have administrator rights or are logged in as the root user.

Method 1: Permanently modify the MAC address

        1. First, open the terminal or console;

        2. Use the following command to view the network interfaces in the current system and their corresponding MAC addresses:

ifconfig

        Or use ipthe command:

ip link show

        3. Determine the name of the network interface you want to modify (usually starts with "eth" or "wlan", such as eth0, wlan0, etc.);

        4. Disable the network interface:

sudo ifconfig <interface_name> down

        Or use ipthe command:

sudo ip link set dev <interface_name> down

        5. Modify the MAC address:

sudo ifconfig <interface_name> hw ether XX:XX:XX:XX:XX:XX

        Or use ipthe command:

sudo ip link set dev <interface_name> address XX:XX:XX:XX:XX:XX

        Replace <interface_name>with the name of the network interface you want to modify XX:XX:XX:XX:XX:XXand the new MAC address you want to set.

        6. Enable the network interface:

sudo ifconfig <interface_name> up

        Or use ipthe command:

sudo ip link set dev <interface_name> up

        7. Confirm whether the MAC address has been modified successfully:

ifconfig <interface_name>

        Or use ipthe command:

ip link show <interface_name>

        8. Restart the network service to make the changes take effect (some distributions may not require this step):

sudo service network-manager restart   # 适用于Ubuntu等使用NetworkManager的发行版

        or:

sudo systemctl restart NetworkManager  # 适用于使用systemd的发行版

Method 2: Temporarily modify the MAC address

        If you only need to temporarily change the MAC address and do not want it to take effect permanently, you can use the following command:

sudo ifconfig <interface_name> hw ether XX:XX:XX:XX:XX:XX

         Or use ipthe command:

sudo ip link set dev <interface_name> address XX:XX:XX:XX:XX:XX

        The MAC address modified by this method will be restored to the original value after restarting.

        Please note that modifying the MAC address may affect network connections and related services. Before using these commands, make sure you understand the risks and know how to restore to default settings.

 

Guess you like

Origin blog.csdn.net/2203_75758128/article/details/132939098