0

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 (192.168.12.1).

The guests can successfully access the yum repos on the host by IP address, so for example curl 192.168.122.1/repo1 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
Server:     192.168.122.1
Address:    192.168.122.1#53

Name:   repo
Address: 192.168.122.1

[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

;; QUESTION SECTION:
;repo.              IN  A

;; ANSWER SECTION:
repo.           0   IN  A   192.168.122.1

;; Query time: 0 msec
;; SERVER: 192.168.122.1#53(192.168.122.1)
;; 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 192.168.122.1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /</title>
 [...]

Same with ping:

[root@localhost ~]# ping repo
ping: unknown host repo
[root@localhost ~]# ping 192.168.122.1
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data.
64 bytes from 192.168.122.1: icmp_seq=1 ttl=64 time=0.110 ms
64 bytes from 192.168.122.1: icmp_seq=2 ttl=64 time=0.146 ms
64 bytes from 192.168.122.1: icmp_seq=3 ttl=64 time=0.191 ms
^C
--- 192.168.122.1 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 192.168.122.1 to the guests' /etc/hosts files but still no dice. Also tried changing guests' /etc/nsswitch.conf with both:

hosts:      files dns

and

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

3

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

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

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

5
  • 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 192.168.122.1.
    – Gestellen
    Sep 18, 2013 at 19:51
0

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.

1
  • 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
0

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>
<dns>
  <forwarder addr="8.8.8.8"/>
  <host ip='192.168.122.1'>
    <hostname>repo</hostname>
  </host>
</dns>

You must log in to answer this question.

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