Updated mkchbond.pl
By joe
- 5 minutes read - 874 wordsOur mkchbond.pl script automates the creation of channel bond entries in Redhat and now SuSE Linux. Its primary reason for existing is to automate a process that is editing intensive, and somewhat annoying. It also provides dry runs by default, you have to tell it to –write a file before it will touch anything.
For example: to create a 4 way channel bond named bond0 out of eth2, eth3, eth4, eth5, with an IP address of the bond as 192.168.10.1, netmask of 255.255.255.0, network of 192.168.10.0, … we would do the following.
gradient:~ # ./mkchbond.pl --bond=bond0 --eth=eth2,eth3,eth4,eth5 --ip=192.168.10.1 --netmask=255.255.255.0 --network=192.168.10.0 --broadcast=192.168.10.255
SuSE detected ...
mkchbond.pl: v0.9 Create channel bonds easily
by Joe Landman (http://scalableinformatics.com)
This software is Copyright (c) 2005-2007 by Scalable Informatics
and licensed under GPL v2.0 only. You may freely distribute this
software under the terms and conditions of the GPL 2.0 license.
You may not alter, remove, or prevent printing of the copyright
notice and information.
---- Would append the following to file '/etc/modprobe.conf.local' up to EOM -----
alias bond0 bonding
options bonding mode=6 miimon=100 downdelay=300 updelay=300 max_bonds=2
---- EOM -----
---- Would write the following to file '/etc/sysconfig/network/ifcfg-bond0' up to EOM ----
DEVICE=bond0
IPADDR=192.168.10.1
NETMASK=255.255.255.0
NETWORK=192.168.10.0
BROADCAST=192.168.10.255
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
BONDING_MASTER=yes
BONDING_SLAVE1='eth2'
BONDING_SLAVE2='eth3'
BONDING_SLAVE3='eth4'
BONDING_SLAVE4='eth5'
---- EOM ----
---- Would write the following to file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e0' up to EOM ----
DEVICE=eth2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
STARTMODE='off'
UNIQUE='mY_N.CJRVzKFlRo8'
NAME='Intel 82546GB PRO/1000 GT Quad Port Server Adapter'
_nm_name='bus-pci-0000:0b:04.0'
---- EOM ----
---- Would write the following to file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e1' up to EOM ----
DEVICE=eth3
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
STARTMODE='off'
UNIQUE='DkES.CJRVzKFlRo8'
NAME='Intel 82546GB PRO/1000 GT Quad Port Server Adapter'
_nm_name='bus-pci-0000:0b:04.1'
---- EOM ----
---- Would write the following to file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e2' up to EOM ----
DEVICE=eth4
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
STARTMODE='off'
UNIQUE='gvUW.CJRVzKFlRo8'
NAME='Intel 82546GB PRO/1000 GT Quad Port Server Adapter'
_nm_name='bus-pci-0000:0b:06.0'
---- EOM ----
---- Would write the following to file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e3' up to EOM ----
DEVICE=eth5
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes
STARTMODE='off'
UNIQUE='75la.CJRVzKFlRo8'
NAME='Intel 82546GB PRO/1000 GT Quad Port Server Adapter'
_nm_name='bus-pci-0000:0b:06.1'
---- EOM ----
of course, applying the –write option writes all of this to disk
gradient:~ # ./mkchbond.pl --bond=bond0 --eth=eth2,eth3,eth4,eth5 --ip=192.168.10.1 --netmask=255.255.255.0 --network=192.168.10.0 --broadcast=192.168.10.255 --write
SuSE detected ...
mkchbond.pl: v0.9 Create channel bonds easily
by Joe Landman (http://scalableinformatics.com)
This software is Copyright (c) 2005-2007 by Scalable Informatics
and licensed under GPL v2.0 only. You may freely distribute this
software under the terms and conditions of the GPL 2.0 license.
You may not alter, remove, or prevent printing of the copyright
notice and information.
opening file '/etc/modprobe.conf.local' for appending
closing file '/etc/modprobe.conf.local'
opening file '/etc/sysconfig/network/ifcfg-bond0' for writing
closing file '/etc/sysconfig/network/ifcfg-bond0'
opening file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e0' for writing
closing file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e0'
opening file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e1' for writing
closing file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e1'
opening file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e2' for writing
closing file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e2'
opening file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e3' for writing
closing file '/etc/sysconfig/network/ifcfg-eth-id-00:0e:0c:cf:18:e3'
And then as a sanity check
gradient:~ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:30:48:57:A6:F6
inet addr:192.168.1.53 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3609534 errors:0 dropped:0 overruns:0 frame:0
TX packets:2096592 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:4925501341 (4697.3 Mb) TX bytes:466784632 (445.1 Mb)
Base address:0xdc00 Memory:cfee0000-cff00000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:594902 errors:0 dropped:0 overruns:0 frame:0
TX packets:594902 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:375086547 (357.7 Mb) TX bytes:375086547 (357.7 Mb)
now lets bring up the bond
gradient:~ # ifup bond0
bond0
bond0 enslaving interfaces: eth2 eth3 eth4 eth5
gradient:~ # ifconfig
bond0 Link encap:Ethernet HWaddr 00:0E:0C:CF:18:E0
inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST MASTER MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
eth0 Link encap:Ethernet HWaddr 00:30:48:57:A6:F6
inet addr:192.168.1.53 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3609595 errors:0 dropped:0 overruns:0 frame:0
TX packets:2096626 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:4925507503 (4697.3 Mb) TX bytes:466790734 (445.1 Mb)
Base address:0xdc00 Memory:cfee0000-cff00000
eth2 Link encap:Ethernet HWaddr 00:0E:0C:CF:18:E0
UP BROADCAST SLAVE MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Base address:0xec00 Memory:cffe0000-d0000000
eth3 Link encap:Ethernet HWaddr 00:0E:0C:CF:18:E1
UP BROADCAST SLAVE MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Base address:0xe880 Memory:cffc0000-cffe0000
eth4 Link encap:Ethernet HWaddr 00:0E:0C:CF:18:E2
UP BROADCAST SLAVE MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Base address:0xe800 Memory:cffa0000-cffc0000
eth5 Link encap:Ethernet HWaddr 00:0E:0C:CF:18:E3
UP BROADCAST SLAVE MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Base address:0xe480 Memory:cff80000-cffa0000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:594902 errors:0 dropped:0 overruns:0 frame:0
TX packets:594902 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:375086547 (357.7 Mb) TX bytes:375086547 (357.7 Mb)
It does all its magic in the distribution appropriate directories. Backing up the files it changed with a time stamp in the name. Neat, huh? mkchbond.pl is GPL2 based. Use it in your distro of choice. We will be making it work in Ubuntu/Debian shortly.