Expand

Blog Navigation

Archive for the ‘Uncategorized’ Category

Bonding two network cards in Ubuntu 10.04

Sunday, October 31st, 2010
By: Andrew

Bonding is the process of aggregating links in Linux (and some other OS’s). You would want to do this if you need either the speed associated with load balancing, or the fault tolerance associated with fail-over. The process is quite easy.

First, install ifenslave. This is the kernel module that allows you to link the Ethernet ports.
sudo apt-get install ifenslave

Second, we must tell the kernel how to use this driver. In Ubuntu 10.04, use this command:
sudo vi /etc/modprobe.d/ifenslave.conf

Add the lines:
alias bond0 bonding
options bonding mode=6 miimon=100 downdelay=200 updelay=200

Make sure you change the mode to the desired type: mode 6 is adaptive load balancing, which is likely great for your application.

Third, edit the file /etc/network/interfaces and comment out your “eth 0 and 1″
sudo vi /etc/network/interfaces

Add a static ip:

iface bond0 inet static
address 10.1.1.100
netmask 255.255.255.0
network 10.1.1.0
gateway 10.1.1.254
up /sbin/ifenslave bond0 eth0 eth1
down /sbin/ifenslave -d bond0 eth0 eth1

Restart networking or the machine and you are done.
reboot

The ways to combine network cards in a machine.

Monday, July 12th, 2010
By: Andrew

According to Intel, here are 6 ways to combine the network cards in a machine. This was originally posted on Intel’s site, but they have taken it down or moved it. I am trying to find a more detailed reference on how each of these modes work and which is best in which scenarios.

1. Adapter Fault Tolerance (AFT) – provides automatic redundancy for your
server’s network connection. If the primary adapter fails, the secondary
adapter takes over. Adapter Fault Tolerance supports two to eight adapters
per team. This teaming mode works with any hub or switch, and all team
members must be connected to the same device.

2. Switch Fault Tolerance (SFT) – provides a failover relationship
between two adapters when each adapter is connected to a separate switch.
Switch Fault Tolerance supports two adapters per team. Spanning Tree
Protocol (STP) must be enabled when you create a team in SFT mode. SFT is
only available on computers running Windows NT* 4.0, Windows* XP, and
Windows 2000. This teaming mode works with any switch.

3. Adaptive load balancing (ALB) – provides load balancing of transmit
traffic and adapter fault tolerance. In Windows operating systems, you can
also enable or disable receive load balancing (RLB) in ALB teams. This
teaming mode works with any switch. This also work in Linux.

4. FEC/Link Aggregation/802.3ad: static mode – provides increased
transmission and reception throughput in a team of two to eight adapters
operating at 100 Mbps. This mode also includes adapter fault tolerance and
load balancing (only routed protocols). This teaming mode requires a switch
with Intel’s Link Aggregation or Cisco’s FEC capability.

5. GEC/Link Aggregation/802.3ad: static mode – is the gigabit extension
of the FEC/Link Aggregation/802.3ad: static mode. All team members must
operate at gigabit speeds. FEC/GEC is used by the Mac pro in OSX.

6. IEEE 802.3ad: dynamic mode – creates one or more teams using dynamic
Link Aggregation with mixed-speed adapters. Like the static Link Aggregation
modes, Dynamic 802.3ad teams increase transmission and reception throughput
and provide fault tolerance. This teaming mode requires a switch that fully
supports the IEEE 802.3ad standard.

Debian/Ubuntu change eth1 back to eth0

Friday, May 14th, 2010
By: Andrew

Many times I have needed to change network cards on a linux box, or I move a virtual machine and the nic mapping changes from eth0 to eth1. Thankfully it is really easy to fix if you just know where to look.

sudo vi /etc/udev/rules.d/70-persistent-net.rules

My example shows the two cards. The top one is the old card – no longer installed; the bottom one the new.

What you do is delete the top card from the list, and change the mapping on the bottom card to eth0.

:wq to save and exit and reboot. Congratulations! You have changed the network card mapping.

Creating multiple default routes in Linux

Tuesday, May 11th, 2010
By: Andrew

