So I have a KVM host that also runs an apache server with some yum repos.

The VM guests are connected to the default virtual network, which is configured to offer DHCP and forwarding with NAT on virbr0 (

The guests can successfully access the yum repos on the host by IP address, so for example curl returns the content without problems. But I'd like to have the guests be able to reach the web server on the host by name rather IP address.

I added the desired name record to the host's /etc/hosts file and libvirt's dnsmasq service seems to be serving that correctly to the guests since nslookup and dig successfully resolve the name on the guests:

[root@localhost ~]# nslookup repo

Name:   repo

[root@localhost ~]# dig repo

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 <<>> repo
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55938
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;repo.              IN  A

repo.           0   IN  A

;; Query time: 0 msec
;; WHEN: Tue Sep 17 02:10:46 2013
;; MSG SIZE  rcvd: 38

But curl/ping/etc still fail:

[root@localhost ~]# curl repo
curl: (6) Couldn't resolve host 'repo'

While a request via ip address works:

[root@localhost ~]# curl
  <title>Index of /</title>

Same with ping:

[root@localhost ~]# ping repo
ping: unknown host repo
[root@localhost ~]# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.110 ms
64 bytes from icmp_seq=2 ttl=64 time=0.146 ms
64 bytes from icmp_seq=3 ttl=64 time=0.191 ms
--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2298ms
rtt min/avg/max/mdev = 0.110/0.149/0.191/0.033 ms

I tried adding repo to the guests' /etc/hosts files but still no dice. Also tried changing guests' /etc/nsswitch.conf with both:

hosts:      files dns


hosts:      dns files

I've read the relevant libvirt documentation and I'm not sure where else to learn more about this and be able to move forward with it.

3 Answers 3


Does adding the following to /etc/hosts on the guests work: repo ? (you said you added repo

What's in your /etc/resolv.conf on the guests?

You should also leave /etc/nsswitch.conf with hosts: files dns

  • Hi @itzo. Welcome to ServerFault! If you have any questions to clarify, please ask it in the comments section for that question. Sep 17, 2013 at 4:00
  • Hi Pothi, thanks for the warm welcome. Unfortunately it appears that I would need 50 rep before I am allowed to post a comment to the question.
    – itzo
    Sep 18, 2013 at 2:54
  • Got it. My apologies! Sep 18, 2013 at 2:55
  • Right! I had that hosts file wrong. Corrected now it with that it does work. But I was still hoping to understand why it ping/curl/etc doesn't work on the guest VM if nslookup/dig does...
    – Gestellen
    Sep 18, 2013 at 19:40
  • Oh and the /etc/resolv.conf of the guest has only nameserver
    – Gestellen
    Sep 18, 2013 at 19:51

Add it to the /etc/hosts of the host, not the guest.

To make it work via DNS, setup both domain names and hostnames, like host1.internal.domain.com (domain = internal.domain.com).

You must change /etc/sysconfig/network (NISDOMAIN=), /etc/resolv.conf (search, domain), /etc/sysconfig/network-scripts/ifcfg-xxx (DOMAIN=,HOSTNAME= (FQDN)), /etc/hostname (FQDN) accordingly.

  • I do have it on the /etc/hosts of the guest. I was hoping to understand why the name record gets delivered correctly to the guest (via nslookup/dig) but ping/curl/etc fails...
    – Gestellen
    Sep 18, 2013 at 19:41

Instead of manually change dns client config, You should use the addressing of libvirt network to manage FQDN for both your guest OS and the host.

perform command virsh net-edit default and added the following stanza within element <network> in your naming context:

<domain name="example.com"></domain>
  <forwarder addr=""/>
  <host ip=''>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .