Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.


Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.


Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.


Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Commands & Shells

Auto-Update /etc/hosts

Submitted by on January 9, 2019 – 4:39 pm

This was a silly solution to a silly problem, but may come in handy in the future for other things. A user process was establishing frequent connections to a handful of FQDNs. Not having any IP caching capability, every connection attempt was preceded by DNS lookup.

When DNS was slow, the process experienced major meltdown. An easy “fix” was to add those FQDNs to /etc/hosts. Even though they were fairly static, I did not control them and their IPs could’ve changed at any time.

And so I wrote this little script intended to run once in a while from root cron to see if the IPs have changed and to update /etc/hosts as needed. I am almost certain there was a way for me to actually fix this problem instead of working my way around it, but so many unwatched episodes…

You can grab the script here or copy it from below.


Print Friendly, PDF & Email

Leave a Reply