Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hosts/DNS/DHCP confusion

Status
Not open for further replies.

lazyrunner50

Programmer
Jul 30, 2004
63
US
I'm using CentOS 5 (2.6.18-53.1.6.el5) and trying to figure out how all the networking files work together. Ok, so I have a wireless router and have set it up as a DHCP server and I get DNS "automatically from ISP". I realize DNS would not have the hostnames for the computers on my LAN, so I'm assuming the DNS server is contained in files on my router.
Code:
Here are my files:
/etc/hosts 
192.168.1.2    myComp2    localhost.localdomain

/etc/host.conf
order hosts,bind

/etc/resolv.conf
nameserver 192.168.1.1
From my understanding, to resolve hostnames the machine looks at /etc/host.conf first, finds out where it should go (in this case /etc/hosts), and then goes to the other locations if the entry is not contained in the first one (in this case /etc/resolv.conf). I noticed however, that no matter what I changed the second value of /etc/hosts to (myComp2), it would still use the old value which I believe is a cached name on my router. So, I have a couple questions.

1. Is my /etc/hosts file correct (assuming I don't have a static IP assigned to my computer)? Should it look like this instead?
Code:
127.0.0.1    myComp2  localhost.localdomain
2. If I do have a static IP of 192.168.1.2, will this entry update the cache on my router DNS?

3. How can I set the hostname of my computer if I get my ip from DHCP (meaning non-static)? I've already tried the hostname command, but I can't figure out what file that edits, nor does the value seem to be persistent between reboots.
 
1. There is nothing wrong with your hosts file. You should really keep the 127.0.0.1 resolution if you are on DHCP. Pointing it to a different IP that what you will get from your DHCP can cause some services & application to fail.

2. NO. Your router only acts as a DNS forwarder to your ISP's DNS server.

3. As far as I know, /etc/sysconfig/network contains your hostname. Most home routers are able to assign you a fixed or regular IP based on your NIC's MAC address only.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--
 
1. Ok thanks. Yeah, except for the addition of "myComp2" that was the original /etc/hosts file on my computer.

2. Sorry should have been more specific. Meant only the DNS (if that is actually what it is called) within my LAN. For instance, the hostname within my LAN would be something like myComp2, which would of course not be on a DNS server on the internet. I'm assuming the router contains some sort of caching mechanism that maintains the hostnames of the machines on my LAN. Anyway, I'm just trying to figure out a way that a particular host can update the router "DNS" for my LAN.

3. Yep, my router does it based on MAC address.
 
/etc/nsswitch.conf determines the order of your resolution data lookups.

Your /etc/hosts is assigning localhost (usually reserved to the loopback interface) to a public interface. That's really bad practice. Actually it's utterly broken, but never-mind.

Regarding your DNS based resolution...If you want your dns lookups to work for your internal (192.x) range then my best suggestion is to run an authoritative nameserver for your internal network. Your router can the do lookups based on internal addresses from your internal dns and request resolution from your isp's nameservers otherwise.

Your dhcp client can prepend or postfix hostname and domain or just ignore the assignment from the DHCP server. See the docs for your particular client.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top