LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-05-2007, 01:42 PM   #1
coldbeer
Member
 
Registered: May 2006
Location: Orion–Cygnus Arm, MWG
Distribution: Slackware, Ubuntu
Posts: 249

Rep: Reputation: 130Reputation: 130
Using Apache server with non-static IP address issue


I've got an apache server operating on my desktop. I don't use a static IP address as its just for experimenting. So I find out the IP assigned to my box and use it for the URL for testing (i.e. on another machine in the web browser's URL I use 'http://123.456.7.8/myweb/'.

So far so good. However when my web application (mediawiki) servers up some pages in response to a command, it starts out with http://123.456.7.8/myweb/somepage but then switches to http://mylinux.domainname.org/myweb/somepage and giving me a DNS error on my client web browswer (where mylinux.domainname.org is the name in the /etc/hosts file:

127.0.0.1 localhost
127.0.0.1 mylinux.domainname.org mylinux


If I take out the 2nd line httpd errors giving me: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

What I want is to stop the apparent substitution of 'mylinux.domainname.org' for '123.456.7.8' when apache 1.3 serves up a page.

I can go into httpd.conf and set ServerName 123.456.7.8 but that only works until I reboot and am assigned a new IP address.


Thanks

Last edited by coldbeer; 07-05-2007 at 01:57 PM.
 
Old 07-06-2007, 01:45 AM   #2
igorc
Member
 
Registered: May 2005
Location: Sydney, Australia
Distribution: Ubuntu 5.04, Debian 3.1
Posts: 74

Rep: Reputation: 15
Hi,

As a workaround you might put this lines in a startup script (assuming eth1 is your network interface):

newip=`ifconfig eth1 | grep "inet " | awk '{print $2}' | cut -d: -f2`
sed -e "s/ServerName[ \t+]\([0-9]\+\.\)\{1,3\}[0-9]\+/ServerName $newip/" httpd.conf
/etc/init.d/apache2 restart # optional, if you change ip address before apache sturts up you don't need this line (this is debian way restart i'm not sure about slackware)

This should detect your new IP address and update the httpd.conf file after restart.

Last edited by igorc; 07-06-2007 at 01:50 AM.
 
Old 07-06-2007, 08:09 AM   #3
coldbeer
Member
 
Registered: May 2006
Location: Orion–Cygnus Arm, MWG
Distribution: Slackware, Ubuntu
Posts: 249

Original Poster
Rep: Reputation: 130Reputation: 130
Thanks Igor! That works nicely

Here's the working slackware 11 specific script for posterity
-------------------------------------------------
#!/bin/sh

path2conf="/etc/apache";

newip=`ifconfig eth0 | grep "inet " | awk '{print $2}' | cut -d: -f2`

sed -e "s/ServerName[ \t+]\([0-9]\+\.\)\{1,3\}[0-9]\+/ServerName $newip/" $path2conf/httpd.conf >$path2conf/httpd.conf.new

mv $path2conf/httpd.conf $path2conf/httpd.conf.bu
mv $path2conf/httpd.conf.new $path2conf/httpd.conf

/etc/rc.d/rc.httpd restart

echo "ServerName assigned to $newip. Apache restarted.\n"
echo "Thats All Folks\n"
----------------------------------------------
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Set IP address to static from DHCP assigned address jborn Linux - Networking 4 02-02-2007 08:38 PM
[SOLVED] Converting static IP-address to dynamic IP-address Blue_Ice Linux - Networking 3 07-20-2006 03:35 AM
Static IP Address with DHCP server control taylortbb Linux - Networking 1 06-28-2005 01:43 PM
Apache 2 Server - Can't access it via ip address from inside LAN Robstro Linux - Networking 1 06-30-2004 01:50 PM
Verizon aDSL setup with static IP address RH9 server costasm Linux - Networking 1 10-16-2003 02:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration