I have a home router with an Internet connection. I also have a computer which is in a place where I cannot connect it directly to the router. Hopefully, I have two raspberry pis that I didn't know what to do with.
I'd like to achieve these results:
The IP of my computer cannot be changed as it is used by other devices on the router network.
So far, I've been able to do the following communications (IPs have been set with ifconfig):
| Command | Pi #1 | Pi #2 | Computer | Any device on HomeRouter |
|---|---|---|---|---|
| ping 192.168.0.1 | OK | OK | OK | NOPE (Subnet is different) |
| ping 192.168.0.2 | OK | OK | OK | NOPE (Subnet is different) |
| ping 192.168.1.1 | OK | OK | OK | OK |
| ping 192.168.2.1 | OK | OK | OK | NOPE (Subnet is different) |
| ping 192.168.1.100 | OK | OK | OK | OK |
| ping 192.168.2.100 | OK | OK | OK | NOPE (Subnet is different) |
| ping 192.168.1.102 | OK | OK | OK | NOPE |
| curl 8.8.8.8 | OK | OK | OK | OK |
| curl google.com | OK | OK | OK | OK |
The following command lines have been executed on both PI:
# Enable IP forwarding echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf echo 'net.ipv6.conf.all.forwarding=1' >> /etc/sysctl.conf sysctl -p /etc/sysctl.conf # Masquerade outgoing packets iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE # Add DNS echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf - On PI #1, I've added the following route:
# Set static IP for both interfaces ifconfig eth0 192.168.1.100 netmask 255.255.255.0 ifconfig ppp0 192.168.0.1 netmask 255.255.255.0 # Add routes ip route add 192.168.2.0/24 via 192.168.0.2 dev ppp0 # Route packets to Pi #2 - On PI #2, I've added the following route:
# Set static IP for both interfaces ifconfig eth0 192.168.2.1 netmask 255.255.255.0 ifconfig ppp0 192.168.0.2 netmask 255.255.255.0 # Add routes ip route add default via 192.168.0.1 ip route add 192.168.1.0/24 via 192.168.0.1 dev ppp0 # Route packets to Pi #1 - On my computer:
# Set static IP ifconfig eth0 192.168.2.100 netmask 255.255.255.0 # Add routes ip route add default via 192.168.2.1 # Add DNS echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf I've tried to add a second IP on the eth0 interface of the first PI. The plan is to redirect all packets coming to 192.168.1.102 to 192.168.2.100.
# Add a new IP to PI #1's eth0 ip addr add 192.168.1.102 dev eth0 # Masquerade IP iptables -t nat -A PREROUTING -i eth0 -s 192.168.1.102 -j DNAT --to-destination 192.168.2.100 iptables -t nat -A POSTROUTING -o ppp0 -s 192.168.2.100 -j SNAT --to-source 192.168.1.102 Would that work ?

192.168.1.0/24on either side of192.168.0.0/24... you shouldn't need iptables, just enable routing on both pi's and make static routes for each endpoint on all devices.ip routesI need to set ? Would it be easier if PI #2 eth0 was a DHCP server ?