This is an old revision of the document!
By default dhcpd based network bridge configured by libvirtd. You can verify that with the following commands:
# brctl show # virsh net-list
KVM default networking All VMs (guest machine) only have network access to other VMs on the same server. A private network 192.168.122.0/24 created for you. Verify it:
# virsh net-dumpxml default
If you want your VMs avilable to other servers on your LAN, setup a a network bridge on the server that connected to the your LAN.
Update your nic config file such as ifcfg-enp3s0 or em1: # vi /etc/sysconfig/network-scripts/enp3s0
Add line:
BRIDGE=br0
Save and close the file in vi. Edit /etc/sysconfig/network-scripts/ifcfg-br0 and add:
# vi /etc/sysconfig/network-scripts/ifcfg-br0
Append the following:
DEVICE="br0" # I am getting ip from DHCP server # BOOTPROTO="dhcp" IPV6INIT="yes" IPV6_AUTOCONF="yes" ONBOOT="yes" TYPE="Bridge" DELAY="0"
Restart the networking service (warning ssh command will disconnect, it is better to reboot the box):
# systemctl restart NetworkManager
Verify it with brctl command:
# brctl show
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-br1 DEVICE="br1" ONBOOT="yes" TYPE="Bridge" BOOTPROTO="none" IPADDR="10.5.22.51" NETMASK="255.255.255.0" GATEWAY="10.5.22.254" IPV6INIT="yes" IPV6_AUTOCONF="yes" DHCPV6C="no" STP="on" DELAY="0.0"
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-br2 DEVICE="br2" ONBOOT="yes" TYPE="Bridge" BOOTPROTO="none" IPADDR="10.5.23.10" NETMASK="255.255.255.0" IPV6INIT="yes" IPV6_AUTOCONF="yes" DHCPV6C="no" STP="on" DELAY="0.0"
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ONBOOT=yes BRIDGE="br1"
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 ONBOOT=yes BRIDGE="br2"
To use a second interface and address we need to add another routing table.
To do this go to file:
# vim /etc/iproute2/rt_tables
and add at the end “1 rt2”:
# # reserved values # 255 local 254 main 253 default 0 unspec # # local # #1 inr.ruhep 1 rt2
Now we need to add routing rules and routes:
ip route add default via 10.5.23.254 dev br2 table rt2; ip rule add from 10.5.23.0/24 table rt2
You can check these changes with commands:
# ip route show table rt2 # ip rule show
Find the ifup-post under /etc/sysconfig/network-scripts. This scipt is called right after any network interface is brought up online. In this script, you will find the following code snippet toward the end.
if [ -x /sbin/ifup-local ]; then /sbin/ifup-local ${DEVICE}
In the code snippet above, if ifup-local script exists in /sbin location, then script gets executed with an interface name in argument. Usually no such ecript like ifup-local exists so in order to run a startup script automatically after a network interface is up. Create an executable script called ifup-local in /sbin and put in there any command or script you wish to run.
Here is an example:
if [[ "$1" == "eth0" ]] then echo "this part will be executed right after eth0 is up." echo "so you can put any startup command for eth0 here" else #DO_NOTHING fi
when script is done, use command to get the script executable.
$ sudo chmod +x /sbin/ifup-local
[root@localhost ~]# cat /sbin/ifup-local #!/bin/sh ip route add default via 10.5.23.254 dev br2 table rt2; ip rule add from 10.5.23.0/24 table rt2