TurnKey Linux Virtual Appliance Library

Run a script when IP address changes

adrianmoya's picture

Guys, do you know any method to run a script when there is a system IP address change? I would like to know a good method for another TKLPatch I'm preparing. It could be usefull maybe if confconsole had some hooks on this event to plug in users script. 

Thanks for your support. I'll continue searching google ;)

Alon Swartz's picture

Depends what you want to do

I'm not exactly sure what you want to do, but here are some pointers that might help:

/etc/network/{if-down.d, if-post-down.d, if-pre-up.d, if-up.d}

If what you want is dhcp specific, you might be interested in /etc/udhcpc/* (but I'm not sure I would recommend this direction as you never know if a user, or TurnKey will change the dhcp client).

I hope the above helps.

Adrian Moya's picture

I've made some tests with the

I've made some tests with the script in if-up.d and if-pre-up.d but have no success. Can't find the official documentation for those to see what I'm doing wrong. That's why I asked. wait... I think I know what happened!!! It could be an 8th layer error... let me check! 

Guest's picture


How about constantly running a script in background to check for current ip address using ifconfig?


while [ 1 ]; do

ifconfig | grep "inet"

## process above output

sleep 5;

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)