Create a new file called new-network.xml
with the following content:
<network>
<name>custom-net</name>
<bridge name='virbr10'/>
<forward mode='nat'/>
<ip address='192.168.100.1' netmask='255.255.255.0'/>
</network>
Run the following commands to create and activate the network:
# Define the new network
virsh net-define new-network.xml
# Start the network
virsh net-start custom-net
# Make it persistent
virsh net-autostart custom-net
Verify the network is active:
virsh net-list --all
To confirm your VMs are running, use:
virsh list
Example output:
Id Name State
-------------------------------
2 ocp-master-0 running
3 ocp-master-1 running
4 ocp-master-2 running
5 ocp-compute-0 running
6 ocp-compute-1 running
7 ocp-compute-2 running
Run the following loop to attach the custom-net
network to all OpenShift VMs:
for vm in ocp-master-0 ocp-master-1 ocp-master-2 ocp-compute-0 ocp-compute-1 ocp-compute-2; do
virsh attach-interface --domain $vm --type network --source custom-net --model virtio --persistent
done
This will add a new network interface to each VM.
To confirm that the network interface has been added, check the interface list of any VM:
virsh domiflist ocp-master-0
Example output:
Interface Type Source Model MAC
---------------------------------------------------
vnet0 network default virtio 52:54:00:12:34:56
vnet1 network custom-net virtio 52:54:00:65:43:21