ifconfig 0.0.0.0 <
> ifconfig 0.0.0.0 <
> brctl addbr <
> brctl addif <
> brctl addif <
> ifconfig ADINET up brctl addbr ADINET brctl delbr ADINET ifconfig bnep 0 0.0.0.0 ifconfig eth0 0.0.0.0 brctl addbr ADINET brctl addif ADINET bnep0 brctl addif ADINET eth0 ifconfig mybridge up bnep0 : 10.0.66.2 eth0 : ?????1.23.181.121 ifconfig bnep0 10.0.66.2 sudo -i ifconfig bnep0 0.0.0.0 sudo -i ifconfig eth0 0.0.0.0 sudo -i brctl addbr ADINET sudo -i brctl addif ADINET bnep0 sudo -i brctl addif ADINET eth0 sudo -i ifconfig ADINET up sudo /etc/init.d/networking restart route add default gateway dhclient brctl showstp # Configure the bridge device (eth1 is virtual) ifconfig eth0 0.0.0.0 brctl addbr br0 brctl addif br0 eth0 brctl addif br0 eth1 ifconfig br0 192.168.1.151 netmask 255.255.255.0 up ifconfig eth0 up ifconfig eth1 up route add default gw 192.168.1.254 --------------------------------------------------------------- interfaces --------------------------------------------------------------------------- auto lo iface lo inet loopback # Bridge between bnep0 and eth0 auto ADINET iface ADINET inet dhcp # For static configuration delete or comment out the above line and uncomment the following: # iface ADINET inet static # address 192.168.1.10 # netmask 255.255.255.0 # network 192.168.1.0 # gateway 10.0.66.1 # dns-nameservers 192.168.1.5 # dns-search example.com pre-up ifconfig bnep0 down pre-up ifconfig eth0 down pre-up brctl addbr ADINET pre-up brctl addif ADINET bnep0 pre-up brctl addif ADINET eth0 pre-up ifconfig bnep 0 0.0.0.0 pre-up ifconfig eth 0 0.0.0.0 post-down ifconfig bnep0 down post-down ifconfig eth0 down post-down ifconfig ADINET down post-down brctl delif ADINET bnep0 post-down brctl delif ADINET eth0 post-down brctl delbr ADINET -------------------------------------------------------------routing---------------------------------------------------------------------------------------- 4.2. Routing for multiple uplinks/providers A common configuration is the following, in which there are two providers that connect a local network (or even a single machine) to the big Internet. ________ +------------+ / | | | +-------------+ Provider 1 +------- __ | | | / ___/ \_ +------+-------+ +------------+ | _/ \__ | if1 | / / \ | | | | Local network -----+ Linux router | | Internet \_ __/ | | | \__ __/ | if2 | \ \___/ +------+-------+ +------------+ | | | | \ +-------------+ Provider 2 +------- | | | +------------+ \________ There are usually two questions given this setup. 4.2.1. Split access The first is how to route answers to packets coming in over a particular provider, say Provider 1, back out again over that same provider. Let us first set some symbolical names. Let $IF1 be the name of the first interface (if1 in the picture above) and $IF2 the name of the second interface. Then let $IP1 be the IP address associated with $IF1 and $IP2 the IP address associated with $IF2. Next, let $P1 be the IP address of the gateway at Provider 1, and $P2 the IP address of the gateway at provider 2. Finally, let $P1_NET be the IP network $P1 is in, and $P2_NET the IP network $P2 is in. One creates two additional routing tables, say T1 and T2. These are added in /etc/iproute2/rt_tables. Then you set up routing in these tables as follows: ip route add $P1_NET dev $IF1 src $IP1 table T1 ip route add default via $P1 table T1 ip route add $P2_NET dev $IF2 src $IP2 table T2 ip route add default via $P2 table T2 Nothing spectacular, just build a route to the gateway and build a default route via that gateway, as you would do in the case of a single upstream provider, but put the routes in a separate table per provider. Note that the network route suffices, as it tells you how to find any host in that network, which includes the gateway, as specified above. Next you set up the main routing table. It is a good idea to route things to the direct neighbour through the interface connected to that neighbour. Note the `src' arguments, they make sure the right outgoing IP address is chosen. ip route add $P1_NET dev $IF1 src $IP1 ip route add $P2_NET dev $IF2 src $IP2 Then, your preference for default route: ip route add default via $P1 Next, you set up the routing rules. These actually choose what routing table to route with. You want to make sure that you route out a given interface if you already have the corresponding source address: ip rule add from $IP1 table T1 ip rule add from $IP2 table T2 This set of commands makes sure all answers to traffic coming in on a particular interface get answered from that interface. Warning Reader Rod Roark notes: 'If $P0_NET is the local network and $IF0 is its interface, the following additional entries are desirable: ip route add $P0_NET dev $IF0 table T1 ip route add $P2_NET dev $IF2 table T1 ip route add 127.0.0.0/8 dev lo table T1 ip route add $P0_NET dev $IF0 table T2 ip route add $P1_NET dev $IF1 table T2 ip route add 127.0.0.0/8 dev lo table T2 ' Now, this is just the very basic setup. It will work for all processes running on the router itself, and for the local network, if it is masqueraded. If it is not, then you either have IP space from both providers or you are going to want to masquerade to one of the two providers. In both cases you will want to add rules selecting which provider to route out from based on the IP address of the machine in the local network. 4.2.2. Load balancing The second question is how to balance traffic going out over the two providers. This is actually not hard if you already have set up split access as above. Instead of choosing one of the two providers as your default route, you now set up the default route to be a multipath route. In the default kernel this will balance routes over the two providers. It is done as follows (once more building on the example in the section on split-access): ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \ nexthop via $P2 dev $IF2 weight 1 This will balance the routes over both providers. The weight parameters can be tweaked to favor one provider over the other. Note that balancing will not be perfect, as it is route based, and routes are cached. This means that routes to often-used sites will always be over the same provider. Furthermore, if you really want to do this, you probably also want to look at Julian Anastasov's patches at http://www.ssi.bg/~ja/#routes , Julian's route patch page. They will make things nicer to work with. ------------------------------------------------------------------bonding---------------------------------------------------------------------------------- Ethernet Bonding modes The following are the different modes of ethernet bonding you can use. If you want active-backup, in /etc/network/interfaces : bond-mode 1 If you are using the modes for use in modprobe.d ( mode=YOURMODEHERE ): options bonding mode=1 miimon=100 0 (balance-rr) Round-robin policy: Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance. 1 (active-backup) Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode. 2 (balance-xor) XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance. 3 (broadcast) Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance. 4 (802.3ad) IEEE 802.3ad Dynamic link aggregation. Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification. * Pre-requisites: * Ethtool support in the base drivers for retrieving the speed and duplex of each slave. * A switch that supports IEEE 802.3ad Dynamic link aggregation. Most switches will require some type of configuration to enable 802.3ad mode. 5 (balance-tlb) Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave. * Prerequisite: Ethtool support in the base drivers for retrieving the speed of each slave. 6 (balance-alb) Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server. The most used are the first four mode types... Interface Configuration Ubuntu 10.04 and newer sudo vi /etc/network/interfaces Your config file could look something like this # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp auto bond0 iface bond0 inet static address 192.168.1.10 gateway 192.168.1.1 netmask 255.255.255.0 slaves eth1 eth2 # LACP confuration bond_mode 802.3ad bond_miimon 100 bond_lacp_rate 1 Check operation Bond link information is available at /proc/net/bonding/ # cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.5.0 (November 4, 2008) Bonding Mode: IEEE 802.3ad Dynamic link aggregation Transmit Hash Policy: layer2 (0) MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 802.3ad info LACP rate: fast Aggregator selection policy (ad_select): stable bond bond0 has no active aggregator Slave Interface: eth1 MII Status: up Link Failure Count: 0 Permanent HW addr: 00:0c:29:f5:b7:11 Aggregator ID: N/A Slave Interface: eth2 MII Status: up Link Failure Count: 0 Permanent HW addr: 00:0c:29:f5:b7:1b Aggregator ID: N/A