Nevyn's Blog

Thursday, 14 August 2008

auto create DHCP hostnames for a scope

Following on from private IP address pools for your cluster, you might want a way to automatically create entries for all your machines in DHCP or in your /etc/hosts file - perhaps you have a Cisco router and don't want to edit that config file by hand?

N=1; for x in $(seq -w 254); do echo -e "10.0.0.$N \t node$x"; N=$(expr $N+1); done >> /etc/hosts

sample output:
...
10.0.0.250 node250
10.0.0.251 node251
10.0.0.252 node252
10.0.0.253 node253
10.0.0.254 node254

Using echo -e interprets the escaped \t as a tab character correctly.
(I gather that tab is sometimes the recommended whitespace format e.g. used in the Windows\system32\drivers\etc\hosts file?, rather than just spaces. I also included spaces for legibility here though)

We use (seq -w 254) which iterates through all the numbers 001, 002, ... 254 and the -w flag keeps the leading zeros. We use this value, assigned to $x, to generate consistent looking hostnames, 'node001' etc.

We also take N (starting at 1) and increase it by 1 on each iteration. We use that as the value of the node's IP number in the echo statement.

Finally, it appends to the /etc/hosts file, although you can redirect this output anywhere if you want to check or edit it before use.

Note:
Take care if modifying the command to loop through multiple subnets, eg 10.0.$N.$M - if you are not careful you could end up with 255*65535 lines of output, or in other words, have ip addresses going from 10.0.1.1 to 10.0.1.65535, which is not what you would want!!

=)

Also Note:

If we used $x instead of $N, we may have difficulty resolving nodes < 100.
For example, 'ping node001' could end up trying a dns lookup on "node001.defaultsearch.domain" instead of pinging '10.0.0.1' as expected.

I've seen this behaviour on CentOS / BlueQuartz - The leading zeros on ips lower than x.y.z.100 seemed to confuse the resolver

It had nothing to do with nsswitch.conf, "hosts: files,dns" or /etc/resolv.conf. Restarting nscd (name service caching daemon) by logging in as root and trying

/etc/init.d/nscd restart
/etc/rc.d/init.d/nscd restart (on other flavours perhaps)

to flush cached DNS entries didn't work either, especially since nscd wasn't running at the time...

Labels: , , , , , , , ,

Monday, 11 August 2008

DNS frustrations

Imagine the situation:

You've just registered a domain name with a DNS registrar.
You update the DNS nameserver records to point to a couple of new nameservers, perhaps under your control, or at the ISP where your hosting is...
You've waited 24 hours for the migration to occur, and it seemed successful.
Now you test {www.yourdomain.xyz} with host -v {domain}, nslookup {domain}, and dig {domain}.
All the results point to your new server's IP address. Yet your browser still goes to the old domain parking page on the registrars server...?

Well it could be that the local resolver on your PC is to blame, caching the old DNS A record while the TTL (Time-To-Live) expires. You could fix it perhaps with a reboot, or try these two Windows commands:

ipconfig /displaydns (shows the local dns cache)
ipconfig /flushdns (drops all the records and begins resolving anew)

tada!! your browser now learns the new address and off it goes to your shiny new site =)

ps if anyone knows the equivalent commands for a linux / unix OS, please post a comment!

Labels: , , , , , , ,

Tuesday, 29 July 2008

The Internet now

Here's what the Internet was like in June 2008, in terms of numbers of domains, web server platforms and so on: http://news.netcraft.com/archives/2008/06/22/june_2008_web_server_survey.html

I should take an archive of that article - it shows the growth of the internet from the beginning of the 'dot-com' era, circa 1995-98, and it will make an excellent comparison in say 10 years now that IPv6 may begin to appear, and more importantly, more top level domains have been allowed (ie instead of just the usual .com, .net, .org, .mil, .gov, .edu , .info, .biz, and all the two letter country codes, we could have someone offering .xxx or .sex, and so on!)

Personally I think those domains are a good idea - what better way to declare a site that has adult content, which would make it easy to allow someone to choose whether to or not to block access to 'unsafe' content (great for parents, and offices who want to block that kind of surfing). Of course, it wouldnt work - too many people would circumvent it. Well, an infinite pool of monkeys.....

Labels: , , , , , , ,