Ubuntu on the go: networking tweaks

Among the many annoyances that moving onto Ubuntu brought was the minimalist defaults for networking. I’ve mentioned in another post how I defeated the ipv6 dragon. This post is about how to make your hostname and resolv.conf behave themselves, just as they do under Red Hat.

First for hostname. By default, Ubuntu sets itself up with just the truncated prefix of a “real” hostname, which since time immemorium has included the domain name as a suffix. While changing this can lead to problems where certain software (think NFS) has been configured to allow/disallow access based on domain, for the most part life becomes a lot easier with the domain appended. To do this on Ubuntu you simply edit /etc/hostname and add the domain name to the host name. For example:

myhost.example.com

Restart the system to effect this change.

Where you’re using DHCP to grab a network address, most of the time you’ll also get fed the server’s domain name as your default search domain, as well as the addresses of whatever name servers its been configured to push. This info gets written to /etc/resolv.conf and is overwritten every time you connect up to a DHCP server. If you have a “home” network where you spend most of your time, you can modify the defaults to change your search domain to that home domain and prepend a name server or name servers to the list the client gets from DHCP. Here’s how:

Edit /etc/dhcp3/dhclient.conf and add the following lines (you should see an example commented out in the file):

supercede domain-name "example.com";
prepend domain-name-servers 192.168.5.2;

Note that the semicolons are required, if you leave them out the system will not invoke the change. This change should be effective on the next restart of networking, but where you’re using NetworkManager (which by default a mobile Ubuntu machine will be), a full system reboot is probably prudent.

Note: I did have one rather nasty bit of fallout from making these changes: VMware Server wouldn’t restart. I was able to get it functioning again by removing the domain component from the hostname (e.g. changing from “myhost.example.com” to “myhost”).