Thursday, June 1, 2017

Setting up DNS resolution for KVM/libvirt guests locally


I decide write this post after realize a few labs in my notebook for poc's purposes, this very useful in case what you don't need setup a complex DNS server (bind), So, Bellow there all steps what I've done to take advantage from 'dnsmasq' which already running over the RHEL7 host with libvirt/kvm to configure a DNS Server using /etc/hosts to register all of my guests hosts.

In this example I'm using "example.com" as fictitious domain name locally for kvm environment.

From the hypervisor/host(perspective), steps:


# virsh net-dumpxml default
 
<network connections='1'>
  <name>default</name>
  <uuid>033315b6-ec67-4b09-9870-81cd68113399</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='51:53:00:bc:17:5b'/>
  <domain name='example.com' localOnly='yes'/> 
  <ip address='192.168.0.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.0.2' end='192.168.0.254'/>
    </dhcp>
  </ip>
</network> 


Still in hypervisor KVM, adding names to the instances in the "/etc/hosts" file, all these names will be used for the vms:
  
# vi /etc/hosts
 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 
192.168.0.3  vm3.example.com   vm3
192.168.0.4  vm4.example.com   vm4
192.168.0.5  vm5.example.com   vm5 
192.168.0.6  vm6.example.com   vm6
  
# vi /etc/NetworkManager/conf.d/localdns.conf 
[main] 
dns=dnsmasq
 
# vi /etc/NetworkManager/dnsmasq.d/libvirt_dnsmasq.conf 
server=/example.com/192.168.0.1
 
 
* Restart all relative services like, NetworkManager, dnsmasq, libvirtd.
 
 
After deploy/provisioning instances in the KVM(virt-mananger/virsh), just point out 
resolv.conf to the IP of the hypervisor host server(KVM) in my case (192.168.0.1). 
 

Wednesday, May 31, 2017

Mounting basic filesystem's for RHEL7 troubleshooting



Mounting basic 'fs' to realize Linux troubleshooting in the rescue/recovery/maintenance mode, RHEL>7, CentOS>7.
When grub pop-up set up the kernel to initialize in single mode(1), editing the 'vmlinuz' line adding 'init=/sysroot/bin/bash'.

Bellow all the fs should be mounted to help in the maintenance mode, before 'chroot' the root fs "/".

# mount -t proc none /sysroot/proc
# mount -t sysfs none /sysroot/sys
# mount -t devtmpfs none /sysroot/dev
# mount -t devpts none /sysroot/dev/pts
# mount -t tmpfs none /sysroot//dev/shm
# mount -t tmpfs none /sysroot//run


And then 

# chroot /sysroot/


Reference:

- http://www.itzgeek.com/how-tos/linux/centos-how-tos/single-user-mode-in-centos-7-rhel-7.html