Joachim Breitner's Homepage
libnss-gw-name: A stable name for your gateway
I often find myself running /sbin/route
to get the IP address of the current gateway, especially when using a wireless LAN while traveling. For example, if the “Internet does not work” I usually ping the local gateway to see where the connectivity problem lies. I also need the IP if I want to access the routers configuration web interface. This is somewhat tedious, so I wrote libnss-gw-name, and now:
$ sudo apt-get install libnss-gw-name [...] $ ping gateway.current PING gateway.current (172.20.239.1) 56(84) bytes of data. 64 bytes from hhicalvin.stud.uni-karlsruhe.de (172.20.239.1): icmp_seq=1 ttl=64 time=2.16 ms 64 bytes from hhicalvin.stud.uni-karlsruhe.de (172.20.239.1): icmp_seq=2 ttl=64 time=1.48 ms 64 bytes from hhicalvin.stud.uni-karlsruhe.de (172.20.239.1): icmp_seq=3 ttl=64 time=2.73 ms ^C --- gateway.current ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 1.482/2.129/2.739/0.513 ms
Once libnss-gw-name is installed, it hooks into the system’s Name Service Switch, which is, among other things, responsible for resolving hostnames to ip addresses. It will only react on the name “gateway.current”, checking the system’s routing table and returning the IP address of the current default gateway.
It’s a pretty simple and small tool, but it could well prove very handy to the power user. I uploaded libnss-gw-name to Debian sid, you can download the source code or access the git repository.
Update: Changed the name to gateway.localhost, as that is within a reserved top-level-domain.
Comments
What would you like libgw-name return?
Could I talk you into also packaging nss-myhostname (http://0pointer.de/lennart/projects/nss-myhostname/)? It resolves the system's current hostname to 127.0.0.2 and ::1 so you don't need to edit /etc/hosts when you change the system's hostname.
(I'd love to see Debian use it by default, for exactly that reason: one less file that varies from system to system, and one less file to edit if you change the hostname.)
Alternatively, if you'd rather not package nss-myhostname, would you consider integrating functionality like it into libnss-gw-name or another nss module in the same package?
Have something to say? You can post a comment by sending an e-Mail to me at <mail@joachim-breitner.de>, and I will include it here.