More Static IP Stuff

I previously detailed how to setup a static ip address on your computer. A quick summary is below.

Backup the config file

vi /etc/network/interfaces{,.orig}

Setup the static entry by changing the file from:

auto lo
iface lo inet loopback

or

auto eth0
iface eth0 inet dhcp

to

auto eth0
iface eth0 inet static
address 192.168.1.200
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

Be sure to change the values to what you want to use. Then restart the networking service.

sudo service networking start|stop|restart|status
/etc/init.d/networking  start|stop|restart|status

Now on to some fun stuff.

Binding

Let’s bind two (or more) addresses on the same nic (network interface card). This is accomplished by adding additional entries below the initial static entry. Note the different in the eth0 name, eth0:0 and eth0:1

auto eth0:0
iface eth0:0 inet static
address 192.168.1.201
netmask 255.255.255.0

auto eth0:1
iface eth0:1 inet static
address 192.168.1.202
netmask 255.255.255.0

In order to bring up the additional addresses, use ifup.

ifup eth0:0
ifup eth0:1

You can verify your additional addresses with the ifconfig command. I’m piping into grep here so I only get the relevant entries.

user@computer ~$ ifconfig | grep 'inet '
     inet addr:192.168.1.200 Bcast:192.168.1.255 Mask:255.255.255.0
     inet addr:192.168.1.201 Bcast:192.168.1.255 Mask:255.255.255.0
     inet addr:192.168.1.202 Bcast:192.168.1.255 Mask:255.255.255.0
     inet addr:127.0.0.1 Mask:255.0.0.0

Bonding

Let’s bond two (or more) network interfaces to a single address. Here, we’re going to bond eth1 and eth2. In order to do so, we’ll need to install the ifenslave package.

apt-get install ifenslave

Net up, edit the interfaces file with the bonding information:

iface bond0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
slaves eth1 eth2
bond-mode active-backup
bond_primary eth1

If you have a particularly old version of Debian or one of its derivatives, you’ll need to run

modprobe bonding

But changes are you won’t. Move on to bringing up the network interface

ifup bond0

You can verify that it is working by running ifconfig bond0

user@computer ~$ ifconfig bond0
     bond0     Link encap:Ethernet HWaddr 08:00:15:62:7c:84
     inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
     inet6 addr: cb73::a00:52de:63ab:1ba5/64 Scope:Link
     UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
     RX packets:36 errors:0 dropped:0 overruns:0 frame:0
     TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
     collisions:0 txqueuelen:0
     RX bytes:9124 (15.2 KiB) TX bytes:3245 (2.3 KiB)

This bonding can also be verified by running:

user@computer ~$ cat /proc/net/bonding/bond0
     Bonding Mode: fault-tolerance (active-backup)
     Primary Slave: eth1
     Currently Active Slave: eth1
     MII Status: up
     MII Polling Interval (ms): 0
     Up Delay (ms): 0
     Down Delay (ms): 0

     Slave Interface: eth1
     MII Status: up
     Link Failure Count: 0
     Permanent HW addr: 08:00:15:62:7c:84

     Slave Interface: eth2
     MII Status: up
     Link Failure Count: 0
     Permanent HW addr: 08:00:19:53:b8:77

And that’s it! You’ve successfully bonded two network interfaces to a single ip address.

Tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

Protected by WP Anti Spam