Routing tables and ip forwarding between two machines

Posted on

Problem :

Hi my current network is like that

[Raspberry]--eth0--------p3p1-[Laptop]-wlp3s0------[Router]-------INTERNET
eth0 = 10.10.10.1
p3p1 = 10.10.10.2
wlp3s0 = 192.168.2.11
Router = 192.168.2.1

I would like to give access to the Internet to Raspberry.
I turned on port forwarding on Laptop

[kamil@laura ~]$ cat /proc/sys/net/ipv4/ip_forward 
1

I checked route table on Raspberry

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.10.10.1      0.0.0.0         UG    0      0        0 eth0
10.10.10.0      *               255.255.255.0   U     0      0        0 eth0

I set up route on my Laptop:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         router          0.0.0.0         UG    0      0        0 wlp3s0
10.10.10.0      0.0.0.0         255.255.255.0   U     1      0        0 p3p1
192.168.2.0     0.0.0.0         255.255.255.0   U     9      0        0 wlp3s0

But my Raspberry cant ping router ip address, it waits all the time.
What am I missing, please help!

IPTables are turned off on both machines.

Solution :

Try this:

  1. Change the IP address on the p3p1 interface of your laptop to 10.10.10.1.

  2. Enable IP forwarding (not port forwarding) on your laptop. If it’s Linux, use:
    sysctl -w net.ipv4.ip_forward=1

  3. Add a route to your router: 10.10.10.0 255.255.255.0 next-hop: 192.168.2.11

You may have to mess with NAT on the router, to NAT for 10.x.x.x addresses. That would depend on the brand of router.

There are a lot of reasons why this won’t work. Here are two:

  1. The router has no idea that it’s supposed to NAT for machines with 10.x addresses. It believes its clients have 192.168.x addresses.

  2. The router has no idea that packets (even locally generated ones) bound for 10.10.10.2 should be sent to the laptop. Yet there is no other IP address it can use as a destination to get packets to the pi. Thus the router cannot reach the pi. At all. By any means. Period.

You need to start out by designing the way this will all work and then implement that. It won’t just happen by itself. Implementing NAT on the laptop would probably be the easiest way.

Leave a Reply

Your email address will not be published. Required fields are marked *