# kvm and dnsmasq configuration

## Adel Ahmed

I noticed that virtual machine using NAT (virt-network) refer to 192.168.122.1(host) as the dns

and the host is using the dnsmasq to provide that service

I would like to add an mx record to that server 

when I opened up the /etc/dnsmasq.conf I found everything was commented out

thanks

----------

## Adel Ahmed

help anyone

----------

## NeddySeagoon

Adel Ahmed,

Your libvirt network settings are stored in /etc/libvirt/qemu/networks/

If you only have one entry, edit it with  

```
virsh net-edit default
```

not with $EDITOR

I'm not sure why you would want to add an MX record there though. That's something you add to a DNS nameserver

You add an MX record to point to your server.  That implies you have a public IP which you DNAT to your virtual host, or at the very least, port 25. 

DNAT in this way is a job for iptables.

Tell us your actual problem rather than your perceived solution.

----------

## Adel Ahmed

I'm studying for the RHCE exam, and I thought I would setup an internal mail delivery system as practice for the exam

I would like to send emails within the domain(subnet) using postfix

I appreciate your assistance

----------

## NeddySeagoon

Adel Ahmed,

You need to have a nameserver with a MX record that paints to the public IP of your mailserver, if you want to receive mail from the big bad internet.

That makes things easier as the nameserver probably exists anyway.

If you will just do this on a private closed network, you need to run your own nameserver.

Hosts that will send/fetch  mail need to use it as one of their nameservers.

nameservers are not trivial to sent up so for testing, you can use /etc/hosts to do name to IP address resolution.    /etc/hosts will need to be populated on every mail sender/fetcher.

On you KVM host, you need either an IP, which you DNAT to the KVM (all ports) or you use the KVM hosts IP and DNAT email ports to your KVM.

Either way, you need iptables to do the DNAT and forwarding.

Now your mailserver on your KVM can receive emails from the outside world and deliver them to user accounts on the mailserver.

Users can collect their mail with pop3 or whatever.

You can doubtless ssh into the KVM host and from the KVM host to the KVM itself.

A good first step is to set up iptables so that you can ssh to the KVM directly from elsewhere on the network.

Hint: If you share the KVM hosts IP address, do not use port 22 for the guest, or you will no longer be able to reach the host.

You need both DNAT and forwarding.  You also need to configure ssh on the KVM to listen on an additional port, other than 22.

After this works,  its the same only different ports for your email services.

Once the network is in place, the mail server setup is standard.  It has no idea its being hosted on a KVM.

----------

## Adel Ahmed

that's a good idea, I have configured a bind server on one of the hosts and I'm getting other sorts of problems now, this problem is solved for now

thanks

----------

