===== Virt KVM ====
==== reference ====
* https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/sect-Virtualization_Host_Configuration_and_Guest_Installation_Guide-Host_Installation-Installing_KVM_packages_on_an_existing_Red_Hat_Enterprise_Linux_system.html
==== install packages ====
[root@localhost ~]# yum groupinstall Virtualization
[root@localhost ~]# yum groupinstall "Virtualization Client"
[root@localhost ~]# service libvirtd status
==== VM pfsense ====
[root@localhost ~]# qemu-img create -f qcow2 /vm/kvm/pfsense.qcow2 10G
[root@localhost iso]# virt-install --vcpus=1 --ram=1024 --name=pfsense --file=/vm/kvm/pfsense.qcow2 --cdrom=/vm/iso/pfSense-CE-2.3.2-RELEASE-amd64.iso --hvm --vnc --network bridge:virbr0
==== information reseau pfsense ====
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.5254005d4f0b yes virbr0-nic
vnet0
[root@localhost ~]# ip addr
...
3: virbr0: mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 52:54:00:5d:4e:0a brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
link/ether 52:54:00:5d:4e:0a brd ff:ff:ff:ff:ff:ff
6: vnet0: mtu 1500 qdisc pfifo_fast master virbr0 state UNKNOWN qlen 1000
link/ether fe:54:00:ad:70:82 brd ff:ff:ff:ff:ff:ff
inet6 fe80::fc54:ff:fead:7082/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# nmap -sP 192.168.122.0/24
Starting Nmap 6.40 ( http://nmap.org ) at 2016-12-18 13:04 CET
Nmap scan report for 192.168.122.148
Host is up (0.00021s latency).
MAC Address: 52:54:00:AD:70:82 (QEMU Virtual NIC)
Nmap scan report for 192.168.122.1
Host is up.
Nmap done: 256 IP addresses (2 hosts up) scanned in 4.68 seconds
[root@localhost ~]# nmap 192.168.122.148
Starting Nmap 6.40 ( http://nmap.org ) at 2016-12-18 13:05 CET
Nmap scan report for 192.168.122.148
Host is up (0.00030s latency).
Not shown: 997 filtered ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
MAC Address: 52:54:00:AD:70:82 (QEMU Virtual NIC)
===== network =====
* https://wiki.libvirt.org/page/VirtualNetworking
* https://seravo.fi/2012/virtualized-bridged-networking-with-macvtap
* https://www.techotopia.com/index.php/Creating_a_CentOS_6_KVM_Networked_Bridge_Interface
* http://www.rendoumi.com/xu-ni-hua-wang-luo-bi-jiao-tun-tap-macvlan-macvtap/
[root@localhost ~]# virsh net-dumpxml default
default
048b8b48-18f5-4100-a708-c19df66bfabd
locatio of xml file
[root@localhost ~]# ls /etc/libvirt/qemu/networks/
autostart default.xml
==== dnsmasq ====
lancé automatiquement par libvirt pour assurer la passralle DNS/DHCP
[root@localhost ~]# cat /var/lib/libvirt/dnsmasq/default.conf
##WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
##OVERWRITTEN AND LOST. Changes to this configuration should be made using:
## virsh net-edit default
## or other application using the libvirt API.
##
## dnsmasq conf file created by libvirt
strict-order
pid-file=/var/run/libvirt/network/default.pid
except-interface=lo
bind-dynamic
interface=virbr0
dhcp-range=192.168.122.2,192.168.122.254
dhcp-no-override
dhcp-lease-max=253
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts
[root@localhost ~]# cat /var/lib/libvirt/dnsmasq/default.hostsfile
==== add 2nd network on specific NIC ====
* https://doc.opensuse.org/documentation/leap/virtualization/html/book.virt/cha.libvirt.networks.html
* https://kashyapc.fedorapeople.org/virt/create-a-new-libvirt-bridge.txt
definition manuelle du nouveau reseau
[root@localhost ~]# cat /root/p4p1-net.xml
p4p1_routed
[root@localhost ~]# virsh net-list --all
Nom État Démarrage automatique Persistent
----------------------------------------------------------
default actif yes yes
[root@localhost ~]# virsh net-define p4p1-net.xml
Réseau p4p1_routed défini depuis p4p1-net.xml
[root@localhost ~]# virsh net-list --all
Nom État Démarrage automatique Persistent
----------------------------------------------------------
default actif yes yes
p4p1_routed inactif no yes
[root@localhost ~]# virsh net-start p4p1_routed
Réseau p4p1_routed démarré
[root@localhost ~]# virsh net-list --all
Nom État Démarrage automatique Persistent
----------------------------------------------------------
default actif yes yes
p4p1_routed actif no yes
[root@localhost ~]# virsh net-autostart p4p1_routed
Réseau p4p1_routed marqué en démarrage automatique
[root@localhost ~]# virsh net-list --all
Nom État Démarrage automatique Persistent
----------------------------------------------------------
default actif yes yes
p4p1_routed actif yes yes
[root@localhost ~]# ls /etc/libvirt/qemu/networks/
autostart default.xml p4p1_routed.xml
[root@localhost ~]# cat /etc/libvirt/qemu/networks/p4p1_routed.xml
p4p1_routed
1d3ddaa8-dffc-4194-a680-07680413daa2
[root@localhost ~]#
==== retrait reseau ====
[root@localhost ~]# virsh net-list --all
Nom État Démarrage automatique Persistent
----------------------------------------------------------
default actif yes yes
p4p1_routed actif yes yes
[root@localhost ~]# virsh net-destroy p4p1_routed
Réseau p4p1_routed détruit
[root@localhost ~]# virsh net-list --all
Nom État Démarrage automatique Persistent
----------------------------------------------------------
default actif yes yes
p4p1_routed inactif yes yes
[root@localhost ~]# virsh net-undefine p4p1_routed
Le réseau p4p1_routed n'est plus défini
[root@localhost ~]# virsh net-list --all
Nom État Démarrage automatique Persistent
----------------------------------------------------------
default actif yes yes
[root@localhost ~]# ls /etc/libvirt/qemu/networks/
autostart default.xml
==== ajout 2eme interface =====
[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.5254005d4f0b yes virbr0-nic
vnet0
virbr1 8000.525400f6a6f4 yes virbr1-nic
[root@localhost ~]# virsh attach-interface --domain pfsense --type bridge --source virbr1 --target eth2 --model virtioInterface attached successfully
[root@localhost ~]# virsh domiflist pfsense
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 bridge virbr0 rtl8139 52:54:00:ad:7a:83
eth2 bridge virbr1 virtio 52:54:00:c9:23:02