12

Are all scripts in /etc/network/if-up.d run when a network interface is brought up?

If so, what is the post-up command for in the interfaces file?

  • 1
    All ".d" folders contents, conventionally, is executed. Some of them actually need ".sh" filename extension. All of the files should be executable. – kolypto Nov 6 '09 at 15:36
14

Yes generally any script that is marked as executable and placed in that folder is ran. The files do have are limited to a specific set of names because run-parts is used.

The post-up does the same thing as using up. Placing a script in the if-up.d is the same as simply using a post-up that points to a script or command somewhere else. Usually you would use the up|post-up when you just needed to run a single command for a single interface. When you have something more complex you would create a script.

man interfaces

...
up command

post-up command
      Run  command  after  bringing the interface up.  If this command
      fails then ifup aborts, refraining from marking the interface as
      configured  (even  though it has really been configured), prints
      an error message, and exits with status 0.   This  behavior  may
      change in the future.
...
There  exists  for  each  of  the  above  mentioned options a directory
/etc/network/if-<option>.d/ the scripts in which are run (with no argu-
ments) using run-parts(8) after the option itself has been processed.

man run-parts

run-parts  runs  all  the  executable  files  named  within constraints
described below,

If  the  --lsbsysinit  option  is not given then the names must consist
entirely of upper and lower  case  letters,  digits,  underscores,  and
hyphens.
...
Files are run in the lexical sort  order  of  their  names  unless  the
--reverse  option  is given, in which case they are run in the opposite
order.
  • 1
    So if you want a script being run only after the interface is up and it needs stuff in the if-up.d folder to be ready, you either have to name it so it will fall in lexical order after the command you need to operate, or put into another directory and run via the post-up command. Does that sound right? – Spig Nov 4 '09 at 22:17
  • 1
    Yes, I believe so. – Zoredache Nov 4 '09 at 22:22
  • 1
    Such a nice detailed answer. Even 10 years later, still providing insight. – Xofo May 9 at 22:57
  • You really have to read the run-parts man page thoroughly in order recognize, that even scripts with an otherwise correct filename using the .sh extension will not run. Quote: "...it would help a lot if there was any information about skipping a script because of a dot. I lost plenty of time troubleshooting... the statement '... the names must consist entirely of upper and lower case letters, digits, underscores, and hyphens.' isn't enough. I read it twice and it didn't help me understand where my issue is. It should be explicitly written that scripts with dots are skipped." – ChrisW Aug 25 at 11:14
  • This 'bug' is "Won't Fix" in Debian: run-parts doesn't run script with sh extension bugs.launchpad.net/ubuntu/+source/debianutils/+bug/38022 – ChrisW Aug 25 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.