The Requirements
This solution aims to solve the problem of connecting pairs of hosts. Each IP address of hosts of the pair is different. All pairs share the same two IP addresses. The IPs of the pairs are:
172.30.21.50
172.30.21.60
The Use Case here is for a test and development system. Only average network speed is required. There is one connection to the rest of the network. The solution must be efficient in space, energy usage and cost.
The Cisco "Solution"
There are quite a few questions out there seeking solutions to a variety of problems with overlapping subnets. The more I learn, the less likely a pure and practical Cisco solution is achievable. The range of solutions offered by Cisco is very narrow.
A lot of the problems could be solved if the IP could be NATed at the switch ports. By definition L2 switches can't do that. L3 switches don't do that. That is the job of a router. If putting one Cisco router between 2 networks is a good idea, putting a Cisco router on every switch port to solve my problem is not.
The solution I propose is to implement switch port routers with Raspberry Pi's fitted with 2 USB to LAN adapters. They would be configured as routers with NAT enabled. One RasPi connected to 1 switch port can then route to a pair of servers.For my application (SSH and file transfers), a high performance network is not required, and Raspi's with USB/LAN adapters won't provide it. A Raspberry Pi uses less space, less power and costs less than a Cisco router. The concept is illustrated in the diagram. NATing the IP traffic with the routers should make the VLANs easy to setup.
If performance is required, then proper routers would be used, plus a rack to install them into. The Cisco 1841 router only has two ports, so I would need a router on each switch port. Double the number of Raspi's would be required.
The whole point of VLANs is to be able to create a virtual network in software. Having to double NAT IPs in hardware to work around programmed software constraints of the switch is not good.
I concluded that a Cisco based solution was too complex and required too many devices. It is a bad solution.
I decided that a layer based solution was the wrong approach. I started looking at an IP pipeline illustrated in the diagram below. The first router NATs the externally visible address pairs to another subnet specifically to separate the VLAN subnet ranges so they are acceptable to the switch. The VLAN then directs traffic to specific switch ports. The router then NATs the intermediate address to the actual address of the server.
The IPTables Solution
Having decided that a Cisco based solution won't meet the design requirements, I looked for alternatives. It didn't take long to find IP Tables. IPTables (almost) ignores layers. It is specifically designed to process IP pipelines.
The solution I came up with is as follows:
My network has a Linux IPtables based firewall/router.
This will be connected to a PC with a lot of PCI slots. MoBos made for bit coin mining are ideal candidates. Quad Gb NICs are now readily available. I will call this the switch host. It is relatively cheap and easy assemble a PC with 24 Gb LAN ports. A lot cheaper than a new Cisco device.
The IPtables process pipeline is illustrated below.
Step 1.
Write a IPtables rule on the firewall that sends a block of IP addresses to a specific port on the switch host.
172.30.21.50 to 99 > 172.30.21.100
The block is the IP addresses that map to the IP pairs.
The port 172.30.21.100 is connected to the switch host with many network cards (quad PCI 1Gb NICs) installed .
Step 2.
The IPtable rules on the switch host direct each IP address of the block to a specific LAN port.
Those same rules NAT the address to match one of the IP pairs
172.30.21.50 > NAT 172.30.21.50 > eth1
172.30.21.51 > NAT 172.30.21.60 > eth0
172.30.21.52 > NAT 172.30.21.50 > eth2
172.30.21.53 > NAT 172.30.21.60 > eth3
THE APPLIED SOLUTION
After going through a series of iterations, starting with a Cisco based approach, I ended up with the solution outlined below.
Rather than use IPTables, I used nft, its modern replacement, running on a single Linux box. The rules here don't allow scripts to be posted so I will describe what was done. There are several parts to the solution shown in the diagram.
PART A
I set up a filter so that only traffic within the IP range of the connected devices was allowed in.
PART B
nft is setup to direct specific IP addresses to specific ports. They act like VLANS but they are not, because all the IP addresses are in the same domain. The packets are DNATed to route them correctly. An packet from the network is sent to the correct port and the destination IP is changed to match the host.
PART C
Part C needs to differentiate between traffic to the neighbour of a pair of hosts, or out to the rest of the network.
Note there is no requirement for comms across different pairs of host. There is only a requirement for comms between the two hosts that make up a pair. The setup below will allow for comms between pairs of hosts.
nft is setup so that any traffic with a destination IP of it's neighbour is steered to the correct eth port and vice versa. For example, if a packet from host 172.30.21.50 (source) comes in from eth0, and has a destination IP of 172.30.21.60 (its neighbour), then nft sends it out through port eth1. No NATing is required.
If a packet comes in from the network with a destination IP of 172.30.22.010, then it is DNATed to 172.30.21.50 with the source untouched (ip xxx.xxx.xxx.xxx) and sent out eth0 port.
The reply to that packet coming back in eth0 port with have a dest IP of xxx.xxx.xxx.xxx, and a source of 172.30.21.50. This is SNATed to 172.30.22.010 and sent out to the network. The network thinks it is communicating with a host on IP 172.30.22.010.
Part C differentiates between external traffic and traffic between pairs. From outside, each host looks like it has its own IP address. Each host can communicate with its neighbour without knowing that there are multiple pairs of hosts with the same IP addresses. All of this is done with a single Linux box with one ethernet port per host.
Bitcoin Switch
This solution is limited by the number of available ports on the Linux box. The work around is to use machine designed for bit coin mining. These have many more pci-express connectors than a standard MoBo. Each connector can take a 4-way network card. It isn't hard to find a mobo with more than 15 pci-e interfaces. That makes a single Linux box with 60 or more ports a practical solution.
The throughput of a single Linux box based on a bit coin MoBo will not match a purpose build Cisco switch/router but it works for a lab test environment (my application). It is a low cost and efficient solution in terms of:
- energy consumption,
- space,
- single box solution,
- $$ cost.
It is a much better solution than Cisco can provide.