PlugPBX Forums
May 22, 2012, 12:49:16 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Email yourself your DHCP address on boot  (Read 699 times)
mattmc97
Administrator
Full Member
*****
Posts: 144


« on: July 07, 2010, 02:49:46 PM »

I am working on some development on the plug and got tired of having to look up my router page for my DHCP address. Since I am working with two different networks (home & work) I don't want to give it a static address.

So my trick is for the plug to email me it's ip address upon boot completion.

vi /usr/src/ip.sh  or nano  /usr/src/ip.sh   (I named it ip.sh, you can name it anything you like and put it somewhere else as well)

Code:

#!/bin/sh
#  Parts copied from Copyright (c) 2010 Sean A.O. Harney
# This script is licensed under GNU GPL version 2.0 or above

email_addr="you@youraddress.com";
subj="PlugPBX_DHCP_Address";   

# If you put spaces in the subject, you have to escape them
# or it will print first word only


ifconfig eth0 | \
grep 'inet addr:' | \
awk '{ split($2, ar, ":") ; print ar[2] }'| mail -s $subj $email_addr


exit 0 ;


Paste the code into the window, save it, and close.

chmod 755 /path/to/filename.sh

type '/path/to/filename.sh' to check and make sure it is working.(without the ' marks)

vi /etc/rc.local

go to a line  BEFORE exit 0

type /path/to/filename.sh

save & exit.

on each reboot, you will get an email with your ip address.

Logged
PlugPBX Admin
Administrator
Sr. Member
*****
Posts: 426



« Reply #1 on: July 07, 2010, 05:52:12 PM »

I think you have to set the hostname in the dhcp configuration options on the box, far easier Wink

Look at /etc/dhcp3/dhclient.conf

Quote
PlugPBX:/etc/dhcp3# cat dhclient.conf
# Configuration file for /sbin/dhclient, which is included in Debian's
#   dhcp3-client package.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
#   man page for more information about the syntax of this file
#   and a more comprehensive list of the parameters understood by
#   dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
#   not leave anything out (like the domain name, for example), then
#   few changes must be made to this file, if any.
#

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name "PlugPBX";
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
#prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
   domain-name, domain-name-servers, domain-search, host-name,
   netbios-name-servers, netbios-scope, interface-mtu,
   rfc3442-classless-static-routes, ntp-servers;
#require subnet-mask, domain-name-servers;
#timeout 60;
#retry 60;
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/etc/dhcp3/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;

#alias {
#  interface "eth0";
#  fixed-address 192.5.5.213;
#  option subnet-mask 255.255.255.255;
#}

#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andare.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}
« Last Edit: July 07, 2010, 06:18:50 PM by PlugPBX Admin » Logged

-Greg
mattmc97
Administrator
Full Member
*****
Posts: 144


« Reply #2 on: July 07, 2010, 06:50:15 PM »

Yes, that is the file.  I figured that out this afternoon as well. I know that there was at least one other person that was looking for an IP address and their PC wasn't pulling it up by hostname.

I may be fixing a problem that does not exist, but it seems like my PC will lose the hostname sometimes and I get redirected to OpenDNS.

I will still probably leave this enabled as it only send one email on reboot and I usually address everything by IP anyway. Old habit I guess.

I know that I reference by IP then I don't have to worry as much about DNS failures as well.
« Last Edit: July 07, 2010, 08:22:55 PM by mattmc97 » Logged
PlugPBX Admin
Administrator
Sr. Member
*****
Posts: 426



« Reply #3 on: July 08, 2010, 04:37:38 AM »

If you have itunes installed on your pc, you can also find it anytime via

PlugPBX.local

That name is broadcast via ZeroConf (much more reliable way of finding PlugPBX).

Not only do I broadcast that, but I also publish the HTTP GUI and the SSH services via ZeroConf to any clients that will present those as 'available' services. Macs do this natively as an example.

You can also install "bonjour" from apples website, with is a full featured ZeroConf client for Windows. Microsoft does not want to embrace the zeroconf standard, but any other OS does now too. You still likely don't have to rely on the email stuff, with either of these options in place.

I ship PlugPBX with both setup for easy of device discovery no matter what the network and clients.

Logged

-Greg
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Install SimpleMachinesForum web hosting Valid XHTML 1.0! Valid CSS!