Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Dynamic IP and Apache Virtual Hosts
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
sidesh0w
n00b
n00b


Joined: 02 May 2002
Posts: 14

PostPosted: Tue May 28, 2002 8:43 pm    Post subject: Dynamic IP and Apache Virtual Hosts Reply with quote

Hello all,

I apologize if this has been posted already. I did a search and did not get any results.


Anyway, I needed a way to dynamically update my apache.conf file each time my IP changed. To accomplish this, I used the following steps:

- copy apache.conf to apache.conf.orig (or whatever naming convention you want)

- edit this apache.conf.orig and replace the hard coded IPs (such as in NameVirtualHost 111.222.333.444 and <VirtualHost 111.222.333.444>) with a variable name such as @MYIP@

- edit the /etc/conf.d/net file and add this line:
Code:
myip=`hostname -i`


- edit the /etc/init.d/net.eth# for your dynamic adapter and add the following to the end of the start() function:
Code:
if [ -n "$(myip)" ]
then
   ebegin " Updating Apache Virtual Hosts"
   /bin/sed "s/@MYIP@/$myip/g" < /etc/apache/conf/apache.conf.orig > /etc/apache/conf/apache.conf
   eend 0
fi


sed will go in and replace the @MYIP@ with the results of `hostname -i` from the net conf script.

- restart the net.eth# script and you should be all set!!

Assumptions:
- you call out the virtual hosts in the apache.conf file and not one of the files on the hosts directory. I havent tried it, but im sure you could do the same with the supplemental files

Thanks to http://www.progsec.uts.edu.au/lists/slug/2000/June/msg00552.html
Back to top
View user's profile Send private message
Rylan
n00b
n00b


Joined: 08 May 2002
Posts: 41

PostPosted: Tue May 28, 2002 11:09 pm    Post subject: Reply with quote

I tried
Code:
hostname -i
hostname --ip-address


Both of them said "hostname: Unknown host"

Is there something I need to do with /etc/hosts to make hostname -i output my ipaddress? This would be much more efficient than the ifconfig -a | grep | cut madness that I've used in the past.
Back to top
View user's profile Send private message
sidesh0w
n00b
n00b


Joined: 02 May 2002
Posts: 14

PostPosted: Wed May 29, 2002 2:12 am    Post subject: Reply with quote

You may just have to set your hostname in /etc/hostname. I only have 127.0.0.1 localhost in my /etc/hosts.
Back to top
View user's profile Send private message
Rylan
n00b
n00b


Joined: 08 May 2002
Posts: 41

PostPosted: Wed May 29, 2002 11:49 pm    Post subject: Reply with quote

Hmmm, my /etc/hostname *has* my hostname in it.

Thanks for the suggestion anyway though.
Back to top
View user's profile Send private message
sidesh0w
n00b
n00b


Joined: 02 May 2002
Posts: 14

PostPosted: Sat Jun 08, 2002 12:10 pm    Post subject: Updated instructions Reply with quote

Rylan,

Well, after a few reboots, I had the same problem - it told me that hostname was unknown. I revapmed some of the code, and tried this:

-Edit /etc/init.d/apache in the start function to add the /bin/sed line:

Code:
start() {                                                                                                                           
        ebegin "Starting apache"                                                                                                   
        /bin/sed "s/@MYIP@/`hostname -i`/g" < /etc/apache/conf/apache.conf.orig > /etc/apache/conf/apache.conf                       
        start-stop-daemon --quiet --start --startas /usr/sbin/apache \                                                             
                --pidfile /var/run/apache.pid -- ${APACHE_OPTS}                                                                     
        eend $?                                                                                                                     


Then set your apache.conf.orig as per the first post.

I think it was trying to execute the `hostname -i` before the network card came up and that is why it was giving us an error.

I tried rebooting my machine a few times as well as shutting the machine down and powering off the cable modem and it still works.

Let me know if it works for you.
Back to top
View user's profile Send private message
DArtagnan
l33t
l33t


Joined: 30 Apr 2002
Posts: 942
Location: Israel, Jerusalem

PostPosted: Thu Jun 13, 2002 1:43 pm    Post subject: Reply with quote

Ok, nice but how can i get the ppp0`s IP?
I have 2 IP, one for eth0 and one for ppp0 ( adsl connection )
The eth0`s IP is stable one and is local number like 10.200.1.1.
The real IP is the ppp0`s number.
Thanks
_________________
All for one and one for All
--

MACPRO machine...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum