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.

  • The clean solution is obviously to assign different IP addresses to the gopro's. Why is this not possible? – dirkt Mar 22 '17 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 '17 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 '17 at 10:40
3

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.

| improve this answer | |
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.

| improve this answer | |

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.