Issue
Is there an easy way to add DHCP issued IP address and host name of a Linux machine in /etc/hosts at system startup automatically?
Background:
My Linux machine has a host name in /etc/hostname and it won't resolve to anything when I ping. I manually added my host name and IP address in /etc/hosts for one my network related Java programs to work.
Solution
dhcpcd has a -c/--script
option to run an external script anytime it configures or brings up an interface. You can use this to manually update the hosts file with the configured hostname.
Answered By - Marc B