welw | About_me Blog WebAssembly

I can ssh to my 192.168.10.100 machine, which is a router for 172.30.x.x/12 subnet. I added route in freebsd. I would like to confirm that the bsd box indeed routes 172.30.x.x via 192.168.10.100 and then setup appropriate routing rules on pi (192.168.10.100 / 172.30.0.2).

Sure, let's confirm the route on your FreeBSD box and then set up the appropriate routing rules on your Raspberry Pi (acting as the router).

Confirm Route on FreeBSD

  1. Check the routing table:

    • Use the following command to see the current routing table:

      sh netstat -rnf inet

    • Look for an entry like:

      172.30.0.0/12 192.168.10.100 UGS 0 24 vtnet0

Set Up Routing Rules on Raspberry Pi (Router)

Since your Raspberry Pi is acting as a router for the 172.30.x.x/12 subnet, you need to ensure it has the correct routing to forward traffic from the FreeBSD box (192.168.10.xx) to the 172.30.x.x/12 subnet.

  1. Ensure IP forwarding is enabled:

    • Check if IP forwarding is enabled:

      sh sysctl net.ipv4.ip_forward

    • If it returns 0, enable it by running:

      sh sudo sysctl -w net.ipv4.ip_forward=1

    • To make the change persistent, edit /etc/sysctl.conf and add or uncomment:

      sh net.ipv4.ip_forward=1

  2. Set up NAT for outgoing traffic:

    • If the FreeBSD box needs to access the internet through your Raspberry Pi, set up NAT masquerading: sh sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    • Replace eth0 with the appropriate interface for your Raspberry Pi's internet connection.
  3. Add a static route for traffic from FreeBSD to 172.30.x.x/12:

    • Add the route on the Raspberry Pi: sh sudo route add -net 172.30.0.0 netmask 255.240.0.0 gw 192.168.10.100
  4. Verify the routing table on Raspberry Pi:

    • Use the following command to check the routing table: sh netstat -rn
    • Look for an entry like: 172.30.0.0 * 255.240.0.0 UG 0 0 eth0
  5. Make routes persistent (optional):

    • To make the route persistent across reboots, add it to /etc/network/interfaces or /etc/rc.local:
      • Edit /etc/network/interfaces: sh post-up route add -net 172.30.0.0 netmask 255.240.0.0 gw 192.168.10.100
      • Or, edit /etc/rc.local (if it exists): sh route add -net 172.30.0.0 netmask 255.240.0.0 gw 192.168.10.100
  6. Check firewall rules (if applicable):

    • Ensure that the Raspberry Pi's firewall rules allow traffic to flow between the 192.168.10.x and 172.30.x.x subnets.

By following these steps, you should be able to verify and set up the routing correctly on both your FreeBSD box and the Raspberry Pi.