ubuntu:networking:configuration:change_the_mac_address_of_an_ethernet_interface
Differences
This shows you the differences between two versions of the page.
ubuntu:networking:configuration:change_the_mac_address_of_an_ethernet_interface [2021/01/08 11:39] – created peter | ubuntu:networking:configuration:change_the_mac_address_of_an_ethernet_interface [2021/01/08 15:31] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Networking - Configuration - Change the MAC address of an Ethernet interface ====== | ||
- | |||
- | To change the MAC address of an Ethernet interface | ||
- | |||
- | ---- | ||
- | |||
- | ===== Background ===== | ||
- | |||
- | It is rarely necessary to change the MAC address of an Ethernet interface because for most purposes any unique address will suffice. | ||
- | |||
- | * use of a service that has been locked to a particular MAC address; | ||
- | * participation in a failover or load balancing scheme that requires use of the same MAC address on multiple interfaces; | ||
- | * anonymous use of a network where MAC addresses are logged. | ||
- | |||
- | The ability to change the MAC address of an interface is dependent on support being provided by the relevant device driver. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Non-persistent method ===== | ||
- | |||
- | If the MAC address of an interface is capable of being changed then this can be done using the **ifconfig** command: | ||
- | |||
- | <code bash> | ||
- | ifconfig eth0 hw ether 02: | ||
- | </ | ||
- | |||
- | or try: | ||
- | |||
- | <code bash> | ||
- | ifconfig en0 lladdr aa: | ||
- | </ | ||
- | |||
- | |||
- | The new address will not persist beyond a reboot. | ||
- | |||
- | If you are inventing a new MAC address for an interface (as opposed to mimicing an existing one) then be aware that two of the bits in the address have special meanings: | ||
- | |||
- | * The least significant bit of the first byte is set to zero for unicast addresses or one for multicast addresses. | ||
- | * The second least significant bit is set to zero for globally unique addresses (which would typically be assigned by hardware manufacturers) or one for locally administered addresses. | ||
- | |||
- | For a locally administered unicast address these bits should be set to zero and one respectively. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Testing ===== | ||
- | |||
- | ==== Check the configured MAC address ==== | ||
- | |||
- | You can verify that the interface has been configured with the intended MAC address using the ifconfig command: | ||
- | |||
- | <code bash> | ||
- | ifconfig eth0 | ||
- | </ | ||
- | |||
- | The MAC address is labelled **HWaddr** in the output from this command: | ||
- | |||
- | <code bash> | ||
- | eth0 Link encap: | ||
- | inet addr: | ||
- | UP BROADCAST RUNNING MULTICAST | ||
- | RX packets: | ||
- | TX packets:309 errors:0 dropped:0 overruns:0 carrier:0 | ||
- | collisions: | ||
- | RX bytes: | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ==== Inspect inbound and outbound traffic ==== | ||
- | |||
- | You can verify that the interface is using the intended MAC address by generating some inbound and outbound network traffic then inspecting the resulting Ethernet headers. | ||
- | |||
- | <code bash> | ||
- | tcpdump -i eth0 -e -n "icmp and host 192.168.0.2" | ||
- | </ | ||
- | |||
- | The options used here are: | ||
- | |||
- | * -i to specify the interface name, | ||
- | * -e to enable the display of link-layer headers, and | ||
- | * -n to display IP addresses numerically. | ||
- | |||
- | The filter restricts the output to ICMP traffic addressed to or from the local machine. | ||
- | |||
- | While tcpdump is running, generate some ICMP traffic using the ping command. Assuming that there is a machine that responds to ping at 192.168.0.1: | ||
- | |||
- | <code bash> | ||
- | ping 192.168.0.1 | ||
- | </ | ||
- | |||
- | The output from tcpdump should show the new MAC address as the link layer source address for echo requests, and as the destination address for echo replies: | ||
- | |||
- | <code bash> | ||
- | 16: | ||
- | | ||
- | 16: | ||
- | | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Errors ===== | ||
- | |||
- | ==== Operation not supported ==== | ||
- | |||
- | The error: | ||
- | |||
- | <code bash> | ||
- | SIOCSIFHWADDR: | ||
- | </ | ||
- | |||
- | indicates that the hardware address for the specified interface cannot be changed. | ||
- | |||
- | ---- | ||
- | |||
- | ==== Cannot assign requested address ==== | ||
- | |||
- | The error: | ||
- | |||
- | <code bash> | ||
- | SIOCSIFHWADDR: | ||
- | </ | ||
- | |||
- | probably indicates that the requested MAC address is not a unicast address. | ||
- | |||
- | ---- | ||
- | |||
- | ==== Device or resource busy ==== | ||
- | |||
- | The error: | ||
- | |||
- | <code bash> | ||
- | SIOCSIFHWADDR: | ||
- | </ | ||
- | |||
- | probably indicates that the relevant device driver does not allow the MAC address to be changed while the interface is up. | ||
- | |||
ubuntu/networking/configuration/change_the_mac_address_of_an_ethernet_interface.1610105964.txt.gz · Last modified: 2021/01/08 11:39 by peter