View previous topic :: View next topic |
Author |
Message |
DavidCent n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 07 Feb 2007 Posts: 5
|
Posted: Wed Jun 06, 2007 2:28 pm Post subject: DHCPCD running own scripts with new ip |
|
|
Hi all,
Ive looked at the man pages, and it implies the script dhcpcd.sh is run after a new ip address is retrieved.
I want to run a scipt which publishes new ip tables rules, when dhcp retrieves a new ip address.
I have edited /lib/rcscripts/net/dhcpcd.sh, and added as a starting test, at the end of the dhcpcd_start() function, before the last return 0 line:
echo "----------------" >> /test.txt
echo /bin/date >> /test.txt
echo "Retrieved new ip : " >> /test.txt
echo IP Address is : $addr >> /test.txt
This seens to work, so i could insert a new script here, however i am sure this is the wrong place to do this.
Could someone confirm if there is something basic i have not yet managed to find where i should insert my own script calls for dhcpcd to call after getting a new ip?
(I will be running iptable updates to handle port forwarding from the new ip address).
This just seems very hacky, and likely an emerge will replace it?!?
Thanks in advance.. sorry if its a stupid question, but ive been search google for a good few hours, and this is about all i can find at the moment with the man pages.
Thanks again
David |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Errtu Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/87726397545488a650cfd4.gif)
Joined: 12 Nov 2002 Posts: 155 Location: Brazil
|
Posted: Wed Jun 06, 2007 2:51 pm Post subject: |
|
|
Maybe this will help you. I faced the same situation as you and came up with the following:
- design a script that does the replacing of ip in various places (firewall rules script etc)
- have your ip in /etc/hosts
- design another script that runs (via cron) every x minutes and compares your ip address from ifconfig (or `ip`) with the ip found in /etc/hosts , and act accordingly.
This is independent of any emerge updates, which is what i wanted. If anyone has a better idea, please respond. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
DavidCent n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 07 Feb 2007 Posts: 5
|
Posted: Wed Jun 06, 2007 3:27 pm Post subject: |
|
|
Hi my above attempt didnt work anyway. That appears to only run, on the inital startup of the dhcpcd client, not each time the dhcpcd gets a new ipaddress.
Any ideas, if you can hook into the dhcpcd after it gets a new ip address to run additional scripts. Anyone
Otherwise, could you please explain how you get the retrieved IP stored somewhere, so that i can use it?
I have found that i could get the ip from the auto-generated file:
/var/lib/dhcpcd/dhcpcd-eth0.info, but im not sure what commands i would use to extract just the <012>.<012>.<012>.<012> argument from the line IPADDR='<012>.<012>.<012>.<012>'.
Could someone help? Im sure its simple - i just need to learn the linux commands better
If necessary Ill go down the crontab route, i just dont like it as then its polling for changes rather than reacting to the odd occassion when they do?
Thanks again, it looks like i may yet do your crontab solution. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Stever Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
Joined: 01 Mar 2005 Posts: 151 Location: North Carolina
|
Posted: Wed Jun 06, 2007 3:44 pm Post subject: |
|
|
DavidCent wrote: | Hi my above attempt didnt work anyway. That appears to only run, on the inital startup of the dhcpcd client, not each time the dhcpcd gets a new ipaddress.
Any ideas, if you can hook into the dhcpcd after it gets a new ip address to run additional scripts. Anyone
|
You are editing the wrong dhcpcd.sh - you want to create one in /etc
From man dhcpcd:
Code: | /etc/dhcpcd.sh
script file, which dhcpcd will try to execute whenever it con-
figures or brings down the interface. The path to this exe-
cutable script can be changed with -c script option. dhcpcd
passes 3 parameters to dhcpcd.sh script:
dhcpcd.sh infofile [up | down | new]
The first parameter infofile is the path to a file containing
all DHCP information we have. The second parameter value up |
down | new mean the interface has been brought up with the same
IP address as before ("up"), or with the new IP address ("new"),
or the interface has been brought down ("down").
|
|
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
DavidCent n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
Joined: 07 Feb 2007 Posts: 5
|
Posted: Wed Jun 06, 2007 4:13 pm Post subject: |
|
|
Hi thanks, thats great. I still need to check it calls it with new ips but it looks like that will work thanks.
I had a few initial problems as i was not using strict bash commands. It now seems to call it at least which is great.
I will continue testing, and once i get a script that works, parcially at least i will try and post it.
For anyone else who has this problem, the files not there just create it and after much searching i found an example file on what to base your new file on, or start with at least. I have done chmod 777 and +x but i suspect 744 will do or less?!?
http://fresh.t-systems-sfr.com/linux/src/dhcpcd-3.0.11.tar.gz:t/dhcpcd-3.0.11/dhcpcd.sh
Thanks for all the help. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|