LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-30-2009, 01:07 PM   #1
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Rep: Reputation: 41
Best way to manage host IP addresses on a small LAN


I've been using the /etc/hosts file to manage IP addresses on my small LAN. (The file has a dozen or so entries.) But IP addresses are changing more frequently than I would like (for various unavoidable reasons such as adding new computers).

Is there a better solution than manually editing the /etc/hosts file on each workstation?

Is there a way to symlink to a single /etc/hosts file on a file server? I suppose you would have to have a hosts file with the IP address of the file server, and then when the file server is reachable, mask that local hosts file with the one linked to the file server. Is this possible? Is it easy?

If I must maintain individual hosts files, can I copy the exact same file to each computer? (This will give a LAN IP address entry for the local host, which is usually not present in the file. Will that be OK?)
 
Old 03-30-2009, 01:13 PM   #2
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,249
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
That is exactly why DNS was created.. Centralized host name management.

BIND9
tinydns
djbdns


http://www.howtoforge.com/howtos/dns
 
Old 03-30-2009, 01:21 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Mountain View Post
I've been using the /etc/hosts file to manage IP addresses on my small LAN. (The file has a dozen or so entries.) But IP addresses are changing more frequently than I would like (for various unavoidable reasons such as adding new computers).

Is there a better solution than manually editing the /etc/hosts file on each workstation?

Is there a way to symlink to a single /etc/hosts file on a file server? I suppose you would have to have a hosts file with the IP address of the file server, and then when the file server is reachable, mask that local hosts file with the one linked to the file server. Is this possible? Is it easy?

If I must maintain individual hosts files, can I copy the exact same file to each computer? (This will give a LAN IP address entry for the local host, which is usually not present in the file. Will that be OK?)
You CAN symlink an /etc/hosts file, but I wouldn't recommend having an important systems file be a shared symlink.

If you just want to manage names, set up a simple DNS server, and shove the entries in there. If you have static IP's for your workstations/servers, you're all set. Just set up your DNS server, and point all the workstations to it, via /etc/resolv.conf. You make a name change in one place, and all workstations pick it up.

If you want to go one step further, you can set up DHCP to dole out the same address to the same device every time. Leave workstations set to boot up via DHCP...on first boot, you'll see the address get assigned, then be able to modify the DHCP config, adding that IP address/MAC address combination for next boot. Since DHCP also sets up name resolution, default gateway, etc., that lets most of the network config for workstations be automatic.
 
Old 03-30-2009, 02:50 PM   #4
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
My NetGear router is a DHCP server and it can reserve an IP address for clients (by MAC address). So what I want, is something really, really simple. Which of the dns servers is as simple as ssmtp, for example?

