LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Using Apache server with non-static IP address issue (https://www.linuxquestions.org/questions/linux-server-73/using-apache-server-with-non-static-ip-address-issue-566896/)

coldbeer 07-05-2007 01:42 PM

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

igorc 07-06-2007 01:45 AM

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.

coldbeer 07-06-2007 08:09 AM

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"
----------------------------------------------


All times are GMT -5. The time now is 10:14 AM.