Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've got an Ubuntu Linux server with a WiFi card. When I boot my computer apache web server starts and the /etc/hosts file lists which lists the following:

$ cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   avalanche

allows my server to be accessed from the same host using http:// localhost/ or http:// avalanche .

However, when I run ifconfig I get the following output:

wlan0     Link encap:Ethernet  HWaddr cc:af:78:bf:28:45  
          inet addr:192.168.3.31  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::ceaf:78ff:febf:2845/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:565796 errors:0 dropped:0 overruns:0 frame:0
          TX packets:360709 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:620453848 (620.4 MB)  TX bytes:46274848 (46.2 MB)

So, I would like browsers on my internal network to be able to access the apache server not only with http:// 192.168.3.31 but also by http:// avalanche/ . This means I must add the following mapping in /etc/hosts :

192.168.3.31    avalanche

but I don't want to have to have to do it by hand every time the machine boots, but at the same time the IP address the router assigns, AFAIK is a dynamic IP address, so it changes all the time, so I cannot just hardcode an IP in the /etc/hosts file.

So, my question is, what is the best way of adding this mapping dynamically when the machine boots up?

Thanks,

John Goche

share|improve this question
    
You don't need to do anything to your hosts file, you need to setup DNS on your network. –  Zoredache Jul 26 '12 at 16:34

1 Answer 1

up vote 1 down vote accepted

First off, give your webserver a static IP on the internal network.

Next off, I guess you are using a DNS server on your network? In such case, just add the avalanche entry to point at webserver static IP

share|improve this answer
    
Why can't I do this with dynamic IPs. Running bind would need a dedicated computer with a static IP running bind. I am not running bind on my network, and given that there is only one computer running Linux on the network, and it has a dynamic IP address, this makes it hard for other computers to reference the nameserver doesn't it. –  user1527429 Jul 26 '12 at 17:37
    
I didnt really get that much of your response. From what I read, you dont have any DNS server on your network? It doesn't have to be BIND, but could be anything - even Windows. The reason why I told you to give the webserver a static IP is because that's best practice. Relying on DNS alone can be a bad thing. –  Frederik Nielsen Jul 26 '12 at 17:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.