Two ethernet ports, same IP as device connected to other ethernet port
I have a small Device with two ethernet ports (NICs) running Ubuntu 16.04.
The first ethernetport has a static IP address (for example 10.0.0.2)
The second ethernetport has static IP address (for example 10.0.0.3) but is connected to a printer with the same IP address as the first ethernetport of my device (it has IP 10.0.0.2 in our example).
As expected, the printer cannot communicate because there is a duplicate IP address on the network. My Linux Device does not know whether to send information to its own NIC or two the printer.
My question is: Can I control the network communication based on the devicename? Or is there any other way to solve this without having to change the IP addresses of Port 1 or the Printer?
31 Answer
No. You will have to move the printer on the network if you don't want to make it unnecessarily complicated for yourself.
To do what you want - correctly put your 'small device' between the printer and the network - you should connect to the main network on NIC 1, and connect NIC 2 to the printer alone. The printer and NIC 2 should be on another IP range so that devices on the main network cannot connect directly to the printer. For example, with the printer connected only to NIC 2:
NIC 1: 10.0.0.3
NIC 2: 192.168.1.100
Printer: 192.168.1.101 (mask /24, gateway NIC 2's IP)
From there, you can have a program listen on NIC 1, modify the print job, then send it to the printer over NIC 2. Having NIC 2 on a different subnet has the added convenience of making the system automatically choose NIC 2 to connect to the printer.