DHCP means "dynamic" - coping with address re-assignment
Hi everyone: I was happily SSH'ing into my home-PC, well aware that the first part of DHCP means "dynamic"... For quite a long time, my IP-address stayed the same, then yesterday, I couldn't get into my machine (from work). That prompted some thinking (always dangerous :-) ). I thought I'd share what I did, and hope that it may help someone else, or stimulate an even better solution. In a nutshell, I have my home-SuSE machine check the IP-address every hour. If it sees a change, then it mails me the new IP-address (to my work-email). (Note: I read the man-page for dhcpcd, and it looks like there is a facility to run a script only when the DHCP-client status changes. This may be a better way to do things, rather than my cron approach. Nonetheless, my parsing and notification may still be useful, even if the trigger-event is different). Without further ado, here is the bash-script: #!/bin/bash # ip_check.sh # Written by Gordon Pritchard. Feb. 12, 2002. # The purpose of this script it to check (via cron) if my DHCP # assigned IP-address has changed. If not, do nothing. If yes, # mail me the new IP-address. # Place this file in /etc/cron.hourly (SuSE system), and set the # owner/group to 'root'. Make sure it's executable. # First, we'll get the current IP-address /sbin/ifconfig eth0 | awk '/inet / {print $2}' > latest_ip # See if our latest IP-address is the same as the previously # assigned IP-address. This works fine the first time this # script is run, and previous_ip doesn't exist. if cmp -s latest_ip previous_ip then exit else cp latest_ip previous_ip mail -s "IP address change!" username@domain < latest_ip fi # You've got mail :-) -Gord -- Gordon Pritchard, P.Eng., Member IEEE Technical University of B.C. - Research Lab Engineer mailto:gordon.pritchard@techbc.ca direct phone: 604-586-6186
* Gordon Pritchard;
I thought I'd share what I did, and hope that it may help someone else, or stimulate an even better solution.
Rather then reaching your home PC via its IP address why not reach via its name. this is hway there are services like www.dyndns.org There are evene third party programs that will update the ip to dyndns dns servers so you can always reache your machine via its name. I recall that there was even a package for a similar service in teh SuSE CD's -- Togan Muftuoglu Unofficial SuSE FAQ Maintainer http://dinamizm.ath.cx
On Wed, 2002-02-13 at 09:51, Togan Muftuoglu wrote:
Rather then reaching your home PC via its IP address why not reach via its name.
Don't I have to register a name, and pay $$$? I don't have a name, and I'm cheap :-)
there are services like www.dyndns.org
Yes, I was aware of these guys. A nice answer if I wanted a *publicly* available machine. Or, if I had a registered name.
I recall that there was even a package for a similar service in teh SuSE CD's
A package that did what? I'd be interested if you had a package-name, so that I could read about it... Thanks, -Gord -- Gordon Pritchard, P.Eng., Member IEEE Technical University of B.C. - Research Lab Engineer mailto:gordon.pritchard@techbc.ca direct phone: 604-586-6186
* Gordon Pritchard;
On Wed, 2002-02-13 at 09:51, Togan Muftuoglu wrote:
Rather then reaching your home PC via its IP address why not reach via its name.
Don't I have to register a name, and pay $$$? I don't have a name, and I'm cheap :-)
no you do not pay $$$ it is free as beer. Why don't you check the page.
there are services like www.dyndns.org
Yes, I was aware of these guys. A nice answer if I wanted a *publicly* available machine. Or, if I had a registered name.
I recall that there was even a package for a similar service in teh SuSE CD's
A package that did what? I'd be interested if you had a package-name, so that I could read about it...
err. I should have been more clear with this one http://www.ddts.org/ it is ddt and ddt-client in suse CD's (CD2) -- Togan Muftuoglu Unofficial SuSE FAQ Maintainer http://dinamizm.ath.cx
Duh. 1. Turn on brain. 2. Read email. It helps if I do it in that order. We use DHCP at work and in many cases we used static addresses. I just assumed you had you had control over the IP addresses, or do you? regards, jimmo On Wednesday 13 February 2002 19:08, Gordon Pritchard wrote:
On Wed, 2002-02-13 at 09:51, Togan Muftuoglu wrote:
Rather then reaching your home PC via its IP address why not reach via its name.
Don't I have to register a name, and pay $$$? I don't have a name, and I'm cheap :-)
there are services like www.dyndns.org
Yes, I was aware of these guys. A nice answer if I wanted a *publicly* available machine. Or, if I had a registered name.
I recall that there was even a package for a similar service in teh SuSE CD's
A package that did what? I'd be interested if you had a package-name, so that I could read about it...
Thanks, -Gord
-- --------------------------------------- "Science has promised man power...But, as so often happens when people are seduced by promises of power, the price is servitude and impotence. Power is nothing if it is not the power to choose." Joseph Weizenbaum of MIT said in reference to Computers. --------------------------------------- The Great Linux-NT Debate: http://www.jimmo.com/Linux-NT_Debate/index.html --------------------------------------- NOTE: All messages sent to me in response to my posts to newsgroups or forums are subject to reposting.
Why don't you just set the lease time to some absurdly large value so you never have to worry about it ever changing? Regards, jimmo On Wednesday 13 February 2002 18:35, Gordon Pritchard wrote:
Hi everyone:
I was happily SSH'ing into my home-PC, well aware that the first part of DHCP means "dynamic"... For quite a long time, my IP-address stayed the same, then yesterday, I couldn't get into my machine (from work). That prompted some thinking (always dangerous :-) ).
I thought I'd share what I did, and hope that it may help someone else, or stimulate an even better solution.
In a nutshell, I have my home-SuSE machine check the IP-address every hour. If it sees a change, then it mails me the new IP-address (to my work-email).
(Note: I read the man-page for dhcpcd, and it looks like there is a facility to run a script only when the DHCP-client status changes. This may be a better way to do things, rather than my cron approach. Nonetheless, my parsing and notification may still be useful, even if the trigger-event is different).
Without further ado, here is the bash-script:
#!/bin/bash
# ip_check.sh # Written by Gordon Pritchard. Feb. 12, 2002.
# The purpose of this script it to check (via cron) if my DHCP # assigned IP-address has changed. If not, do nothing. If yes, # mail me the new IP-address.
# Place this file in /etc/cron.hourly (SuSE system), and set the # owner/group to 'root'. Make sure it's executable.
# First, we'll get the current IP-address
/sbin/ifconfig eth0 | awk '/inet / {print $2}' > latest_ip
# See if our latest IP-address is the same as the previously # assigned IP-address. This works fine the first time this # script is run, and previous_ip doesn't exist.
if cmp -s latest_ip previous_ip then exit else cp latest_ip previous_ip mail -s "IP address change!" username@domain < latest_ip fi
# You've got mail :-)
-Gord
-- --------------------------------------- "Science has promised man power...But, as so often happens when people are seduced by promises of power, the price is servitude and impotence. Power is nothing if it is not the power to choose." Joseph Weizenbaum of MIT said in reference to Computers. --------------------------------------- The Great Linux-NT Debate: http://www.jimmo.com/Linux-NT_Debate/index.html --------------------------------------- NOTE: All messages sent to me in response to my posts to newsgroups or forums are subject to reposting.
On Wed, 2002-02-13 at 11:54, James Mohr wrote:
Why don't you just set the lease time to some absurdly large value so you never have to worry about it ever changing?
I tried :-( I want to try intermediate settings, but for "large" values, my IPS re-defines the lease-time to 2 days :-( -Gord
participants (3)
-
Gordon Pritchard
-
James Mohr
-
Togan Muftuoglu