I could use some help with this. I don't even know how to get started despite being familiar with iptables.

I have a gadget, with a static IP address This is what it is and I cannot change it. My laptop used to have just one NIC. I was able to connect to the public internet and this gadget (which does not need to access any other devices but my laptop) by just plugging it into my development network and giving my laptop NIC a secondary address and plugging the device to the same switch as my laptop. Not ideal but it worked.

Now I had to move to another development network, the IP range of which is .... (suspenseful music) .... And is in its DHCP range occupied by another device.

I have now obtained another network interface card (eth1) for my laptop and given it an IP address of

Basically what I need to do is some iptables magic to make it so that when I access for example, this traffic when exiting eth1 gets IP address for example and is passed to in eth1, and when the gadget responds and eth1 receives the response, it will be passed to my host laptop as if coming from

I probably need SNAT/DNAT rules here but how should I set them up?



That is not a task for iptables, network namespaces suit better the problem,

# Create network namespace gadget
ip netns add gadget

# Put device eth0 in gadget namespace
ip link set eth0 netns gadget

# Configure network in gadget namespace
# # Bring up ifaces
ip netns exec gadget ip link set lo up
ip netns exec gadget ip link set eth0 up

# # address on eth0 
ip netns exec gadget ip address add dev eth0

# Now gadget pinging should work...
ip netns exec gadget ping
  • Thanks, I had forgotten about namespaces completely. I used to use them all the time to do some weird Openstack routing, but it has been a while. – Hannu Apr 10 '17 at 8:29
  • Any idea how to connect a single relay process to both namespaces? (Python). Or should I just skip the whole thing and build a temporary solution with one program listening and feeding to an unix domain socket, and another listening in the default namespace and relaying the data forward? – Hannu Apr 10 '17 at 13:05
  • So you want to put the gadget on the development network via your laptop... – xae Apr 10 '17 at 13:32
  • Basically I need to connect to it to poll data, then convert the resulting data to a format acceptable by the app that needs to process the sensor data, and push it there. I have done this with other "gadgets" without the IP address clash. But as the "app" is on the public Internet, my relay needs to access both the gadget and internet. I will probably just build something quick and dirty with temp files etc. until I can change the device IP address. – Hannu Apr 10 '17 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.