The same IP on multiple interfaces

Solution 1:

Yes this is possible, using a nice feature called network namespaces (see man ip-netns(8)). It basically gives you multiple distinct network stacks, each with its own set of interfaces, routes etc.

You would need to create a namespace for each of your STBs and could then run your required services separately in each namespace.

For the namespaces you would need to proceed as follows:

  • Create a namespace called net1:

    ip netns add net1
    
  • Assign your interface ethX to the new namespace and configure your IP address 172.16.50.1:

    ip link set dev ethX netns net1
    ip netns exec net1 ip link set dev ethX up
    ip netns exec net1 ip address add 172.16.50.1/24 dev ethX
    

The IP address 172.16.50.1 is now not visible from your default namespace. A simple ping 172.16.50.1 doesn't work, you first need to switch to the net1 namespace and execute the command there:

ip netns exec net1 <command>

In this way you can now run each service in each of your namespaces.

If you feel adventurous, you could even try to somehow redirect all requests from your STBs to a central service. For this you need a tunnel from each namespace to your default namespace (see ip link help veth) and quite some iptables magic...

Solution 2:

Technically you can, but configuration would be colorful. It would be a kludge and it would require each STB to have a unique IP while being isolated on their own wire to satisfy your requirement. Configuration on the clients doesn't change. Here's the config on the server:

ifconfig eth0 10.0.50.1 netmask 255.0.0.0
route del -net 10.0.0.0 netmask 255.0.0.0 dev eth0
route add 10.0.50.2 dev eth0
ifconfig eth1 10.0.50.1 netmask 255.0.0.0
route del -net 10.0.0.0 netmask 255.0.0.0 dev eth1
route add 10.0.50.3 dev eth1
# ...

This should result in only one IP per interface in the routing table. These are on separate wires, so there's no crosstalk. Each of these devices would think they were on a 2 node 10.0.0.0/8.

When the server wants to talk to 10.0.50.2, it will look at the ARP table and then routing table. If the ARP table is empty, the routing table tells it to send an ARP request on the respective interface, therefore they MUST have unique IPs or the server will only be able to speak to the last route added.

You can set your DHCP server to assign IPs based on the hardware addresses or run a separate dynamic DHCP range on each interface. The DHCP server can hand out anything, but 10.0.50.3 on the eth0 wire will not be reachable.

Solution 3:

You cannot use the same IP address on multiple interfaces. It just won't work properly (usually it will only work on the last interface the IP was assigned on).

You need to put the ethernet interfaces into a bridge and assign the IP address on the bridge itself.

Essentially all ethernet ports in that bridge will work as a Switch.

Alternatively you can remove all ethernet cards for each STB and simply add a switch (which is more scalable than adding new ethernet cards on your server).

But since there is a requirement for each STB to be on its own broadcast domain then I am afraid you need to stick to your current setup.

Or to simplify at least the server hardware part of your setup, ditch the multiple ethernet cards and simply add a managed switch and use VLANs to simulate the 'multiple ethernet cards' using only one physical ethernet card.