This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
kvm:bridge_interface [2021/04/09 10:10] admin |
kvm:bridge_interface [2021/04/09 10:40] (current) admin |
||
|---|---|---|---|
| Line 55: | Line 55: | ||
| ===== Manual Bridge with static IP ===== | ===== Manual Bridge with static IP ===== | ||
| + | By KVM Virtual Manager can be created bridge interface on each of network interface | ||
| + | {{ :linux:bridge_virt_01.jpg |}} | ||
| + | ==== If you have two LAN interface with two VLAN network ==== | ||
| + | |||
| + | <code bash> | ||
| + | [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" | ||
| + | </code> | ||
| + | <code bash> | ||
| + | [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" | ||
| + | </code> | ||
| + | <code bash> | ||
| + | [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 | ||
| + | DEVICE=eth0 | ||
| + | ONBOOT=yes | ||
| + | BRIDGE="br1" | ||
| + | </code> | ||
| + | <code bash> | ||
| + | [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 | ||
| + | DEVICE=eth1 | ||
| + | ONBOOT=yes | ||
| + | BRIDGE="br2" | ||
| + | </code> | ||
| + | |||
| + | <note warning>In this configuration second interface eth1 and br2 will not be accessible outside.</note> | ||
| + | |||
| + | <note important>To use a second interface and address we need to add another routing table.To do this go to file:</note> | ||
| + | |||
| + | <code bash> | ||
| + | # vim /etc/iproute2/rt_tables | ||
| + | </code> | ||
| + | and add at the end “1 rt2”: | ||
| + | |||
| + | <code winbatch> | ||
| + | # | ||
| + | # reserved values | ||
| + | # | ||
| + | 255 local | ||
| + | 254 main | ||
| + | 253 default | ||
| + | 0 unspec | ||
| + | # | ||
| + | # local | ||
| + | # | ||
| + | #1 inr.ruhep | ||
| + | 1 rt2 | ||
| + | </code> | ||
| + | |||
| + | Now we need to add routing rules and routes: | ||
| + | |||
| + | <code bash> | ||
| + | ip route add default via 10.5.23.254 dev br2 table rt2; | ||
| + | ip rule add from 10.5.23.0/24 table rt2 | ||
| + | </code> | ||
| + | |||
| + | You can check these changes with commands: | ||
| + | |||
| + | <code bash> | ||
| + | # ip route show table rt2 | ||
| + | # ip rule show | ||
| + | </code> | ||
| + | |||
| + | ==== CentOS: Start custom script automatically after network startup ==== | ||
| + | |||
| + | 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. | ||
| + | <code bash> | ||
| + | |||
| + | if [ -x /sbin/ifup-local ]; then | ||
| + | /sbin/ifup-local ${DEVICE} | ||
| + | </code> | ||
| + | |||
| + | 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: | ||
| + | |||
| + | <code bash> | ||
| + | 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 | ||
| + | </code> | ||
| + | |||
| + | when script is done, use command to get the script executable. | ||
| + | |||
| + | <code bash> | ||
| + | $ sudo chmod +x /sbin/ifup-local | ||
| + | </code> | ||
| + | |||
| + | |||
| + | <code bash> | ||
| + | [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 | ||
| + | </code> | ||