Hack and / - Bond, Ethernet Bond

Configure Ethernet bonding and get a license to kill a network interface without any downtime.
Debian Is Forever

As you might imagine, Debian's network configuration is quite different from Red Hat's. Unfortunately, I don't have a Perl script to automate the process for Debian users, but as you will see, it's so simple, a script isn't necessary. All the network configuration for Debian-based servers can be found in /etc/network/interfaces. Here's a sample interfaces file:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
  address 192.168.19.64
  netmask 255.255.255.0
  gateway 192.168.19.1

To configure a bonded interface, I simply comment out all of the configuration settings for eth0 and create a new configuration for bond0 that copies all of eth0's settings. The only change I make is the addition of an extra parameter called slaves that lists which interfaces should be used for this bonded interface:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto eth0
#iface eth0 inet static
#  address 192.168.19.64
#  netmask 255.255.255.0
#  gateway 192.168.19.1

auto bond0
iface bond0 inet static
  address 192.168.19.64
  netmask 255.255.255.0
  gateway 192.168.19.1
  slaves eth0 eth1

Once you have made the changes, type sudo service networking restart or sudo /etc/init.d/networking restart to restart your network interface.

No matter whether you use Red Hat or Debian, once you have configured the bonded interface, you can use the ifconfig command to see that it has been configured:

$ sudo ifconfig
bond0	Link encap:Ethernet HWaddr 00:0c:29:28:13:3b
	inet addr:192.168.19.64 Bcast:192.168.0.255
	Mask:255.255.255.0
	inet6 addr: fe80::20c:29ff:fe28:133b/64 Scope:Link
	UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
	RX packets:38 errors:0 dropped:0 overruns:0 frame:0
	TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
	collisions:0 txqueuelen:0
	RX bytes:16644 (16.2 KB) TX bytes:3282 (3.2 KB)

eth0	Link encap:Ethernet HWaddr 00:0c:29:28:13:3b
	UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
	RX packets:37 errors:0 dropped:0 overruns:0 frame:0
	TX packets:43 errors:0 dropped:0 overruns:0 carrier:0
	collisions:0 txqueuelen:1000
	RX bytes:16584 (16.1 KB) TX bytes:3282 (3.2 KB)
	Interrupt:17 Base address:0x1400

eth1	Link encap:Ethernet HWaddr 00:0c:29:28:13:3b
	UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
	RX packets:1 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:60 (60.0 B) TX bytes:0 (0.0 B)
	Interrupt:18 Base address:0x1480

lo	Link encap:Local Loopback
	inet addr:127.0.0.1 Mask:255.0.0.0
	inet6 addr: ::1/128 Scope:Host
	UP LOOPBACK RUNNING MTU:16436 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)

Once the bonded interface is enabled, you can ping the server from a remote host and test that it fails over when you unplug one of the Ethernet cables. Any failures should be logged both in dmesg (/var/log/dmesg) and in the syslog (/var/log/messages or /var/log/syslog) and would look something like this:

Oct 04 16:43:28 goldfinger kernel: [ 2901.700054] eth0: link down
Oct 04 16:43:29 goldfinger kernel: [ 2901.731190] bonding: bond0:
link status definitely down for interface eth0, disabling it
Oct 04 16:43:29 goldfinger kernel: [ 2901.731300] bonding: bond0:
making interface eth1 the new active one.

As I said earlier, I highly recommend you experiment with each bonding mode and with different types of failures, so you can see how each handles both failures and recoveries on your network. When your system is more tolerant of failures, you'll find you are more tolerant of your system.

Kyle Rankin is a Systems Architect in the San Francisco Bay Area and the author of a number of books, including The Official Ubuntu Server Book, Knoppix Hacks and Ubuntu Hacks. He is currently the president of the North Bay Linux Users' Group.

______________________

Kyle Rankin is a director of engineering operations in the San Francisco Bay Area, the author of a number of books including DevOps Troubleshooting and The Official Ubuntu Server Book, and is a columnist for Linux Journal.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Good Article

earlan's picture

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

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

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.

Learn More

Sponsored by Storix