0

Debian host. I have a single NIC that's supposed to sit on two networks; on 172.16.0.0/24 and 10.0.80.0/24.

  • On the 172.16.0.0/24 network, there should be a bridge, so that local KVM hosts can attach to it; the host machine should be available at 172.16.0.99.
  • On the 10.0.80.0/24 network, no need for a bridge, and machine should be available at 10.0.80.99.

A cheap D-Link switch is linked to that NIC; it may be confused by multiple IP addresses associated with the same MAC.

I've tried aliasing the NIC (e.g. adding a enp1s0:0 device), aliasing the bridge (e.g. vmbr0:0), but every permutation I've tried failed, and all I can find in search engines deals only with one aspect at a time (two IPs on same NIC, bridge aliases, MAC address mangling).

For reference, this is the setup for the bridge; how can I add a 10.0.80.99 address to the same NIC, ideally forcing a different MAC address for it?

iface enp1s0   inet manual

auto  vmbr0
iface vmbr0 inet static
        address      172.16.0.99/24
        gateway      172.16.0.1
        bridge_ports enp1s0
        bridge_stp   off
        bridge_fd    0

1 Answers1

1

Your concern is wrong.

It is pretty typical in IP networks to have several IP addresses associated with the same MAC, though switches don't bother with this. I mean, any address from a network behind the router could be only associated with a router MAC. Also same situation happens in case of proxy ARP (which is a kind of "hacky routing"); and again, everything works, and if ever problem arise, they aren't related to switches.

A cheap D-Link switch only examines Ethernet header and trailer of packet and considers everything else as a payload. It parses a header, looks for a packet length to know how many bytes to forward, it looks for a destination MAC and forwards a packet to the associated port or floods it to all ports except ingress if there's still no associated port for that MAC; at the same time, it extracts a source MAC and associates it the with ingress port (the one packet came from). It doesn't know what IP address is and where it is in the packet, and all this process will work even if there'll be non-IP Ethernet packets. IPv6, IPX, AoE, anything you can think of — all of them would work, even at the same time within the same Ethernet segment through the same cheap D-Link switch. Also having more that one IP network in the same Ethernet segment is pretty normal, it would work perfectly and nothing will be confused. Don't worry.

Therefore, you have absolutely no need to set up another IP address with another MAC. Exact opposite is true: by not using an additional redundant MAC you only can make life easier for your switch. This way you fill its (reasonably small) MAC address table less, have less probability for collisions and so on. For a switch, less MAC addresses in the network, easier to work! Although this benefit is only theoretical, one more MAC wouldn't make any noticeable difference, but still you have think of it.

Just go with this configuration:

auto  vmbr0
iface vmbr0 inet static
        address      172.16.0.99/24
        gateway      172.16.0.1
        bridge_ports enp1s0
        bridge_stp   off
        bridge_fd    0

iface vmbr0 inet static
    address 10.0.80.99/24

Or follow the link above and try a "manual configuration" (the next header).


In case you absolutely sure you need to have a single server with two different MACs, you may use a macvlan virtual interface:

auto  vmbr0
iface vmbr0 inet static
        address      172.16.0.99/24
        gateway      172.16.0.1
        bridge_ports enp1s0
        bridge_stp   off
        bridge_fd    0

auto vmbr0mv1
iface vmbr0mv1 inet static
    pre-up ip link add vmbr0mv1 link vmbr0 type macvlan mode bridge
    address 10.0.80.99/24
    post-down ip link del vmbr0mv1

it will be created with random MAC address, but you can add another pre-up line which will set any MAC address you want.

But again, don't do this just for "not to confuse a cheap D-Link switch". With this you're confusing it more instead. This is designed for completely different things, for example, for putting a macvlan interface into another network namespace, for containers to have "their own" network interfaces with least possible overhead.

Nikita Kipriyanov
  • 10,947
  • 2
  • 24
  • 45