Best way to manage host IP addresses on a small LAN
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?)
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.
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 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:
##{ 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:
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?
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.
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.
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.)
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.
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.
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.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.