LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-17-2010, 06:11 AM   #1
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Rep: Reputation: 43
Manually maintaining /etc/hosts when using DHCP??


Hello. My first post here and i'm new to Linux/ networking so sorry if this is a daft question.

I have set up a home network using a modem/router, which my devices connect to via ethernet and wireless. I have got it working but i'm still not happy (stick with me...)!

I have settings configured so as to utilise DHCP, so IP addresses for the different machines are automatically assigned by the modem/router (as i understand it). I then obtained these auto-assigned IPs by running ifconfig on each device. I tested connections between the devices by pinging each other using these IPs (ie ping 192.168.2.2).

BUT I want to be able to use hostnames (ie ping dandelion) instead, and the only way I can make this work is to add hosts and corresponding IPs into the /etc/hosts file.

I have made it work in this way, but doesn't this method defeat the idea of DHCP, as I will now presumably have to manually maintain the /etc/hosts files on each device.

Thanks in advance.

Spoovy
 
Old 02-17-2010, 06:30 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
Depending on your router, there may be a setting that allows you to make the addresses that it assigns permanent. For example on my router, next to the ip address assigned to each machine, it has a checkbox that is labelled "always use this address".
Yes, once you've achieved that, you will have to edit your /etc/hosts file on each machine, but unless you keep changing the hostnames, you will only have to do it once.

Please use the correct format for hostnames i.e. host.domain.com in your /etc/hosts file as it will avoid problems later. You don't need to have a genuine domain for this as it only gets used inside your network. But once done you can use http addresses of the same format to access each machine with a browser (once apache is set up of course).

Also make sure you set the hostname on each machine properly. There are several places it needs to be changed if you do it manually, but depending on your distro, there is usually a GUI network config tool that allows you to set the hostname and add entries to /etc/hosts.

regards

Alan
 
1 members found this post helpful.
Old 02-17-2010, 04:28 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
There is a difference between netbios names and FQDN's. Hosts files are really for static situations. They can be used in your situation but as you say, you'd have to either mark the systems as lease forever or always issue or relay information back to your linux system with changes like you seem to be suggesting.

I think I'd set to forever lease and or always assign if possible as noted above.

Otherwise you might try setting up this. http://linux.die.net/man/8/nmbd
 
Old 02-18-2010, 12:21 PM   #4
spoovy
Member
 
Registered: Feb 2010
Location: London, UK
Distribution: Scientific, Ubuntu, Fedora
Posts: 373

Original Poster
Rep: Reputation: 43
Cheers guys i've set leases to permanent, which seems to be the best option at the moment. I can't really see much difference than setting fixed IPs though with this method.

I thought I would be able to set it up so that the router holds the IP addresses and hostnames, and then does the resolving for me like an internet DNS would; avoiding the need for the /etc/hosts files on each PC.

Is this possible or have I misunderstood how it works?

Thanks
 
Old 02-18-2010, 07:14 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625Reputation: 3625
It might be me that is confused. I kind of assumed you were talking about windows systems.

OH, sorry to be late. Welcome too!

Last edited by jefro; 02-18-2010 at 07:45 PM.
 
  


Reply



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
How do I manually disconnect/reconnect DHCP DSL internet connection? chaz_bro1972 Linux - Networking 34 06-06-2008 01:17 AM
Manually configuring DHCP for static IP -- cannot assign IP tristanlee85 Linux - Networking 3 10-16-2005 01:34 AM
manually changing DHCP settings minm Linux - Newbie 2 01-10-2005 01:28 PM
Manually specify network interfaces for DHCP NetAX Linux - Networking 1 04-22-2004 04:03 AM
debian DHCP/manually settings pe2338 Linux - Networking 0 08-14-2003 04:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:19 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