8

My Ubuntu12 server VM is receiving its IP address from an DHCP server (actually my WLAN router called Fritz Box). Hence all domain names are resolved to machinename.fritz.box. The reason seems to be the resolv.conf file under /etc.

But how can I change this search name to an arbitrary name such as xyz.mydomain? It clearly says not to edit the file. The machine itself is set as ubuntu.xyz.mydomain in hostname. What I want is that machine1 is assumed to be machine1.xyz.mydomain and NOT(!) machine1.fritz.box.

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.1
search fritz.box # shall be xyz.mydomain
jdthood
  • 177
  • 1
  • 7
Horst Walter
  • 517
  • 1
  • 6
  • 10

3 Answers3

8

resolvconf is a program to manage the resolv.conf file so that multiple sources can add and remove entries without tripping over each other. The manager of each network interface feeds it a resolv.conf file for that interface, and it merges them all together.

resolvconf is meant to be run by network scripts or DHCP clients, but you can also run it yourself. Entries you make have to be associated with an interface; the "lo" interface is nice to use for locally administered entries because it's always up, it isn't dynamically managed, and its entries take priority over other interfaces. So:

echo 'search xyz.mydomain' | resolvconf -a lo

will add xyz.mydomain to the beginning of the search list. This will persist until you run resolvconf -d lo. (The network scripts may also run this if you use them to bring the lo interface down.)

You can make this more permanent by having the networks scripts handle it for you. On Ubuntu or other Debian-family distros, edit your /etc/network/interfaces file as follows:

iface lo inet loopback         # This line already present
    dns-search xyz.mydomain    # Add this line beneath it

For more info:

Jander
  • 16,272
  • 6
  • 50
  • 66
5

The best way to do this is to configure your WLAN router correctly, so that is is giving out proper fully qualified domain names (FQDN) to your hosts.

If the WLAN router serves hosts in the myhome.org domain then configure it as wlan-router.myhome.org. It likely uses it's own domain name as the value to hand out to clients.

A full DHCP has an option for setting this value for client systems:

option domain-search "example.com", "sales.example.com", "eng.example.com";

but it is unlikely, although possible, that you can set these dhcp options in your WLAN router.

If you are really stuck, you can edit resolv.conf, it will simply get clobbered every time you run the dhcp client. You can write a script to update it every time, but this is less than ideal, and will likely cause you grief if this is a mobile system, like a laptop.

spkane
  • 330
  • 2
  • 5
4

Without knowing how to change that in the router, one way is to setup static IP in the VM.

Modify /etc/network/interfaces as follow.

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
    address 192.168.0.X
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 192.168.0.1
    dns-search xyz.mydomain

Change 192.168.0.X to IP address you want to assign to VM. It should be outside of the dhcp range.

The dns-nameservers and dns-search will setup your /etc/resolv.conf.

John Siu
  • 4,695
  • 2
  • 25
  • 22