1

I have a small usb-over-ethernet network of RPiZs connected to a single RPi4. I am accessing the zeros through an ethernet connection on the RPi4, so they need to send packets going to my laptop through the RPi4.

I created a hook at /lib/dhcpcd/dhcpcd-hooks/40-route which is run by /lib/dhcpcd/dhcpcd-run-hooks.

It looks like this

# /lib/dhcpcd/dhcpcd-hooks/40-route                                             
ip route replace 10.0/16 dev usb0
ip route replace 169.254/16 dev usb0 via 10.0.11.1 metric 101

If I run sudo sh /lib/dhcpcd/dhcpcd-run-hooks, it makes the appropriate changes to my ip table.

However, I have to run it manually after every start up. Is there a way to get the hooks to run automatically? Or am I going about this completely wrong.

I feel this is on-topic for RPi SE because there is no other distribution that uses dhcpcd as its default network manager.

7
  • 1
    this is a Linux question, not a Raspberry Pi question ... it belongs at unix.stackexchange.com/questions
    – jsotola
    Commented Aug 6, 2022 at 17:44
  • 1
    Unfortunately, your question has been closed to new answers. I've submitted a request that it be re-opened, but that's probably a long-shot. Before I invest more time, can you tell me if you've read this?
    – Seamus
    Commented Aug 8, 2022 at 4:47
  • 1
    I've re-opened this, but you might want to demonstrate more definitely that it does not run, eg., by shimming in something like date >> /tmp/run-hook.log; echo $reason >> /tmp/run-hook.log. Note that if it is running, it is probably executed a bunch of times in close succession, since you don't appear to have checked the context via the environment at all.
    – goldilocks
    Commented Aug 8, 2022 at 14:38
  • The meatier bits of /etc/dhcpcd.conf might be useful too.
    – goldilocks
    Commented Aug 8, 2022 at 14:41
  • @goldilocks thank you for the advice. Unfortunately, I got pulled away from this project and only just managed to do some investigating. You are right, it runs a bunch of times when the dhcpcd service gets restarted. I printed the $reason, $interface, and ip route before and after the changes. I found that the ip table changes remains stable with my changes in every round except the second to last where no reason or interface is listed, but in the next/final run the ip table starts missing my changes. Last round is IPV4LL for usb0. Then the changes are gone once it is started.
    – Rusty
    Commented Jan 24, 2023 at 22:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.