I'm considering writing a patch that would cause a hosts file to be created containing the ip addressess, ifnames and hostnames of all network interfaces.
For example, consider an OpenWRT box with these NVRAM values set:
wan_hostname=MyRouter
wan_proto=dhcp
wan_ifname=vlan1
lan_hostname=MyLanRouter
lan_proto=static
lan_ifname=br0
lan_ipaddr=192.168.201.1
dmz_hostname=DMZGateway
dmz proto=static
dmz_ifname=vlan2
dmz_ipaddr=192.168.222.1
ifnames=dmz
Note that the "ifnames" NVRAM variable is new in Kamikaze. It tells the network hotplug script which non-default interfaces to initialise. lan, wan and wifi are initialised by default, according to their "<name>_proto=" variable.
The hotplug script would use a little awk routine to get the actual IP address of an interface so that interfaces configured via DHCP could also have their DHCP-assigned IP address in the hosts file.
If people want to add their own entries to their hosts file, they add them to /etc/hosts.static. The contents of this file are appended to /tmp/hosts.localhost when it is created or updated.
/etc/hosts would be symlinked to /tmp/hosts.localhost. After initialisation, /tmp/hosts.localhost would look like this:
#/tmp/hosts.localhost
#this file is dynamically generated by OpenWRT - don't bother editing it!
127.0.0.1 localhost
144.129.30.62 wan MyRouter
192.168.201.1 lan MyLanRouter
192.168.222.1 dmz DMZGateway
#contents of /etc/hosts.static are automatically added below this line
Having a default configuration where the names "wan" and "lan" always point at the correct IP address would be very handy. Many programs allow hostnames instead of ip addresses in their config files. Being able to substitue "lan" instead of "192.168.1.1" or "br0" in a config file makes it possible to package programs with default settings that can withstand a wide range of hardware and custom network configs.
By default, dnsmasq reads the contents of /etc/hosts and makes the contents available for name resolution via it's dns server. However, we would not want it to serve the contents of /tmp/hosts.localhost because the interface names (wan, lan, dmz) would not be appropriate for other dns clients on our network. To solve this, the network initialisation script also genrates a file called /tmp/hosts.dnsmasq that looks like this:
#/tmp/hosts.dnsmasq
#this file is dynamically generated by OpenWRT - don't bother editing it!
144.129.30.62 MyRouter
192.168.201.1 MyLanRouter
192.168.222.1 DMZGateway
We would configure dnsmasq to read /tmp/hosts.dnsmasq and /etc/hosts.static but not /etc/hosts (the symlink to /tmp/hosts.localhost).
Of course a scheme like this won't be useful in every circumstance, but I think it'd make using openwrt a lot nicer and it opens the door for further configs based on hostname rather than interface name or IP address.
Before I spend time writing the patch, I'd like some feedback on the idea - from developers and users. Cheers!