27

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.

4 Answers 4

38

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.

2
  • 3
    Sorry to necropost, but regarding the "at some point something broke in the kernel and it would cause it to use one MAC for everything" part, it may not be a bug: I had to set the kernel tunable "net.ipv4.conf.all.arp_ignore" to 1 to get this working correctly. Other ARP tunables may be needed too; for more explanations, read this and this. Commented Jul 15, 2016 at 16:19
  • I added eth0.1 and eth0.2 to my eth0 interface. But how do I list those MAC addresses associated to eth0 now, or remove them? Commented Jun 29, 2023 at 6:26
5

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.

3

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.

1
  • I tried that already and it doesnt work. If i use br0(eth0,tap0,tap1). I have to set IP on br0 to get networking working. Without IP (ifconfig br0 0.0.0.0 up) network doesnt work. So when I set IP on br0 and tap0. (from win-pc)I can ping both IPs but after arp -a each of them have same MAC. Commented Jan 18, 2011 at 21:58
0

It looks like you might be able to use vconfig to create multiple vlan addresses on the same physical ethernet, each with different mac addresses.

1
  • Traffic from all IPs must be untagged Commented Jan 18, 2011 at 12:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.