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:29] admin |
kvm:bridge_interface [2021/04/09 10:40] (current) admin |
||
---|---|---|---|
Line 102: | Line 102: | ||
</code> | </code> | ||
- | In this configuration second interface eth1 and br2 will not be accessible outside. | + | <note warning>In this configuration second interface eth1 and br2 will not be accessible outside.</note> |
- | We need to to add route and rule : | + | |
- | + | <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> | ||
- | <note important>If you want to after reboot or restart network service save bridge configuration</note> | ||
<code bash> | <code bash> |