User Tools

Site Tools


ubuntu:networking:configuration:change_the_mac_address_of_an_ethernet_interface

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ubuntu:networking:configuration:change_the_mac_address_of_an_ethernet_interface [2021/01/08 11:39] – created peterubuntu: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.  (Unlike IP addresses, there is no requirement for the addressing scheme to reflect the topology of the network.)  However there are circumstances which require the use of a specific address, or alternatively, a randomly-chosen address.  These include: 
- 
-  * 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.  Most drivers do this, but there are some which do not. 
- 
----- 
- 
-===== 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:5d:6c:e8:8d:b2 
-</code> 
- 
-or try: 
- 
-<code bash> 
-ifconfig en0 lladdr aa:bb:cc:11:22:33 
-</code> 
- 
- 
-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.  It follows that the first byte of the address should end with 2, 6, A or E when expressed in hexadecimal. 
- 
----- 
- 
-===== 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 
-</code> 
- 
-The MAC address is labelled **HWaddr** in the output from this command: 
- 
-<code bash> 
-eth0      Link encap:Ethernet  HWaddr 02:5d:6c:e8:8d:b2 
-          inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0 
-          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1 
-          RX packets:9659 errors:0 dropped:0 overruns:0 frame:0 
-          TX packets:309 errors:0 dropped:0 overruns:0 carrier:0 
-          collisions:0 txqueuelen:1000 
-          RX bytes:2783810 (2.6 MiB)  TX bytes:25318 (24.7 KiB) 
-</code> 
- 
----- 
- 
-==== 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.  The traffic can be inspected using **tcpdump**: 
- 
-<code bash> 
-tcpdump -i eth0 -e -n "icmp and host 192.168.0.2" 
-</code> 
- 
-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 
-</code> 
- 
-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:28:08.574438 02:5d:6c:e8:8d:b2 > 02:a2:e3:40:d7:29, ethertype IPv4 (0x0800), length 98: 
- 192.168.0.2 > 192.168.0.1: ICMP echo request, id 2919, seq 1, length 64 
-16:28:08.574591 02:a2:e3:40:d7:29 > 02:5d:6c:e8:8d:b2, ethertype IPv4 (0x0800), length 98: 
- 192.168.0.1 > 192.168.0.2: ICMP echo reply, id 2919, seq 1, length 64 
-</code> 
- 
----- 
- 
-===== Errors ===== 
- 
-==== Operation not supported ==== 
- 
-The error: 
- 
-<code bash> 
-SIOCSIFHWADDR: Operation not supported 
-</code> 
- 
-indicates that the hardware address for the specified interface cannot be changed.  This could be because the interface does not have a hardware address, or because the ability to change the address has not been implemented by the relevant device driver. 
- 
----- 
- 
-==== Cannot assign requested address ==== 
- 
-The error: 
- 
-<code bash> 
-SIOCSIFHWADDR: Cannot assign requested address 
-</code> 
- 
-probably indicates that the requested MAC address is not a unicast address.  (To qualify as a unicast address the first byte must be even.) 
- 
----- 
- 
-==== Device or resource busy ==== 
- 
-The error: 
- 
-<code bash> 
-SIOCSIFHWADDR: Device or resource busy - you may need to down the interface 
-</code> 
- 
-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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki