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.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
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: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.
| 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 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- RSS Feeds
- New Products
- Trying to Tame the Tablet
- What's the tweeting protocol?
- Dart: a New Web Programming Experience
- Drupal is an Awesome CMS and a Crappy development framework
3 hours 45 min ago - IT industry leaders
6 hours 8 min ago - Reply to comment | Linux Journal
22 hours 56 min ago - Reply to comment | Linux Journal
1 day 1 hour ago - Reply to comment | Linux Journal
1 day 2 hours ago - great post
1 day 3 hours ago - Google Docs
1 day 3 hours ago - Reply to comment | Linux Journal
1 day 8 hours ago - Reply to comment | Linux Journal
1 day 9 hours ago - Web Hosting IQ
1 day 10 hours ago




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