Hack and / - Bond, Ethernet Bond
The next step is to configure the bonding module with the bonding mode you want to use, along with any other options you might want to set for that module. On a Red Hat system, you will edit either /etc/modprobe.conf (for a 2.6 kernel) or /etc/modules.conf (for an older 2.4 kernel). On a Debian-based system, edit or create the /etc/modprobe.d/aliases file. In either case, add the following lines:
alias bond0 bonding options bonding mode=1 miimon=100
The alias line will associate the bond0 network interface with the bonding module. If you intend on having multiple bonded interfaces (such as on a system with four or more NICs), you will need to add an extra alias line for bond1 or any other interfaces. The options line allows me to set my bonding mode to 1 as well as set miimon (how often the kernel will check the link state of the interface in milliseconds).
Like with module configuration, different distributions handle network configuration quite differently, and that's true for bonded interfaces as well. So, at this point, it's best if I describe each system separately.
Red Hat network configuration is managed via files under /etc/sysconfig/network-scripts. Each interface has its own configuration file preceded by ifcfg-, so that the configuration for eth0 can be found in /etc/sysconfig/network-scripts/ifcfg-eth0. To configure bonding, you simply can use the basic network settings you would have for your regular interface, only now they will be found in ifcfg-bond0:
DEVICE=bond0 NETMASK=255.255.255.0 GATEWAY=192.168.19.1 BOOTPROTO=static IPADDR=192.168.19.64 HOSTNAME=goldfinger.example.net ONBOOT=yes
Next, each interface you want to use for bond0 needs to be configured. In my case, if I wanted to bond eth0 and eth1, I would put the following into ifcfg-eth0:
DEVICE=eth0 USERCTL=no ONBOOT=yes MASTER=bond0 SLAVE=yes BOOTPROTO=none
and the following into ifcfg-eth1:
DEVICE=eth1 USERCTL=no ONBOOT=yes MASTER=bond0 SLAVE=yes BOOTPROTO=none
Finally, type service network restart as root to restart your network service with the new bonded interface. From this point on, you can treat ifcfg-bond0 as your main configuration file for any network changes (and files like route-bond0 to configure static routes, for instance). To make this even easier for you, I've included a script for Red Hat users that automates this entire process. Run the script with the name of the bonded interface you want to use (such as bond0), follow it with the list of interfaces you want to bond, and it will set up the modules and network interfaces for you automatically based on the configuration it finds in the first interface (such as eth0) that you list. So, for instance, to set up the above configuration, I would make sure that ifcfg-eth0 had the network settings I wanted to use, and then I would run the script shown in Listing 1.
Listing 1. Bond Script for Red Hat Users
# bond bond0 eth0 eth1
#!/usr/bin/perl
# bond -- create a bonded interface out of one or
# more physical interfaces
# Created by Kyle Rankin
#
my $bond_interface = shift;
my @interfaces = @ARGV;
my $network_scripts_path = '/etc/sysconfig/network-scripts/';
my $bond_mode=1;
my $bond_miimon=100;
my $bond_max=2;
usage() unless (@ARGV);
if($#interfaces < 1){
usage("ERROR: You must have at least 2 interfaces to bond!");
}
system("/etc/init.d/network stop");
config_bond_master($bond_interface, $interfaces[0]);
foreach(@interfaces){
config_bond_slave($bond_interface, $_);
}
config_modules($bond_interface, $bond_miimon, $bond_mode);
system("/etc/init.d/network start") or die
↪"Couldn't start networking: $!\n";
sub usage
{
$error = shift;
print "$error\n" if($error);
print "Usage: $0 bond_interface interface1 interface2 [...]\n";
print "\nbond_interface will use the network
↪settings of interface1\n";
exit
}
sub config_bond_master
{
my $bond_interface = shift;
my $main_interface = shift;
my $netconfig_ref = get_network_config($main_interface);
open CONFIG, "> $network_scripts_path/ifcfg-$bond_interface"
↪or die "Can't open
↪$network_scripts_path/ifcfg-$bond_interface: $!\n";
print CONFIG "DEVICE=$bond_interface\n";
foreach(keys %$netconfig_ref){
unless($_ eq "HWADDR" || $_ eq "DEVICE"){
print CONFIG "$_=$$netconfig_ref{$_}\n";
}
}
close CONFIG;
}
sub config_bond_slave
{
my $bond_interface = shift;
my $slave_interface = shift;
my $netconfig_ref = get_network_config($slave_interface);
open CONFIG, "> $network_scripts_path/ifcfg-$slave_interface"
↪or die "Can't open
↪$network_scripts_path/ifcfg-$slave_interface: $!\n";
print CONFIG <<"EOC";
DEVICE=$slave_interface
USERCTL=no
ONBOOT=yes
MASTER=$bond_interface
SLAVE=yes
BOOTPROTO=none
EOC
if($$netconfig_ref{'HWADDR'}){
print CONFIG "HWADDR=$$netconfig_ref{'HWADDR'}";
}
}
# This subroutine returns a hash with key-value pairs matching
# the network configuration for the interface passed as an
# argument according to the configuration file in
# /etc/sysconfig/network-scripts/ifcfg-interface
sub get_network_config
{
my $interface = shift;
my %netconfig;
open(CONFIG, "$network_scripts_path/ifcfg-$interface")
↪or die "Can't open
↪$network_scripts_path/ifcfg-$interface: $!\n";
while(<CONFIG>)
{
chomp;
($key, $value) = split '=';
$netconfig{uc($key)} = $value;
}
close CONFIG;
return \%netconfig;
}
sub config_modules
{
my $bond_interface = shift;
my $bond_miimon = shift;
my $bond_mode = shift;
my $bond_options_configured = 0;
my $bond_alias_configured = 0;
if(-f "/etc/modprobe.conf"){ # for 2.6 kernels
$module_config = "/etc/modprobe.conf";
}
else {
$module_config = "/etc/modules.conf";
}
open CONFIG, "$module_config" or die
↪"Can't open $module_config: $!\n";
while(<CONFIG>){
if(/options bonding/){ $bond_options_configured = 1; }
if(/alias $bond_interface bonding/){
↪$bond_alias_configured = 1; }
}
close CONFIG;
open CONFIG, ">> $module_config" or die
↪"Can't open $module_config: $!\n";
unless($bond_alias_configured)
{
print CONFIG "alias $bond_interface bonding\n";
}
unless($bond_options_configured)
{
print CONFIG "options bonding
↪miimon=$bond_miimon mode=$bond_mode max_bonds=$bond_max\n";
}
close CONFIG;
}
Kyle Rankin is a systems architect; and the author of DevOps Troubleshooting, The Official Ubuntu Server Book, Knoppix Hacks, Knoppix Pocket Reference, Linux Multimedia Hacks, and Ubuntu Hacks.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- I once had a better way I
3 hours 12 min ago - Not only you I too assumed
3 hours 29 min ago - another very interesting
5 hours 22 min ago - Reply to comment | Linux Journal
7 hours 16 min ago - Reply to comment | Linux Journal
14 hours 10 min ago - Reply to comment | Linux Journal
14 hours 26 min ago - Favorite (and easily brute-forced) pw's
16 hours 17 min ago - Have you tried Boxen? It's a
22 hours 9 min ago - seo services in india
1 day 2 hours ago - For KDE install kio-mtp
1 day 2 hours ago




Comments
Good Article
Wew, good work :D
Keep posting . . .
Hack? Are hack legal?
I think No . . .
http://earlan.info/
http://earlan.info/