mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / HOSTALIASES.mdwn
1 I have accounts on a number of systems where the sysadmin doesn't
2 maintain a comprehensive `/etc/hosts` file.  In order to work around
3 this, I wanted to have a per-user `~/.hosts` to extend the system file
4 with my own aliases.  Then I could use my short nicknames for network
5 activity without spelling out the whole domain name (the `domain`
6 setting in `/etc/resolv.conf` is often not close enough for the
7 nicknames to work using [[DNS]]).
8
9 A common technique for translating host names into IP addresses is to
10 use either `getaddrinfo(3)` or the obsolete `gethostbyname(3)`.  As
11 mentioned in `hostname(7)`, you can set the `HOSTALIASES` environment
12 variable to point to an alias file, and you've got per-user aliases!
13
14 Well, mostly…
15
16 `HOSTALIASES` will work if your program (`ping`, `ssh`, etc.)
17 satisfies two conditions:
18
19 1. It has to actually use one of the two functions listed above to
20    resolve the host name.  I haven't run across anything that doesn't,
21    but you never know.
22 2. It cannot be setuid to another user.  If it is, [libc sanitizes the
23    environment][sanitize], so your `HOSTALIASES` setting is lost.  See
24    `sysdeps/generic/unsecvars.h` for a list of all environment
25    variables that glibc removes for setuid programs.
26
27 `ping` is setuid `root` (because it needs to listen for ICMP packets),
28 so `HOSTALIASES` will not work with `ping` unless you're already
29 `root` before you call `ping`.
30
31 Here's an example:
32
33     $ echo 'g www.google.com' >> ~/.hosts
34     $ export HOSTALIASES=~/.hosts
35     $ firefox g
36
37 Adjust your `~/.bashrc` appropriately, and you can forget about
38 `/etc/hosts` entirely :).
39
40 [sanitize]: http://en.wikipedia.org/wiki/Environment_variable#Security