General Computing
linux networking forwarding routing
Updated Mon, 13 Jun 2022 02:47:00 GMT

Routing tables and ip forwarding between two machines


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.