0

I have the following setup:

                         (192.168.4.1)     
   Device A     <------->   device B   <------->   Device C
(192.168.5.84)           (192.168.5.1)          (192.168.4.5)

Device B actually has an wifi interface (wlan0 = 192.168.4.1) on which an dhcp server is running. Then there is an cables interface (eth0 = 192.168.5.1).

What I want to reach is that devices A and C can talk to each other. I have been reading how to get to this result and I have found that I should use routing to accomplish this. I have tried some things and I do not understand why it is not working.

Device A has an static ip (subnet 255.255.255.0 and gateway 192.168.5.1).

Device C received an ip from the DHCP server (subnet 255.255.255.0 and gateway 192.168.4.1).

What I have done:

On device B I have set enabled the ipforward in /etc/sysctl

Added routing:

iptables -A FORWARD -i eth0 -o wlan0 -s 192.168.5.0/24 -d 192.168.4.0/24 -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -s 192.168.4.0/24 -d 192.168.5.0/24 -j ACCEPT 

The thing is that both device A and C are accessible from device B, so this would indicate that it MUST be a routing issue. So my question is, how do I get to the situation where device B routes the traffic from A to C?


Update: What I failed to mention is that I want to accomplish this result by ONLY changing the settings of device B

1

No need to use iptables. If you have successfully enabled the ip forwarding (i.e. by setting /proc/sys/net/ipv4/ip_forward to 1), device B will do the job because both networks are directly connected to B. The thing you might missing are the correct routes on device A and C.
On A:

ip route add 192.168.4.0/24 via 192.168.5.1

On C:

ip route add 192.168.5.0/24 via 192.168.4.1
  • Ok yes, this worked! However this made me realize that I did not explain my question properly. The question I now have: how can I accomplish this with ONLY changing the settings of device B? (since C may change a lot and changing A is undesirable) – Steven Jun 13 '18 at 14:18
  • The DHCP response could assign 192.168.4.1 as the default gateway for device C, then you don't have to do anything on device C. You will have to arrange something similar for device A, or at least add a route to 192.168.4.0/24 via device B on the default gateway, if A's default gateway is not B; that gateway will send a redirect ICMP to A when A tries to reach 192.168.4.0/24. – wurtel Jun 13 '18 at 15:03
  • So both A and C should have their default gateway set to B. But hoe does B 'know' it has to route traffic between the two interfaces? I thought the routing rules are meant to accommodate that. If not, what do routing rules do? – Steven Jun 13 '18 at 21:49
  • In fact, the current setup has the gateway of A set to 192.168.5.1 and the gateway of C set to 192.168.4.1. From both A and C I can reach ..5.1 and ..4.1 however I cannot reach each other. What is my setup lacking...? – Steven Jun 14 '18 at 7:36
  • Post the output of ip route show from every station please. – Winnie Tigger Jun 14 '18 at 8:07

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.