One physical port: two IP (on the same subnet) with different MACs

I want to have 2 WAN IP addresses (of the same subnet) with different MAC addresses on the same physical port, with the same firewall rules (wan), and then, by means of routing table, separate the traffic.

I have been looking how to achieve this on 19.07.3 with macvlan (not mwan3). I've been testing different configurations, but haven't figured out the right combinaton of parameters yet.

BTW: This only have 1 vlan with the real physical port and the cpu:

Some other people reported having success by running something like:

ip link add link eth0 name veth0 type macvlan
ifconfig veth0 up
ip link add link eth0 name veth1 type macvlan
ifconfig veth1 up

Or:

config device 'veth0'
	option name 'veth0'
	option type 'macvlan'
	option ifname 'eth0'

config device 'veth1'
	option name 'veth1'
	option type 'macvlan'
	option ifname 'eth0'

So, because my actual network config is like:

config device 'wan_port' 
   option name 'eth0.1'
   option macaddr '11:11:11:11:11:11'

config interface 'wan'
   option ifname 'eth0.1'
   option proto 'static'
   option ipaddr '10.10.10.10'
   option netmask '255.255.255.0'

I did:

ip link add link eth0.1 name eth0.2 type macvlan
ifconfig eth0.2 up

Works when doing it manually, but not when adding it to the rc.local (I mean, it creates it and looks as it should, but it don't work).

Regarding the second approach, I think something like the following should work:

config device 'wan_port' 
   option name 'eth0.1'
   option macaddr '11:11:11:11:11:11'

config interface 'wan'
   option ifname 'eth0.1'
   option proto 'static'
   option ipaddr '10.10.10.10'
   option netmask '255.255.255.0'
   option metric '10'

config device 'foo_wan_port' 
   option name 'eth0.2'
   option type 'macvlan'
   option ifname 'eth0.1'
   option macaddr '11:11:11:22:22:22'

config interface 'foo_wan'
   option ifname 'eth0.2'
   option proto 'static'
   option ipaddr '10.10.10.20'
   option netmask '255.255.255.0'
   option metric '20'

I obtain different ifconfig / LuCI results depending on where on the config file I declare the MAC(s) and the macvlan(s) options, or whether I omit some, but with none of those I get a ping reply for the eth0.2, and under some combinations not even for eth0.1. Moreover, with most of the combinations, luci / kvorker eats a lot of cpu, making the ssh and LuCI response very slow.

Note: I also tried simply assigning two IP addresses / interfaces to the same eth0.1, but then I get the same MAC for both regardless what I declare for the override MAC option.

I would appreciate you support with this puzzle.

looks wrong...

EDIT: For sure something is wrong with the configurations I'm sharing. The logic tells me I should try eth0.2 over eth0, but I haven't figured out how. The eth0.2 over eth0.1 is what I have made work sometimes (/etc/init.d/network reload), but crashing after a reset, and/or making the response utterly slow (workaround for that: remove the cable and close LuCI).

1 Like

Here is one of the odd results when trying to create eth0.2 over eth0:


ifconfig don't process correctly the WAN2 creation instructions, but ip link does.

For the above example, I didn't declare the mac address I intend to use (assuming the device should take the e2:97:ac:85:c4:f4 macvlan provided). On the contrary, if I set the option macaddr for the interface, ifconfig do reports the eth0.2 creation, but still cannot ping the directly connected 10.10.10.1 gateway (timeout). The same (timeout) result occurs if I move the macaddr option declaration to the eth0_2_dev section.
image
For the scenarios where eth0.2 is created, worth noting no RX packets for it.

I can add: if I declare the option macaddr, it creates the additional interface, but with the same MAC macvlan provided, not the one I want.