Reason
Predictable IP placement of virtual machines is useful when performing repeated test of network software.Environment:
This post was developed on Fedora Core 29 but should work on other recent Fedora/CentOS/RHEL OS releases.Pre-reqs
A non-root user with sudo access was used to query and configure libvirtIn this example, four virtual machines are used and connected to the default libvirt network. The virtual machines are configured for DHCP.
Network Configuration Diagram
baseOS<->|
|<->vmos1
libvirt |<->vmos2
default |<->vmos3
network |<->vmos4
Network Configuration Command Line
$ sudo virsh net-dumpxml default
<network connections='4'>
<name>default</name>
<uuid>e418d7f8-b770-47e6-9cb0-3d013568b761</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:7a:96:4d'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
Gather the MAC addresses of each VM
The example hosts have only one network interface. If there are multiple interfaces, gather the MAC address attached to the default network. IP address can be defined for other networks by adjusting the below command lines as needed. $ sudo virsh domiflist vmos4
Interface Type Source Model MAC
-------------------------------------------------------
vnet3 network default virtio 52:54:00:d3:3e:e7
Set the mac IP reservation for each MAC address.
Ensure the assigned IP address are available. sudo virsh net-update default add ip-dhcp-host '<host mac="52:54:00:87:c4:d1" ip="192.168.122.3"/>' --live --config
sudo virsh net-update default add ip-dhcp-host '<host mac="52:54:00:57:b0:a6" ip="192.168.122.4"/>' --live --config
sudo virsh net-update default add ip-dhcp-host '<host mac="52:54:00:37:aa:4f" ip="192.168.122.5"/>' --live --config
sudo virsh net-update default add ip-dhcp-host '<host mac="52:54:00:d3:3e:e7" ip="192.168.122.6"/>' --live --config
Display updated network configuration
$ sudo virsh net-dumpxml default
<network connections='4'>
<name>default</name>
<uuid>e418d7f8-b770-47e6-9cb0-3d013568b761</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:7a:96:4d'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
<host mac='52:54:00:87:c4:d1' ip='192.168.122.3'/>
<host mac='52:54:00:57:b0:a6' ip='192.168.122.4'/>
<host mac='52:54:00:37:aa:4f' ip='192.168.122.5'/>
<host mac='52:54:00:d3:3e:e7' ip='192.168.122.6'/>
</dhcp>
</ip>
</network>
Start/Restart each VM as needed.
The interface can be disconnected/reconnected if a restart is not wanted.
$ for f in vmos1 vmow2 vmos3 vmos4 ; do sudo virsh destroy $f ; sleep 5 ; sudo virsh start $f ; done
Update hosts file
The hosts file is updated to ease host access $ cat <<EOF | sudo tee -a /etc/hosts
192.168.122.3 vmos1
192.168.122.4 vmos2
192.168.122.5 vmos3
192.168.122.6 vmos4
EOF
Test connectivity
$ ping -c4 vmos1
PING vmos1 (192.168.122.3) 56(84) bytes of data.
64 bytes from vmos1 (192.168.122.3): icmp_seq=1 ttl=64 time=0.387 ms
64 bytes from vmos1 (192.168.122.3): icmp_seq=2 ttl=64 time=0.418 ms
64 bytes from vmos1 (192.168.122.3): icmp_seq=3 ttl=64 time=0.396 ms
64 bytes from vmos1 (192.168.122.3): icmp_seq=4 ttl=64 time=0.355 ms
--- vmos1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 104ms
rtt min/avg/max/mdev = 0.355/0.389/0.418/0.022 ms
References
Libvirt Networking
Red Hat Virtualization Deployment and Administration Guide
No comments:
Post a Comment