3

I have three wlan interfaces attached in my RaspberryPi:

  • wlan0
  • wlan1
  • wlan2

Each of them is connected to the different SSID:

  • gopro-0
  • gopro-1
  • gopro-2

GoPro cameras are set as a WiFi router, have always the same IP address: 10.5.5.9.

With this configuration if I call:

curl http://10.5.5.9

then first wlan0 interface will be used (simplified assumption). If I'd like to call the camera gopro-2, I hve to invoke:

curl http://10.5.5.9 --interface wlan2

It works. However there is a problem that not all commands allows me to specify the interface (i.e. ffmpeg - or I don't know about it).

Is it possible to somehow trick Linux and delegate some IP address to be forwarded to 10.5.5.9 on specific interface?

For example:

10.5.4.100 -> 10.5.5.9 @ wlan0
10.5.4.101 -> 10.5.5.9 @ wlan1
10.5.4.102 -> 10.5.5.9 @ wlan2

I would appreciate any solution or even other approach that will let me call the same IP on different interface using regular HTTP GET/POST methods.

5
  • 1
    The clean solution is obviously to assign different IP addresses to the gopro's. Why is this not possible?
    – dirkt
    Mar 22, 2017 at 7:29
  • @dirkt Each GoPro camera - if works as a hotspot - creates wlan network with SSID that I can specify, but their IP addresses are always fixed: 10.5.5.9 - there is no possibility to change it.
    – hsz
    Mar 22, 2017 at 8:04
  • 2
    That sounds really broken. I'd use iptables with SNAT (incoming) and DNAT (outgoing) targets to map IPs depending on the interface, as you suggested. Make sure the routing tables match. I can't write rules for you because I can't test them without the hardware setup.
    – dirkt
    Mar 22, 2017 at 10:40
  • 1
    See also: cam-do.com/pages/ip-address-changer Aug 4, 2020 at 15:04
  • 1
    @MikkoRantalainen that seems to be the best solution: fix the brokenness so that the workaround I've no longer necessary Dec 22, 2023 at 10:36

3 Answers 3

4

I had this same issue for a different type of device and figured out a way to do it. You need a combination of iptables mangle and ip route

Give each interface a unique IP(192.168.44.8 below) on the same subnet as the device. In this example the virtual IP for the first device is 192.168.44.9

My physical devices were all at 192.168.44.1 on 4 different interfaces and with this pattern and the virtual IPs I could reliably communicate with all of them.

iptables -t mangle -A PREROUTING -d 192.168.44.9 -j MARK --set-mark 0x01

iptables -t nat -A PREROUTING -m mark --mark 0x01 -d 192.168.44.9 -j DNAT --to-destination 192.168.44.1

iptables -t nat -A POSTROUTING -m mark --mark 0x01 --destination 192.168.44.1 -j SNAT --to-source 192.168.44.8

With this in place, now add the following routes.

ip route add 192.168.44.0/24 dev eth4 table 1
ip rule add from all fwmark 1 table 1
ip route flush cache

You can repeat this pattern any number of times, just keep increment the mark and the addresses for how ever many interfaces you have.

Hopefully this will be useful to others dealing with duplicate addresses on different network interfaces.

2
  • These commands don't seem to work. I would expect to be able to do ping 192.168.44.9 and end up hitting 192.168.44.1. Is there a step missing? Do you have to create a VLAN or something that is set to 192.168.1.9? Feb 14, 2021 at 23:51
  • This was very helpful! Now how would be the setup to achieve the opposite operation? I mean redirecting packets from: * wlan0 -> 10.5.4.100 * wlan1 -> 10.5.4.101 * wlan2 -> 10.5.4.102
    – Eric
    Dec 22, 2023 at 0:05
0

I think the way is to use iptables, and set routes for that. Here is a similar answer for the question that you asked:

https://serverfault.com/questions/345111/iptables-target-to-route-packet-to-specific-interface

This is a bit less complex in OpenBSD/pf.

0

The very same problem was described on this thread: https://forum.developer.parrot.com/t/multiple-parrot-anafi-controlled-via-olympe-on-linux-configure-ip/9590/2

It gives a complete solution, that indeed uses both iptables rules and routing

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .