Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> Server On A Non-static Ip
Jim
post May 6 2004, 11:59 AM
Post #1


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,280
Joined: 19-November 03
From: University of Minnesota- TC
Member No.: 1,828



So I don't have a tip or trick on how to do this, but I want someone to help me make one.

So I want to be able to host a ssh/apache server from my home, which has a semi-static IP address. It doesn't really change all that often, but they reserve the right to so it does every now and than. So this won't be such a big deal this summer as I will be able to have the computer infront of me if the IP changes. Whats going to screw me is when I am away from school.

So the question is any ideas on how to deal with a semi-static IP? My thought was having some sort of auto-scheduled task to e-mail me the IP when it reboots. Because it wont get new IP unless I do a network restart or a reboot on it. Than I could always have the IP. I don't even know if thats possible and or how I would do that.

Getting a staic IP isn't a financial option or even possible since they don't offer them where I am at and on home services. So how do you host a server on a semi-static IP address?


--------------------
--Jim Lester
jim@linuxhelp.net

Distro: Gentoo
System: AMD Athlon 3000+ XP 2.166 GHz
NVIDIA nForce2 IGP Chipset
1GB 333 MHz DDR SDRAM
NVIDIA nForce2 Dual Head 64 MB Graphics

Server Distro: CentOS
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
hughesjr
post May 26 2004, 06:05 AM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



Well .... with some prodding from termina smile.gif .... here is my update script (actually, two scripts):

The first script is called check_ip and I call it every 15 minutes ... it checks my IP address on eth0 (my external NIC on my Linux firewall) and then does a name lookup at the zoneedit site. If the IPs match, it does nothing ... if they don't, it updates the website with the text browser lynx.

If I can't get a name lookup at all ... (that is, $DOMAIN_IP is blank) then I restart my network and restart my firewall ... my ISP requires my cable modem to download it's configuration file at a certian interval ... and after it downloads, I can't talk to the internet until I do another DHCP request ... so this part of the script does that for me).

check_ip
CODE
#!/bin/bash

###############################
#Full Path to executables
#use the command "which ifconfig", etc. to find the info on your system ...
#this is correct for most RedHat distros

IFCONFIG=/sbin/ifconfig
AWK=/bin/awk
GREP=/bin/grep
DIG=/usr/bin/dig
LYNX=/usr/bin/lynx
ECHO=/bin/echo
###############################

###############################
#External Interface (if on this machine)

EXTIF="eth0"
###############################

###############################
#Domain name to Monitor (you only need 1 for all domains in this IP)

DOMAIN_NAME="www.hughesjr.com"
###############################

###############################
#Primary DNS listed

PRIMARY_DNS="ns5.zoneedit.com"
###############################

###############################
#Domains to update (enter all domains with a space between them)
#Example DOMAINS_TO_UPDATE="domain1.com www.domain1.com ftp.domain1.com domain2.org"

DOMAINS_TO_UPDATE="hughesjr.com www.hughesjr.com mail.hughesjr.com"
###############################

###############################
#ZoneEdit username and password
USERNAME="your_username_here"
PASSWORD="your_zoneedit_password_here"
###############################

###############################
#Get the External IP address
#
# If the machine you are running this script on is your firewall,
# use the IFCONFIG line to find your external IP address.  If you have
# an external firewall, comment out the IFCONFIG EXTIP line (with a #)
# and use the LYNX (remove the #) instead.
#
EXTIP="`$IFCONFIG $EXTIF | $AWK /$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"
#EXTIP="`$LYNX -source http://www.whatismyip.com/ | $GREP 'TITLE' | $AWK '{split($0,a,"is");split(a[2],a," ");print a[1];exit}'`"
###############################

#####---------------------------------------------######
#####----------------SCRIPT BEGINS----------------######
#####-No changes normally needed below this point-######
#####---------------------------------------------######

#Date for Logs
DATE="`date +'%x %X %Z - '`"


#Get the Domain Name's IP Address
DOMAIN_IP="`$DIG @$PRIMARY_DNS $DOMAIN_NAME | grep $DOMAIN_NAME | grep -v DiG | grep -v ";"$DOMAIN_NAME | awk '{print $5}'`"

###############################
#If there is an error, log it and exit the script
#otherwise, continue with the updates

if [ "$DOMAIN_IP"x == x ]; then
 $ECHO $DATE"Error doing lookup!" >> /var/log/check_ip.log
 /etc/init.d/network restart
 /etc/rc.d/rc.firewall
 exit 1
else
 ###################
 #This is for testing, or a more verbose output to the screen
 #$ECHO "External IP: "$EXTIP
 #$ECHO "Monitored IP: "$DOMAIN_IP
 #$ECHO "Domains to update: "$DOMAINS_TO_UPDATE
 ###################

 #Actual update is required ... update domains and log it
 if [ "$EXTIP" == "$DOMAIN_IP" ]; then
   #$ECHO $DATE"External IP("$EXTIP") matches Domain IP("$DOMAIN_IP"). No Action required."
   exit 0
 else

   for DOMAIN in $DOMAINS_TO_UPDATE

   do
     $ECHO $DATE"Updating "$DOMAIN" from "$DOMAIN_IP" to "$EXTIP >> /var/log/check_ip.log
     COMMAND="$LYNX -source -auth=$USERNAME:$PASSWORD http://dynamic.zoneedit.com/auth/dynamic.html?host=$DOMAIN"
     $COMMAND
   done
 fi
fi


The other script is one that I run once a month (it is called monthly_update_ip. Even if your IP hasn't changed, if it isn't updated at least once a month then zoneedit will close your account (because they figure you have lost interest in maintaining your site). SO this script is basically the same as the other script ... but it does the update even if the looked up IP is the same as the external IP.

monthly_update_ip
CODE
#!/bin/bash

###############################
#Full Path to executables
#use the command "which ifconfig", etc. to find the info on your system ...
#this is correct for most RedHat distros

IFCONFIG=/sbin/ifconfig
AWK=/bin/awk
GREP=/bin/grep
DIG=/usr/bin/dig
LYNX=/usr/bin/lynx
ECHO=/bin/echo
###############################

###############################
#External Interface (if on this machine)

EXTIF="eth0"
###############################

###############################
#Domain name to Monitor (you only need 1 for all domains in this IP)

DOMAIN_NAME="www.hughesjr.com"
###############################

###############################
#Primary DNS listed

PRIMARY_DNS="ns5.zoneedit.com"
###############################

###############################
#Domains to update (enter all domains with a space between them)
#Example DOMAINS_TO_UPDATE="domain1.com www.domain1.com ftp.domain1.com domain2.org"

DOMAINS_TO_UPDATE="hughesjr.com www.hughesjr.com mail.hughesjr.com"

###############################

###############################
#ZoneEdit username and password
USERNAME="your_username_here"
PASSWORD="your_zoneedit_password_here"
###############################

###############################
#Get the External IP address
#
# If the machine you are running this script on is your firewall,
# use the IFCONFIG line to find your external IP address.  If you have
# an external firewall, comment out the IFCONFIG EXTIP line (with a #)
# and use the LYNX (remove the #) instead.
#
EXTIP="`$IFCONFIG $EXTIF | $AWK /$EXTIF/'{next}//{split($0,a,":");split(a[2],a," ");print a[1];exit}'`"
#EXTIP="`$LYNX -source http://www.whatismyip.com/ | $GREP 'TITLE' | $AWK '{split($0,a,"is");split(a[2],a," ");print a[1];exit}'`"
###############################
#####---------------------------------------------######
#####----------------SCRIPT BEGINS----------------######
#####-No changes normally needed below this point-######
#####---------------------------------------------######

#Date for Logs
DATE="`date +'%x %X %Z - '`"

#Get the Domain Name's IP Address
DOMAIN_IP="`$DIG @$PRIMARY_DNS $DOMAIN_NAME | grep $DOMAIN_NAME | grep -v DiG | grep -v ";"$DOMAIN_NAME | awk '{print $5}'`"

###############################
#If there is an error, log it and exit the script
#otherwise, continue with the updates

if [ "$DOMAIN_IP"x == x ]; then
 $ECHO $DATE"Error doing lookup!" >> /var/log/check_ip.log
 exit 1
else
 ###################
 #This is for testing, or a more verbose output to the screen
 #$ECHO "External IP: "$EXTIP
 #$ECHO "Monitored IP: "$DOMAIN_IP
 #$ECHO "Domains to update: "$DOMAINS_TO_UPDATE
 ###################

 #Actual update is required ... update domains and log it
 for DOMAIN in $DOMAINS_TO_UPDATE
   do
     $ECHO $DATE"Updating "$DOMAIN" from "$DOMAIN_IP" to "$EXTIP >> /var/log/check_ip.log
     COMMAND="$LYNX -source -auth=$USERNAME:$PASSWORD http://dynamic.zoneedit.com/auth/dynamic.html?host=$DOMAIN"
     $COMMAND
   done
fi


If you have an external router ... you need to figure out how to get the external IP address from it. Most have a URL that you can use to do that.

There are 3 long lines in the code that might wrap ... they are both a single line ... here they are:

DOMAIN_IP="`$DIG @$PRIMARY_DNS $DOMAIN_NAME | grep $DOMAIN_NAME | grep -v DiG | grep -v ";"$DOMAIN_NAME | awk '{print $5}'`"

the EXTIP lines are also one line....

and
CODE
COMMAND="$LYNX -source -auth=$USERNAME:$PASSWORD http://dynamic.zoneedit.com/auth/dynamic.html?host=$DOMAIN"


########################EDITED##########################
OK ---- I edited the file and added a second option for EXTIP if you have an external router.....

This post has been edited by hughesjr: May 31 2004, 02:17 PM


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 23rd October 2017 - 07:31 PM