multiple MAC addresses on one physical network interface (linux)

Simple question: How can I setup multiple MAC addresses on one physical network interface (linux)?

Why? My ISP is checking ip<->mac on GW and I d like to route traffic through my "linuxbox" and than forward it with different source ip.

Without checking ip<->mac, I will use eth0, eth0:0, but in this situation I need unique MAC address for every IP.


You can use macvlan to create multiple virtual interfaces with different MAC addresses.

ip link add link eth0 address 00:11:11:11:11:11 eth0.1 type macvlan
ip link add link eth0 address 00:22:22:22:22:22 eth0.2 type macvlan

In theory that should be all you need, though at some point something broke in the kernel and it would cause it to use one MAC for everything. I'm not sure what the status of that is; hopefully it's fixed.

If not, you could use arptables to rewrite the MAC addresses on output based on the egress interface or on input based on destination IP:

arptables -A OUT -o eth0.1 --arhln 06 -j mangle --mangle-hw-s 00:11:11:11:11:11
arptables -A OUT -o eth0.2 --arhln 06 -j mangle --mangle-hw-s 00:22:22:22:22:22
arptables -A IN -d 192.168.1.1 --arhln 06 -j mangle --mangle-hw-d 00:11:11:11:11:11
arptables -A IN -d 192.168.1.2 --arhln 06 -j mangle --mangle-hw-d 00:22:22:22:22:22

Unfortunately arptables is also quite buggy in my experience.


The reason why your bridge and TAP interface share the same MAC address,is because the bridge does not have a MAC,until its bound to an interface. If you create a bridge with BRCTL,and do a "brctl show",you will find the bridge has empty ports.(no interface bound to it) In binding TAP0 to br0,naturally,it will show as the same MAC. I created a test bridge,to illustrate.

# brctl addbr testbr0

[root@stooge etc]# brctl show testbr0
bridge name bridge id       STP enabled interfaces
testbr0     8000.000000000000   no

I created three test TAPS. The output from "brctl showmacs testbr0".

[root@stooge etc]# brctl showmacs testbr0
port no mac addr        is local?   ageing timer
  1 86:51:b6:95:0e:b6   yes        0.00
  2 86:58:63:c6:d4:e7   yes        0.00
  3 8a:a7:fa:17:c5:12   yes        0.00

As you can see,each bridge port has a unique MAC address,and the bridge should show its MAC, as the first interface bound. If you bridge a physical network interface,the Ethernet bridge will inherit its MAC address,and move all virtual interfaces down. Example binding eth0,to the test bridge.

[root@stooge etc]# brctl showmacs testbr0
port no mac addr        is local?   ageing timer
  4 AA:BB:CC:DD:EE:FF   yes        0.00
  1 86:51:b6:95:0e:b6   yes        0.00
  2 86:58:63:c6:d4:e7   yes        0.00
  3 8a:a7:fa:17:c5:12   yes        0.00

Using "brctl show" again;

[root@stooge etc]# brctl show
bridge name     bridge id               STP enabled     interfaces
testbr0         8000.00aabbccddee       no              eth0
                                                        tap00
                                                        tap01
                                                        tap02 

the TAP interfaces have moved down one,even though eth0,is still at PORT 4. You still have unique MAC addresses. If the Ethernet bridge is bound to a source-route interface,you have no choice in using an IP address,or DHCP. For what its worth,if you bridge a source-route interface,you will show a "non-local" MAC address. This is the next-hop router MAC address. I know in RedHat,there is an option in specifying a source IP,using IFCONFIG. My first option,would be consulting the IP command reference,as I think you can specify a source IP. I never have tried it.


Try to create tap devices or any other virtual ethernet devices with needed MAC addresses and IPs and then attach them into one bridge with eth0.