How to access the same IP using different network interfaces
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.
linux networking ip tcp
migrated from serverfault.com Mar 22 '17 at 7:07
This question came from our site for system and network administrators.
add a comment |
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.
linux networking ip tcp
migrated from serverfault.com Mar 22 '17 at 7:07
This question came from our site for system and network administrators.
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
1
That sounds really broken. I'd use iptables withSNAT
(incoming) andDNAT
(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
add a comment |
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.
linux networking ip tcp
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.
linux networking ip tcp
linux networking ip tcp
asked Mar 22 '17 at 7:03
hsz
1063
1063
migrated from serverfault.com Mar 22 '17 at 7:07
This question came from our site for system and network administrators.
migrated from serverfault.com Mar 22 '17 at 7:07
This question came from our site for system and network administrators.
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
1
That sounds really broken. I'd use iptables withSNAT
(incoming) andDNAT
(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
add a comment |
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
1
That sounds really broken. I'd use iptables withSNAT
(incoming) andDNAT
(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
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
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
@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
1
1
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
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f352997%2fhow-to-access-the-same-ip-using-different-network-interfaces%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
edited Apr 13 '17 at 12:13
Community♦
1
1
answered Mar 22 '17 at 7:18
Ed Neville
1,13957
1,13957
add a comment |
add a comment |
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.
New contributor
add a comment |
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.
New contributor
add a comment |
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.
New contributor
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.
New contributor
New contributor
answered 4 mins ago
Steve Ritacco
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f352997%2fhow-to-access-the-same-ip-using-different-network-interfaces%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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
1
That sounds really broken. I'd use iptables with
SNAT
(incoming) andDNAT
(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