I have recently been toying with multiple ethernet interfaces on completely different vlans for security purposes, and have been struggling to figure this out. I found millions of articles on the web of how to play with iptables and routes, but virtually none that address this simple problem. Consider this example:

Eth0 10.10.1.10/24 gw 10.10.1.10
Eth1 10.1.51.200/24 gw 10.1.51.1

The default gateways for both lans are the same router.

$ netstat -anr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.10.1.0       0.0.0.0         255.255.255.0   U         0 0          0 eth0
10.1.51.0       0.0.0.0         255.255.255.0   U         0 0          0 eth1
0.0.0.0         10.10.1.1       0.0.0.0         UG        0 0          0 eth0

By default, Linux allows you to specify ONE default gateway on your primary nic, in this case eth0. This is a huge problem in this scenario, because you cannot be assured that traffic intended for eth1 will come to eth1. Everyone gets confused and trys to send the data to eth0 which they either can’t see or they are forced to use the router to translate the vlans and subnets. Epic Fail. For all intents, this server is using the one default route on eth0.

How to fix it.

Borrowing the method from this website, we create a policy route.  I am using Ubuntu 10.04 Server 64bit in this example which has kernel support for “policy routing” If you are on a modern Debian or Ubuntu system (k 2.6.26 or newer), this should be there already.  Don’t know about the other distros, but they should be similar.

sudo vi /etc/iproute2/rt_tables

add “1 internal” to the bottom. This creates a policy table for the internal network on eth0.

This table starts out empty so we need to give it some information about the network eth0 is on.  My eth0 is 10.10.1.10 and my gateway is 10.10.1.1.

ip route add 10.10.1.0/24 dev eth0 src 10.10.1.10 table internal
ip route add default via 10.10.1.1 dev eth0 table internal

Great. We have created the route table for eth0. Now we need to tell the kernel how to use this policy with an ip rule

Ubuntu seems to forget them on restart, and I want these to come back every time the computer is restarted so I put them in /etc/rc.local
sudo vi /etc/rc.local
Add the following lines before exit:
ip rule add from 10.10.1.10/32 table internal
ip rule add to 10.10.1.10/32 table internal

Nothing has happened yet because we told these rules to be created and applied at bootup, so restart. You should now be able to see the rules with ip rule show
Congratulations! You’re system should now properly route traffic. Repeat the process as necessary.

Read command line with Perl

Saturday, March 20th, 2010
By: Andrew

So I am often confronted with needing to retrieve the output from a system() command. Up until this point, I have done what most do and write it to a file using >> and then open that file. This is not a very quick or elegant way to do it as you are waiting on the disk the whole time. Then I ran across this yesterday. Simply use the pipe! I needed to get the output of df and do some formatting.

Example:

#output of "df"
open(CMD, "df |");
while (<CMD>) {
chomp;
$temp = $_;
if ($temp =~ m/Filesystem/) {next;}
if ($temp =~ s/\s+/,/g){
$df .= $temp ."|";
}else{$df .= $temp;}
}
close CMD;
chop($df);

That is all there is to it. Quick and elegant.

WordPress issues

Thursday, March 13th, 2008
By: Andrew

I have been having major wordpress issues. Every post I make it says is invalid and won’t save. Not a fun time to be sure. I think it is now working again.

(more…)

WME file creation script done

Friday, September 21st, 2007
By: Andrew

Finally! I have been saying that I would write this script, and now it is done. The problem that I have been having is that I want to batch convert a LOT (4,500+)  files from various formats to WMV. Not hard at all, but freakin’ time consuming to use the Microsoft Windows Media Encoder tool to create every file and update the meta data. (more…)

Stupid Dog, but so cute

Monday, July 30th, 2007
By: Andrew

I love my dog, but sometimes she annoys me. For the last 2 months she and I have been going on a 4 mile run each morning. (I ride the bike, `cause she is way to fast for me.) Since we have had her, she has had a mortal fear of storm drains. (more…)

HUGE Houses

Friday, June 29th, 2007
By: Andrew

I was in Southlake, TX yesterday visiting the Timerron golf course, and I saw some of the most extravagant houses I had ever seen. (more…)