Why are post-up commands in /etc/network/interfaces ran multiple times at boot?
Files in /etc/network/if-up.d
already run automatically whenever an interface (any interface) comes up. When you specify the same script to run again in an explicit post-up
command, you only cause the script to run again. So my guess is this is what should happen:
- It runs once when
lo
comes up (with environment variableIFACE=lo
) due to being located in/etc/network/if-up.d
. - It runs once when
eth0
comes up (with environment variableIFACE=eth0
) for the same reason. - It runs again when
eth0
comes up (with environment variableIFACE
unset) because you asked for this in apost-up
directive.
I'm not sure where the fourth time comes from, but anyway that's three already.
You need to either locate the script somewhere else and run it once using a post-up
directive, or leave it where it is but don't mention it in a post-up
directive and check the value of $IFACE
so that it does nothing unless the desired interface (eth0
) has come up.
As stated by Celada, /etc/network/if-up.d
scripts are run for each interface. To avoid rule duplication simply add:
[ "$IFACE" = "eth0" ] || exit 0
at the top of your script. This will cause the script to exit immediately if the interface is not the desired one.