I looked at some of the how-tos (http://www.howtoforge.com/howtos/dns) and they all look too complex. I want something super simple.
 
Old 03-30-2009, 05:05 PM   #5
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
I have an idea for a script, but I could use some help in implementing it.

My idea is that I could write each /etc/hosts file with a designated block of replaceable content and then run a script that will take my updated hosts file content and write it to the /etc/hosts file on each Linux workstation on my LAN. However, I don't know how to do this. Can anyone help?

I can set up a login account on each workstation and give that account permissions to /etc/hosts.

I'm thinking that I could designate the block to be replaced something like this:

127.0.0.1 localhost
127.0.1.1 Ubuntu1.my-isp.com. Ubuntu1

##{ begin managed content
10.10.100.1 Ubuntu1.my-isp.com. Ubuntu1 #is the presence of this line a problem on machine Ubuntu1?
10.10.100.2 Ubuntu2.my-isp.com. Ubuntu2
10.10.100.3 Ubuntu3.my-isp.com. Ubuntu3
10.10.100.5 Ubuntu4.my-isp.com. Ubuntu4
10.10.100.6 Ubuntu5.my-isp.com. Ubuntu5
10.10.100.7 Win2k3_SageTV.my-isp.com. Win2k3_SageTV
10.10.100.17 Ubuntu6.my-isp.com. Ubuntu6
10.10.100.123 HpPrinter.my-isp.com. HpPrinter
10.10.100.251 MyRouter.my-isp.com. MyRouter
10.10.100.114 UbuntuLaptop.my-isp.com. UbuntuLaptop
11.222.33.123 MyLinode
##} end managed content

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts


And I could either let the script look at all computers in the 10.10.100.x address range and see if it can login via SSH and update /etc/hosts. If not, it skips that IP address. Or I could give a list of IP addresses to update, which is more reasonable because I would have that list handy, by definition of this task.

And the content to use for the update would simply reside in a text file that the script could read. It would be something like this:

##{ begin managed content
10.10.100.1 Ubuntu1.my-isp.com. Ubuntu1
10.10.100.2 Ubuntu2.my-isp.com. Ubuntu2
10.10.100.3 Ubuntu3.my-isp.com. Ubuntu3
10.10.100.5 Ubuntu4.my-isp.com. Ubuntu4
10.10.100.6 Ubuntu5.my-isp.com. Ubuntu5
10.10.100.7 Win2k3_SageTV.my-isp.com. Win2k3_SageTV
10.10.100.17 Ubuntu6.my-isp.com. Ubuntu6
10.10.100.123 HpPrinter.my-isp.com. HpPrinter
10.10.100.251 MyRouter.my-isp.com. MyRouter
10.10.100.114 UbuntuLaptop.my-isp.com. UbuntuLaptop
10.10.100.115 NEWLaptop.my-isp.com. NEWLaptop
11.222.33.123 MyLinode
##} end managed content

Can anyone show me what the script to accomplish this would look like? Thanks
 
Old 03-31-2009, 11:50 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Mountain View Post
I have an idea for a script, but I could use some help in implementing it.

My idea is that I could write each /etc/hosts file with a designated block of replaceable content and then run a script that will take my updated hosts file content and write it to the /etc/hosts file on each Linux workstation on my LAN. However, I don't know how to do this. Can anyone help?

I can set up a login account on each workstation and give that account permissions to /etc/hosts.

I'm thinking that I could designate the block to be replaced something like this:


Can anyone show me what the script to accomplish this would look like? Thanks
Well, we can HELP you, but I'm not too sure of anyone here writing programs for you, for free. If you post what you've written, and what problems you're having, I'm sure we could help you work through them.

On another note, you're going through alot of headaches, and messing with important configuration files, only to duplicate on a very small level, what DNS already does. Setting up a basic DNS server isn't difficult at all, and is far more worthwhile than this approach. It gives you stability, centralized management, and far more features, for a small time investment and following some clear HOWTOS.

What version/distro of Linux are you using for your server?
 
Old 03-31-2009, 12:09 PM   #7
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
I think I'm going to give up on this and just keep manually copying hosts files around. I don't want the features of a DNS server really because I need to keep things very simple. And I don't (yet) have the skills to write the script I was describing, so it seems like I have hit a dead end with this idea.
 
Old 03-31-2009, 12:11 PM   #8
mbostwick
Member
 
Registered: Feb 2009
Location: Where ever life takes me
Distribution: gentoo,opensuse,ubuntu, arch
Posts: 110

Rep: Reputation: 18
Why cant you statically set ip's ?
 
Old 03-31-2009, 12:26 PM   #9
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
I do, but that doesn't help when hardware changes, for example.
 
Old 03-31-2009, 12:41 PM   #10
mbostwick
Member
 
Registered: Feb 2009
Location: Where ever life takes me
Distribution: gentoo,opensuse,ubuntu, arch
Posts: 110

Rep: Reputation: 18
The issue is even if the script was written. Dns server is really the best way to control hosts to ip. You can make a simple script that uses rsync all of your hosts files when it boots up but you have to deal with all machines having it. I recommend reading up on some perl . I am sure some of us could help debug once you have some code written.
 
Old 03-31-2009, 12:45 PM   #11
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
Thanks. All the solutions we have discussed here require more time and effort than the original problem, so I'm going to bag this for now. There are other more pressing issues. If I ever get caught up on those, I may revisit this. (But my LAN is just too small for a DNS server in my opinion.)
 
Old 03-31-2009, 12:47 PM   #12
mbostwick
Member
 
Registered: Feb 2009
Location: Where ever life takes me
Distribution: gentoo,opensuse,ubuntu, arch
Posts: 110

Rep: Reputation: 18
One benefit of a dns server is cache so even though you make think your lan is small for a dns server you can get a performance increase if you cache common dns.
 
Old 03-31-2009, 12:59 PM   #13
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
Quote:
Originally Posted by mbostwick View Post
One benefit of a dns server is cache so even though you make think your lan is small for a dns server you can get a performance increase if you cache common dns.
thank you. that's worth considering for some time in the future.
 
Old 03-31-2009, 03:51 PM   #14
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,249
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
How to setup TinyDNS in 3 Minutes

So you are honestly telling us you don't have 3 minutes ? Glad my time isn't stretched that thin
 
Old 03-31-2009, 04:08 PM   #15
Mountain
Member
 
Registered: Nov 2007
Location: A place with no mountains
Distribution: Kubuntu, sidux, openSUSE
Posts: 214

Original Poster
Rep: Reputation: 41
Of course I have 3 minutes, but I also have 100 things that I should be working on in that 3 minutes.

Actually, it isn't the time required to install DNS. It is the management. I decided that even for the benefit of a performance gain, I cannot justify installing a DNS server. If I install one I will have to maintain it and I realized that extra burden would be a mistake for me. I need to take my technology in the other direction -- toward greater simplicity. I do not need a DNS server. (I'm reminding myself when I say that.)
 
  


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
Destination host unreachable after setting up IP addresses on LAN 10110111 Linux - Networking 3 10-29-2008 02:50 PM
Host has two addresses associated with it kaplan71 Red Hat 1 03-13-2007 10:12 AM
C: manage IP addresses Ephracis Programming 3 07-22-2006 01:18 PM
find ip addresses on lan allelopath Linux - Networking 9 05-03-2006 08:14 AM
Conflicting IP addresses in LAN? Joe Soap Linux - Networking 2 05-05-2005 04:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:27 PM.

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