DNS for my LAN
Posted: Mon Dec 31, 2012 1:04 pm
Well...There's this problem. I have a large lan, but it's not so much server->client as a bunch of peers. Each machine gets an IP from DHCP from my telco router (which I have to use, and cannot change) on boot - so everytime, each machine has a different IP.
Samba finds them all of course, with proper config, but that means I have to use my file explorer (Nautilus in linux) to find/access another machine for copying files, cross backups and so on - a script can't do it since it can't find the right machine always.
So, I spent the weekend diddling around. I'm hoping, actually, that it was wasted effort and that someone will tell me "just get program X for dns and tell things to only do this for the LAN, and it will work with any two machines on". But this hasn't happened yet.
So I spent some time munging around in perl. I wrote two scripts, one that simply finds out the name/ip pair of the machine it's running on and sends that out the UDP broadcast address about once a minute.
The other one listens for that, builds up a data structure of what's out there (and kills off things it hasn't heard from in awhile) and rewrites /etc/hosts when things change.
This works - many of my machines, for example, run apache and mysql, and it's nice to be able to use that interface by just typing in a machine name to a web browser, or hard-coding a machine into a script that might want to use my fast upstairs server database to record data from the fusor downstairs (safely away from the lightning too).
But, there are issues. Doing this in perl means the programs have a fairly large footprint in ram (500k for one, 1.5 megs for the other). Further, while the transmit one is tiny and simple (and should really be re-written in C for size, it's not rocket science), the recieve one is not only large and complex, but needs root priveledge to write /etc/hosts - and a lot of things complain about that unless you run it manually from a terminal. I want both to be daemons that run at startup, now and forever, which again, is pretty easy for the transmit one, but kind of hairy for the receive one. And no, I don't want to make /etc writable by non-root, it's dangerous.
But the programs work as is, run in terminals (even detached) and I can turn off their debugging printing etc for that. Anybody out there have a better idea?
Note, to make any sense at all of a perl program, use something that does syntax highlighting, else you'll just go blind. Gedit does, padre does, geany does, and so on.
For example, here's one of them in gedit.
Samba finds them all of course, with proper config, but that means I have to use my file explorer (Nautilus in linux) to find/access another machine for copying files, cross backups and so on - a script can't do it since it can't find the right machine always.
So, I spent the weekend diddling around. I'm hoping, actually, that it was wasted effort and that someone will tell me "just get program X for dns and tell things to only do this for the LAN, and it will work with any two machines on". But this hasn't happened yet.
So I spent some time munging around in perl. I wrote two scripts, one that simply finds out the name/ip pair of the machine it's running on and sends that out the UDP broadcast address about once a minute.
The other one listens for that, builds up a data structure of what's out there (and kills off things it hasn't heard from in awhile) and rewrites /etc/hosts when things change.
This works - many of my machines, for example, run apache and mysql, and it's nice to be able to use that interface by just typing in a machine name to a web browser, or hard-coding a machine into a script that might want to use my fast upstairs server database to record data from the fusor downstairs (safely away from the lightning too).
But, there are issues. Doing this in perl means the programs have a fairly large footprint in ram (500k for one, 1.5 megs for the other). Further, while the transmit one is tiny and simple (and should really be re-written in C for size, it's not rocket science), the recieve one is not only large and complex, but needs root priveledge to write /etc/hosts - and a lot of things complain about that unless you run it manually from a terminal. I want both to be daemons that run at startup, now and forever, which again, is pretty easy for the transmit one, but kind of hairy for the receive one. And no, I don't want to make /etc writable by non-root, it's dangerous.
But the programs work as is, run in terminals (even detached) and I can turn off their debugging printing etc for that. Anybody out there have a better idea?
Note, to make any sense at all of a perl program, use something that does syntax highlighting, else you'll just go blind. Gedit does, padre does, geany does, and so on.
For example, here's one of them in gedit.