I have the following setup:

   Device A     <------->   device B   <------->   Device C
(           (          (

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

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 and gateway

Device C received an ip from the DHCP server (subnet and gateway

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 -d -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -s -d -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 Answer 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 via

On C:

ip route add via
  • 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, 2018 at 14:18
  • The DHCP response could assign 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 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
    – wurtel
    Jun 13, 2018 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, 2018 at 21:49
  • In fact, the current setup has the gateway of A set to and the gateway of C set to 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, 2018 at 7:36
  • 1
    OK, I solved it by setting /proc/sys/net/ipv4/ip_forward to 1. I did check that net.ipv4.ip_forward=1 in /etc/sysctl.conf was ok. Furthermore I should add that I also added the default gateway to the DHCP server and I was able to set the default gateway on device A. Thanks!
    – Steven
    Jun 14, 2018 at 13:09

You must log in to answer this question.

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