Ubuntu – How to assign unique MAC addresses to sub-interfaces

dhcpethernetnetworkingserver

I'm in a corporate environment with a DHCP server with static assignments for my server. I have one physical nic with several sub-interfaces. I statically assign different MAC addresses for each sub-interface to get another IP address from the DHCP server. For some reason, my server is not taking the static MAC addresses. You'll notice that ifconfig shows each interface with the same MAC.

How do I assign unique MAC addresses to my sub-interfaces?

$ cat interfaces

auto lo 
iface lo inet loopback

auto eth0:1
iface eth0:1 inet dhcp 
        hwaddress ether 00:0c:29:31:24:fa
        hostname gwrt-test
        client gwrt-test

auto eth0:2
iface eth0:2 inet dhcp
        hwaddress ether 00:0c:29:31:25:fa
        hostname gwrt-test2
        client gwrt-test2

$ ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0c:29:31:25:fa  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:329737 errors:0 dropped:0 overruns:0 frame:0
          TX packets:121645 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:69228791 (69.2 MB)  TX bytes:63531749 (63.5 MB)
          Interrupt:16 

eth0:1    Link encap:Ethernet  HWaddr 00:0c:29:31:25:fa  <- should be 24:fa
          inet addr:10.203.102.29  Bcast:10.203.102.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:16 

eth0:2    Link encap:Ethernet  HWaddr 00:0c:29:31:25:fa  
          inet addr:10.203.102.32  Bcast:10.203.102.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:16

Best Answer

You can install macchanger Install macchanger

Then execute like following,

sudo macchanger --mac 00:11:22:33:44:55 <interface_name>

More details

Related Question