Feed CountHere’s a nice trick I learnt a couple of days back. I wanted to display my feed subscriber count in a way that would match my site’s theme. I was tired of the vanilla feed-count display provided by FeedBurner – probably because you can find it on almost every other site these days (and I wanted something unique). So I got down to designing one on my own and I’m going to show you how to do the same for your site.

I won’t go into any lengthy (step-by-step) discussion on creating the graphical background – that’s something that’ll be your call. But I’ll teach you the core idea – fetching the feed-count from FeedBurner’s server using their API and displaying it on your site.

The Graphical Part

First and foremost, you need to decide on what kind of a display you want – small or large, dark or light. For example, I chose to display mine on a black background with medium sized font (see my RSS box at the top of the page). Depending on your background, you’ll need to either create or find a suitable RSS icon. You can find some excellent tutorials on creating feed icons here, here and here. Alternatively, you can download a whole bunch of free icons from here.

As a starter fire up your favourite graphics editor (Adobe Fireworks for me). For simplicity’s sake we’ll follow the same approach as I did with my feed-count box. Draw a black rectangle with rounded corners. Place your feed icon in a suitable place. Then draw another smaller rounded rectangle inside the earlier one, but with a lighter stroke colour (say white). This will be the container where you display your feed-count. You can throw in some fancy glow / shadow effects as you like. We should get something that approximately resembles the following image.

Feed Count Container Graphics

The image shown above was created with Fireworks and is an editable layered PNG file. If you’re using Fireworks, you can very well download this one (Right Click on it > Save Image), use it as a starting point and add/edit/resize it according to your preferences.

The Coding Part

You need to ensure that your web-host offers cURL (as an extension of PHP). By default, 90% of the web-hosts do – so you shouldn’t have anything to worry about. Secondly, the FeedBurner Awareness API (for your feeds) should be turned on. If you have been using the Feed Count feature of FeedBurner – then it IS already turned on. If not, you can login into your FeedBurner account, select the Publicize tab for the appropriate feed and activate this service. Once you’ve made sure of these two factors, we can progress to the actual coding.

Here’s the code you’ve going to need.

// Get FeedBurner Subscription Count - using FeedBurner Awareness API
function get_feedburner_count( $uri, $display = 'true', $format = 'true' ) {

	// Construct URL
	$apiurl = "http://api.feedburner.com/awareness/1.0/GetFeedData?uri=" . $uri;

	// Initialize the Curl session
	$ch = curl_init();

	// Set curl to return the data instead of printing it to the browser.
	curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
	// Set the URL
	curl_setopt( $ch, CURLOPT_URL, $apiurl );
	// Execute the fetch
	$data = curl_exec( $ch );
	// Close the connection
	curl_close($ch);

	// Parse XML
	try {
		@$xml = new SimpleXMLElement($data);
		$fcount = $xml->feed->entry['circulation'];
	} catch ( Exception $ex ) {
		// echo 'Caught exception: ',  $ex->getMessage(), "\n";
		$fcount = "?????";
	}

	// Display or Return, Formatted or Unformatted
	if( $display ) {
		if( $format )
			echo number_format( $fcount, 0, '.', ',' );
		else
			echo $fcount;
	}
	else
		return $fcount;

}

If you’re wondering where you’re going to add this code without messing up your theme – almost all modern WordPress themes have this file named functions.php, which contains the functions essential for registering the sidebar, tweaking specific WordPress routines etc. You can add this code to that file and it’ll be made available for calling from anywhere inside your theme.

The function is called get_feedburner_count() and accepts three parameters – two of which are optional. Here’s an explanation of the parameters…

  1. $uri – This is a mandatory parameter. If you don’t specify this one, the function won’t be able to fetch the feed count. The URI is the name you chose to represent your feed on FeedBurner. For example – my feed url is, http://feeds.feedburner.com/ChaosLaboratory. That makes my URI, ChaosLaboratory. This is what needs to be specified here.
  2. $display – This is an optional parameter. It takes up the values true or false. I have modelled this function on the lines of the general WordPress template functions – which means that the function is able to either display the feed-count directly, OR return it to you for further processing. If you don’t specify any value here, it’ll default to displaying the feed-count.
  3. $format – This too is an optional parameter and takes up either true or false. By default it is set to true. This tells the function to pass the feed-count through another formatting function, which adds a digit-grouping comma to it for every thousandth place. The formatting occurs on Line 31 of the code and you can modify that line to reflect any sort of formatting you want.

A typical call the function can look like,
get_feedburner_count( 'ChaosLaboratory' ); – this will print out the formatted feed-count directly

OR

$fcount = get_feedburner_count( 'ChaosLaboratory', false, false ); – this will fetch the raw (non-formatted) feed count and store it in a variable called $fcount. This doesn’t print the figure directly to the screen, but leaves it at your disposal for further processing

OR any variation thereof.

Now, we need to apply some styling to that background image we created so that the feed-count is aligned properly.

Note: I applied the styling on an anchor (link) tag, since I wanted to make the whole image clickable, so as to provide a way of subscribing to my feeds too. Here’s an example…

a#feedcount {
	display:block;
	width:120px;
	height:26px;
	margin:0;
	padding:5px 10px 5px 0;
	background:url(images/bg-feed.png) no-repeat transparent;
	color:#D6D6D6;
	font-size:2em;
	font-weight:bold;
	text-align:right;
	text-decoration:none;
}

Points to note here: On Line 1, I’ve declared display:block. This is necessary, since the a tag by default is an inline element – which means, it collapses to the exact width of the text contained in the anchor. This is not desirable here as we’re attaching the background image to the a tag, and we want it to adapt to the exact proportions of it (specified in Lines 3 & 4). I’ve aligned the feed-count text to the right (Line 11) and used a padding of 10px on the right (Line 6) so as to leave a comfortable gap from the right edge of the graphics.

The code-block above can be added to your template’s stylesheet file or in the header.php within style tags – depends on you. For me, I prefer to keep all the styling in one place, i.e. the stylesheet file.

Adding it to your template

Now that we’ve got all the code in the right place, it’s time to add it to the template. Open up the appropriate file (header or index) – where you want to display the feed-count and add the following lines…


	< ?php get_feedburner_count( "YOUR_FEED_URI" ); ?>

And that’s it! That should display your feed count with the custom graphical background and make the image clickable too, to act as a feed subscription button. The final effect should look like the following…
FeedBurner Feed Count with Graphical Background

Any questions / clarifications, feel free to write back.

Jun 22nd by miCRoSCoPiC^eaRthLinG

IntroductionThis tutorial was created for an opensource site named AntiLost that a couple of my friends and myself had tried to launch a while back. While the site never really took off (and has been torn down long since), some of the material that were hosted there still remains with me. I was going through them yesterday and discovered this one. It’ll come real handy to a lot of the aspiring digital artists out there. So here it is in honour of my good buddy Twitch aka Michael Land, who happens to be the original author. Twitch is an excellent graphics / web-designer and has one of the most brilliant colour matching brain I’ve ever seen.

We’ll be using the vector graphics tool named Fireworks from Macromedia (now a part of Adobe).

Step 1

Launch Fireworks and create a new document in it. Set the width and height of the Canvas at 75px each and set the resolution at 72px/inch. As for the Canvas colour, set it to Transparent as it’ll enable you to place the final image over any other artwork you like. It’ll also make it easier for you to work with the Doughnut Tool later on.

Fireworks CD Image - Create Canvas

Step 2

Now, instead of using the standard Ellipse Tool Fireworks Ellipse Tool Icon to make the outline of a CD, we’ll use the Doughnut Tool Fireworks Doughnut Tool Icon, as the generated image contains an “empty” circle in the middle which allows for seeing objects placed behind it. With the Doughnut Tool selected, draw a simple doughnut shape on the canvas in the default Layer.

Fireworks CD Image - Doughnut Shape

Once done, adjust the X, Y Coordinates of the shape to 5px each. Then set the dimensions (width & height) to 65px – so that you doughnut shape nicely fits inside the canvas leaving some marginal area around.

Fireworks CD Image - Adjust Coordinates and Dimensions

Name this layer, CD Base.

Step 3

We have our basic CD. You may want to adjust the inner radius (of the little circle) so that it ressembles a CD all the more since the spindle hole of the CD isn’t as big as that of the doughnut shape. To do so, click and drag the Diamond Dot on the inner ring till you get a shape that satisfies you.

Fireworks CD Image - Adjust Inner Radius

Following the adjustment, the image should look like this…

Fireworks CD Image - After Adjusting Inner Radius

Step 4

Now that it looks a bit more like a CD, we’re going to add some colours to it. Feel free to use whatever colours you like – but keep in mind that you’ve to pick two tones (light & dark) of the same colour. To keep to the Web 2.0 style, you should pick pastel shades. For your doughnut, change the colour to Solid > Gradient > Linear.

Fireworks CD Image - Change Colour to Gradient

Make sure your gradient band is horizontal and not at an angle – or else, you won’t get the desired effect.

Fireworks CD Image - After Applying Gradient

When you’re ready, we’ll go ahead and change the gradient start and end colours. Make the first or beginning tag the lighter one while choose the darker colour for the ending tag. For our purpose, I’m going to pick #94CAE4 and #2F8EBD respectively.

Fireworks CD Image - Choosing the Gradient Colours

The recoloured CD image should now look like the following …

Fireworks CD Image - After Choosing the Gradient Colours

Step 5

Our CD is finally coming together. Although it may not seem like it, there are only a few steps remaining now. Next apply a Stroke. This doesn’t mean “stroke your screen”. By stroking, you add a solid line in the external regions of the figure so as to define the edges. So select your CD, choose a colour that is a triffle bit lighter than the darker shade of your gradient and apply a stroke of 1px thickness. If you’ve used the colour tones that I used, #388BB4 would be a good tone to use for the stroke.

Fireworks CD Image - Adding a Stroke

You should end up with an image like this…

Fireworks CD Image - After Adding a Stroke

Step 6

This is the easiest step. Go to the Filters Panel and drop a Shadow (follow Shadow & Glow > Drop Shadow). Leave the settings as they are.

Fireworks CD Image - Dropping a Shadow

The end effect should be like this…

Fireworks CD Image - After Dropping a Shadow

Step 7

This is the second hardest part of this tutorial, but if you’ve followed the guidelines so far you shouldn’t face any problems. Create a new Layer and name it CD Ring. Make sure it is placed above the last layer (CD Base). Selecting this layer, draw another doughnut shape smaller than the CD image but overlapping it. Be careful as to not cover the spindle hole. Give it a Solid Fill (I’ve used White#FFFFFF here). If the shape inherits a Shadow by default, simply remove the effect from it.

Fireworks CD Image - Adding a CD Ring

Next, adjust the dimensions, coordinates and inner radius of the doughnut so that it fits around the spindle hole of the CD like a narrow ring. This may take some effort but eventually you’ll get it right. For me, setting the dimensions to 30px each and the coordinates to 23 x 23 and then trivially adjusting the inner radius worked like a charm. Finally, apply the same Stroke colour as before. Here’s the result…

Fireworks CD Image - After Adjusting CD Ring

Step 8

The hardest of all ! Making the reflection segments. When I say hardest, I don’t mean you require an expert to do so. However, you’ve got to be extra careful with this one as it can make or break the whole effect.

Start by creating a new Layer named Reflection. Place this in between CD Base and CD Ring i.e. above CD Base and below CD Ring. Copy your larger CD from the CD Base layer and paste the copy in the newly created layer. Remove the Drop Shadow effect from it and give it a Solid Fill with White. Remove the Stroke too.

Fireworks CD Image - Setting Relfection Layer Parameters

Next set the transparency (opacity) of this shape to about 25%.

Fireworks CD Image - Set Reflection Layer Opacity to 25%

Here comes the fiddly part. On the doughnut shape, there’s a little Diamond Dot on the Outer Ring. Press and hold down the ALT key and drag the diamond a bit along the circumference to create a segment. If you’ve difficulty working with the dot, you can always Zoom In the image. A zoom of 300-400% should suffice. Now, from the end-point of the last segment, create another segment of a different (wider or narrower) circumference and do so till you’ve created 5 segments of varying circumferences.

Fireworks CD Image - Creating the Segments #1 Fireworks CD Image - Creating the Segments #2

The reason that you create 5 segments is that 2 of them in between will act as spaces (well, 6 segments & 3 spaces – if you count in the part between the last segment and the starting point).

Now switch to the Subselection Tool by pressing 1 or A on your keyboard. Select a segment which you consider a space (will show through to the bottom layer) and press Delete on your keyboard. You may get a warning – just go ahead and click OK.

Fireworks CD Image - Deleting the Segment Spaces

Delete two more such spaces till you get your perfect CD Image with alternating reflection segments. If you did everything right, you have your Web 2.0 style CD Image.

Fireworks - Web 2.0 Style CD Image

Note: One final touch-up. I noticed that the shadow was getting cropped a bit at the right and bottom edges. Increasing the Canvas size to 77px by 77px keeping the Anchor on the Top-Left did the trick.

If you require the original Fireworks file containing all the layers, simply right-click and save the final CD image. Opening it in Fireworks will reveal all the layers.

Have fun :)

Aug 29th by miCRoSCoPiC^eaRthLinG

Ever come across those neat graphics of directional arrows and wished you could have them on your site? They can be used for anything from grabbing attention to indicating download links.

Look no further. Here is a step-by-step tutorial that should get you on track, and enable you to create custom graphical arrows.

The tutorial is based on Inkscape, which is an open source vector graphics editor. But that doesn’t mean that the creation process is limited to Inkscape only. You should be able to follow this simple tutorial with other vector graphics editors too.

Step 1

Use the Rectangle Tool Rectangle Tool icon to draw a rectangle.

Rectangular base for the arrow.

Step 2

Using the same tool, you will need to draw a square – a perfect square that is a little bit wider than the first rectangle.

Square above the Rectangle

HintInstead of fighting with the Rectangle Tool in order to get the perfect square, hold down the [Ctrl] button while drawing the square. The length and height will snap to the same size.

Step 3

Next task is to rotate the square through 45 degrees. With the Select Tool Select Tool icon click on the square twice. The selection will change to rotation and skewing mode.

Skew and Rotation mode

Hold down the [Ctrl] key and use the corner rotate icon to rotate the square in chunks of 15 degrees. Holding down the [Ctrl] keys lets you make snapped rotations. If you do not use the [Ctrl] key, the rotation is free form and through an arbitrary degree.

Sqaure rotated through 45 degrees

Step 4

Convert the rotated square to a path, by selecting Path > Object To Path.

Convert the Square to a Path

Use the Edit Node Tool Edit Node Tool icon and select the rotated square shape. Then select the lower node and delete it.

Symmetric Triangle

This will give you a symmetric Triangle.

Step 5

Select both the shapes, and choose Align and Distribute Objects Align & Distribute Objects icon option. Next, Center Align them both over the Vertical Axis Center Align over Vertical Axis icon .

Selected Square and Triangle

Select only the triangle and move it down over the rectangle.

Triangle moved over the Rectangle

Select both the shapes and perform a Union operation. This can be done by either pressing down [Ctrl] and [+] keys or through Path > Union. What you have now is a basic arrow shape.

Basic Arrow Shape

You can apply several vector effects to this and customize it according to your needs. For example, give the arrow shape a fill color, and a darker outline color. Then copy the shape, place it below the first, move it a bit, and turn on the blur. This gives you a fancy shadow effect.

Arrow filled with colours and with a shadow

Here’s a short video showing you how to do that.

Or you can also go on to give it a nice glossy look.

Glossy Arrow

This uses the same basic shape to give a solid fill color, and a copy to give the gradient of dark to light from top to bottom. Another copy of the same arrow, combined with a free form shape transformation gives that glossy look on the side.

Here is an example of how you can use the illustration for your website …

Download Link using the Arrow

Let me know how useful this has been, and also if you would like to learn something else.

Happy vectoring!


Vyoma aka K. Mahesh Bhat dabbles in vector art as a hobby and runs his own arts and graphics design blog titled KalaaLog. This is his first appearance as a guest blogger at Chaos Laboratory.

Aug 27th by Vyoma

OpenSearch LogoFollowing the tutorial(s) I posted on creating OpenSearch plug-ins for Firefox that can search Invision Power Board based forums & WordPress blogs, I received quite a few requests for help in creating such plug-ins for a wide variety of blogs/CMS/sites.

To make the job easier for all of you, I decided to create a couple of sample plug-ins, which I’ll list here as zip files. The zip will contain…

  • An XML file – which contains the actual plug-in code
  • A sample HTML file, which shows how to display a plug-in installation link on your site, as well as how to enable auto-discovery of the same by Firefox & IE7

Simply go through those files and replace the appropriate fields. In most cases, all you’ll need to modify is the actual URL to your site and the Author details. While setting up the plug-in at your site, feel free to put your name as the author’s name in it. No credits are required :)

I’ll try to cover as much ground as possible and update this list frequently. At the moment, the list isn’t so “wide” as I claimed in the title :D and if you don’t find a suitable plug-in here, check back at a later point of time, or just drop me a line at:

My email address

To start with, I’ll list the plug-ins I’ve received the maximum number of requests for…

Plug-ins List

Content Management Systems

  1. Mambo CMS based Sites
  2. Joomla CMS based Sites

Bulletin Board Systems

  1. Invision Power Board based Forums

Blog Softwares

  1. WordPress based Blogs

Miscellaneous Sites

  1. iPodNova Torrent Search
  2. BlogSpot based Blogs
  3. PsyDB – Psychedelic Trance Database

Jan 14th by miCRoSCoPiC^eaRthLinG

A brief introduction

This tutorial will attempt to explain in a simple manner how to create an OpenSearch plug-in for Firefox. These plug-ins appear in a drop-down menu in the Firefox Quick-Search bar (located right of the URL/Address bar) and help you perform quick searches across various search engines without having to visit the search page first. Pretty neat, eh?

These search plug-ins were in existence (for Firefox) for a long time. But only with the introduction of Firefox 2.0, the OpenSearch standards have been adopted.

OpenSearch is a collection of simple formats for the sharing of search results.

The OpenSearch description document format can be used to describe a search engine so that it can be used by search client applications.

The OpenSearch response elements can be used to extend existing syndication formats, such as RSS and Atom, with the extra metadata needed to return search results.

The example I’m going to demonstrate searches Invision Power Board (Bulletin Board System). You can make this plug-in perform searches on virtually any other Blogs / Bulletin Board / Content Management System / Search Engine with just some minor modifications in the way the search URL (along with keywords) is sent to the search engine. Here’s a screen-shot of two such plug-ins I’ve created for Astahost & Trap17 forums powered by IPB (Invision Power Board).

OpenSearch Plug-ins Dropdown List

Advantages

There are quite a few advantages of shifting to the new OpenSearch format for these plug-ins, namely …

  • OpenSearch plug-ins are universally supported across many browsers & search clients. Specially worth a mention here are Firefox and IE7 !!
  • OpenSearch supports Autodiscovery of the plug-in, which means you don’t really have to instruct the user to click on a link on your site to install the plug-in. The search client can auto-discover the plug-in script based on a link provided between the HEAD tags of the page.If you wish to, the old-school click & install method can still be implemented.
  • A lot of recent Blogs / CMS / BBS etc. softwares have started supporting the OpenSearch API, which provides a flexible common standard for XML based searches. A list of such software can be found here.

Without further ado, lets get down to business …

The actual plug-in

The OpenSearch plug-ins consist of a single XML file called the OpenSearch Description File. It follows a very simple syntax as shown below:


	engineName
	engineDescription
inputEncoding
	outputEncoding
	
	


	
	searchFormURL

Most of the tags here need to be customised according to the Search Engine you’re going to use with the plug-in. Here’s what you need to modify here.

engineName

engineName enclosed within the ShortName tags specifies the name of the Search Engine as it’ll show up in the dropdown list. Replace this with the name of your Search Engine.

engineDescription

engineDescription enclosed within the Description tags shows up as a brief description of the Search Engine. Replace this with a suitable description.

inputEncoding

inputEncoding enclosed within the InputEncoding tags declares the encoding to use for search string / keywords you provide for a search. The search string is encoded in this format prior to sending to the Search Engine. Your best best is to use UTF-8 here to declare it as Unicoded text that’ll cover the whole Unicode Character Set.

outputEncoding

outputEncoding, enclosed within the OutputEncoding tags acts similar to InputEncoding and declares the character set to be used for producing the search results output. Even here the best used option is UTF-8.

Image

Enclosed within the Image tags, this specifies the image / icon to be used for the Search Engine. This icon turns up next to the search engine name in the dropdown list and also shows up to the left of the quick-search bar. The image is usually in a 16 x 16 pixels format.

The image data can be provided in two formats:

  1. As a direct URL link to the location of the image file (gif/jpg/png etc.)
  2. As base64 encoded data which can be embedded in the plug-in directly. This I believe, is a more elegant way of doing it. However, I couldn’t make it work properly for me. The image simply refused to turn up and hence I’d to resort to method 1.There’s a very good tool at URI Kitchen that encodes any uploaded image in base64 format. The encoded data can then be directly embedded in the plug-in.

Url

Enclosed within the Url tags, this provides the actual location of the Search Engine page. The method attribute defines whether to use GET or POST for fetching the data, while the template attribute points to the location of the search query page. NOTE, that IE7 doesn’t support the POST method and hence to make your plug-in compatible with both IE7 and Firefox, you should ideally use GET here.

Param

Further nested within the Url tags lie a series of Param tags which have two attributes – a name and a value. These act as parameters which are passed to the search engine while performing a query. This too, isn’t supported in IE7. However, you can use a dynamic variable called {searchTerms} to pass on keywords.

Say for instance, I’m searching Invision Power Board based forums. The standard search string in IP takes the format,


http://www.domain.com/index.php?act=Search&CODE=show&searchid=xxx&search_in=posts&result_type=topics&highlite=keywords

If you study the URL carefully, you’ll notice that there are a couple of variables like act, CODE etc. which appear every time along with same values. You can use Param tags to define key-value pairs for these variables, which will then be passed onto the Search Engine during a query.

The actual search keywords (as mentioned before) are available through a variable called {searchTerms}. IPB supports a variable called keywords in the search string and hence you can define a key-value pair like…


… to pass the keywords. Here’s a full working example of the plug-in I created for Astahost forums…


	AstaHost
	AstaHost: Search the Forums
	miCRoSCoPiC^eaRthLinG
	microscopic.earthling@gmail.com
	open
	false
	en-us
	UTF-8

UTF-8

	http://plugins.astahost.com/splugins/astahost.gif
	






http://www.astahost.com/index.php

Here you’ll notice several other tags like Developer, Contact, SyndicationRight, AdultContent etc. which I haven’t discussed in this article. A detailed outline of all the OpenSearch tags can be found at: OpenSearch Description Elements.

Autodiscovery

If you recall I’d discussed a feature called Autodiscovery earlier on. This helps search clients automatically discover a plug-in embedded in your page. The process is quite simple. All you’ve to do is include a special LINK statement in the HEAD part of your page.

  

You simply need to modify the title and the href link to the actual plug-in file.When you visit a site with the plug-ins set to be auto-discovered, here’s how the drop-down menu in the quick-search box will look like…

OpenSearch Plug-in Autodiscovery Screenshot

Adding the plug-in Programmatically

You can also include the plug-in on your page in a click-and-install manner. The process has been simplified. All you need to do is provide a link to install the plug-in on your page and in the link, add the window.external.AddSearchProvider() JavaScript statement. Example is shown below.


	Link Text

Clicking on this link will cause Firefox to pop-up a dialog box asking the visitor for a confirmation of plug-in installation. Example of the dialog box …

OpenSearch Plug-in Click & Install Screenshot

Working examples can be found at the Astahost Plug-ins Page.

Any questions / confusions ?? Feel free to leave a comment and I’ll make sure to get back to you.

Jan 07th by miCRoSCoPiC^eaRthLinG

This is one of the first of a series of tutorials I wrote on taming the Linux daemons. It was first published at Astahost Forums on February 5th, 2005.I’m sure all of you must have come across the term DHCP – anyone who’s connects to the internet has to come across it every now and then. You see the term even on the small setup instructions leaflets that accompany the dial-up internet packages from most of the ISPs. DHCP is what allots you a unique IP address every time you dial out to your ISP. Here’s a short description of what DHCP is and what it can do straight from the Redhat Manuals.

Chapter 18. Dynamic Host Configuration Protocol (DHCP)

Dynamic Host Configuration Protocol (DHCP) is network protocol for automatically assigning TCP/IP information to client machines. Each DHCP client connects to the centrally-located DHCP server which returns that client’s network configuration including IP address, gateway, and DNS servers.

18.1. Why Use DHCP?

DHCP is useful for fast delivery of client network configuration. When configuring the client system, the administrator can choose DHCP and not have to enter an IP address, netmask, gateway, or DNS servers. The client retrieves this information from the DHCP server. DHCP is also useful if an administrator wants to change the IP addresses of a large number of systems. Instead of reconfiguring all the systems, he can just edit one DHCP configuration file on the server for the new set of IP address. If the DNS servers for an organization changes, the changes are made on the DHCP server, not on the DHCP clients. Once the network is restarted on the clients (or the clients are rebooted), the changes will take effect.

Furthermore, if a laptop or any type of mobile computer is configured for DHCP, it can be moved from office to office without being reconfigured as long as each office has a DHCP server that allows it to connect to the network.

Assumptions:

  1. You have a Linux Server up and running with DHCP pre-installed on it. This will be referred to as your DHCP Server from now on.
  2. You have another Windows 2000/XP workstation running and connected to the Linux Server. This is required to test if the DHCP is being able to allot the IP addresses properly. This will be referred to as your DHCP Client from now on.
  3. You have only ONE network card (NIC) attached to the Linux Server and it’s name according to Linux Device List is eth0.

If you are unsure about what your NIC is referred to as, type the following in a linux console: shell> ifconfig

The output you get should look similar to this:

eth0   Link encap:Ethernet  HWaddr 00:0D:88:39:D2:69
inet addr:10.19.168.5  Bcast:10.19.168.255  Mask:255.255.255.0
inet6 addr: fe80::20d:88ff:fe39:d269/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:14450 errors:0 dropped:0 overruns:0 frame:0
TX packets:15310 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1539185 (1.4 Mb)  TX bytes:1763316 (1.6 Mb)
Interrupt:225 Base address:0xb800

This tells you that indeed your NIC is present and set to handle Linux networking. See if you can spot the important parameters like the Server’s NIC Hardware Address (MAC address), the Server’s alloted IP, Subnet Mask etc. They’re all grouped up in the first 2-3 lines of the output.

My server’s IP is set to 10.19.168.5 and that’s what you see on first half of the second line, along with the Broadcast Address (10.19.168.255) and Subnet Mask (255.255.255.0).

Step 1 – Editing the /etc/dhcpd.conf file

Most likely the file dhcpd.conf would not exist beforehand in you /etc directory. We’ll start with a blank file. If you want to save up on some typing, you can load up the sample configuration file that comes with linux and modify the parameters. If you have the most recent version of DHCP you’ll find the sample configuration file at /usr/share/doc/dhcp-3.0.1rc12/dhcpd.conf.sample. The location of the sample file might vary from distribution to distribution – so if you can’t find it in this directory try using the locate command to find the location of the file. A quick example of how to spot a file with locate…

shell> locate dhcpd.conf

Personally I prefer starting off with the blank file and inserting the configuration data according to my needs. So lets get on with it. Type in the following four lines at the beginning of the file…

default-lease-time 86400;
max-lease-time 86400;
ddns-update-style interim;
ignore client-updates;

A short explanation:

  • default-lease-time 86400 – This tells the DHCP server that the minimum amount of time that an IP is alloted to a client a.k.a lease, shouldn’t be less than ONE DAY (86400 seconds). One day is a good figure to keep for your default lease time. This will lease an IP address for 86400 seconds if the client host doesn’t ask for a lease over a specific time frame.

  • max-lease-time 86400 – This again, is the maximum duration for which one particular client host will have the IP alloted to it. When this period is over, the client has to re-apply for a new IP lease – and depending on the range of free IP addresses, it might be given the same IP as it had before or a new one. Be aware that once you have the server running – this process takes place with absolute transparency without any human intervention. Feel free to modify the numbers to suit your need. Normally you wouldn’t need values larger than 86400 – unless you intend to have any of your client hosts to be up and running for more than a day. Say you want it running for 2 days – change the figure to 2 x 86400 = 172800 and so. Whatever number of days you want the lease to stay, just multiply 86400 by that and put the result in. Even if the client host requests a lease time frame which is more than this – the request would be rejected and the client will receive this figure as the maximum lease time.

  • ddns-update-style interim & ignore client-updates – These two lines are required too – but we won’t delve much deeper into these parameters – except that they involve a far advanced concept involving the inner operations of the DNS Server and are REQUIRED here. So just blindly put them in.

  • Below this part put a few blank lines and type in the following lines…

    option subnet-mask 255.255.255.0;
    option broadcast-address 10.19.168.255;
    option routers 10.19.168.5;
    ## The IP address of the name server
    ##
    option domain-name-servers 10.19.168.5;
    option domain-name "mydomain.com";

    These are the global option clauses that take the form:

    option <optionname> <optionvalue>

    The options should be fairly self evident. The first line sets a global subnet mask for your network. The second line fixes the Broadcast address for your subnet – the DHCP Server will advertise it’s services from either this IP (10.19.168.255) or use the universal broadcast IP (255.255.255.255). The third line sets the address of your router – which in turn shows up as the Default Gateway under windows. If you don’t have one, you can comment out this line. Fourth and fifth line as you can see specifies your DNS Servers IP and your Domain Name. If you have multiple DNS Servers, say 10.19.168.5 and 10.19.168.6 – you should specify them in order of search, i.e. the statement will take this form:

    option domain-name-servers 10.19.168.5 10.19.168.6;

    We key in all these parameters here, because certain network services/hosts cannot be allowed to have dynamic IPs. They require fixed addresses to perform properly i.e., any hosts on the network should always be able find these services at fixed addresses.

    Next we come to the Subnet Configuration part of the config file. Go ahead and type in the following…

    subnet 10.19.168.0 netmask 255.255.255.0 {
    range 10.19.168.31 10.19.168.250;
    }

    As you can see – the first line specifies the subnet of your network and your netmask. Replace my subnet IP with that of yours. The netmask usually always is 255.255.255.0 – which means your network logically wouldn’t have more than 253 client hosts and 254 including your server. My experimental network has just one subnet. You might have many more. In case you do, you have to make another similar block on entry below this one replacing the IPs with those of your second subnet.

    Next comes the clause that takes the form of…

    range <startrange> <endrange>

    - which specifies the IP Block or IP Pool from which addresses will be handed out to the client hosts. As you can see, I was experimenting with it, and set the start range to 10.19.168.31 and end range to 10.19.168.250 – so range of IPs alloted to my clients will start only at .31 and upto a maximum of .250.

    You can repeat the option statements that we used earlier inside this subnet {} block too – in case, you want this subnet to have a different set of dns/router/domain etc. The “options” specified earlier in the file are global and will affect any subnet which doesn’t have it’s own set of option clauses.

    This brings us to the last part of the configuration file. Whatever we’ve put in so far is enough to get your DHCP Server up and running – but in some special cases, you need to tell the server to allot a fixed IP to a certain system. This is possible by setting up a matching list of IPs and Hardware MAC Addresses of those systems. Say I have my own development WorkStation and a friend’s system called Tony who joins my network regularly. So the config options to be entered are…

    # Assign fixed address to certain hosts based
    # on NIC Address
    # My Development Workstation
    host workstation {
    hardware ethernet
    00:11:2F:47:54:F2;
    fixed-address 10.19.168.50;
    }
    # Tony's Computer
    host tony {
    hardware ethernet
    00:0A:5E:24:24:0E;
    fixed-address 10.19.168.60;
    }
    # Networked Laser Printer
    host laser-printer {
    hardware ethernet 08:00:2b:4c:59:23;
    fixed-address 10.19.168.100;
    }

    Once again this part should be self evident:

    • host <hostname>clause specifies the host for which I’m going to fix a specific IP address.
    • hardware ethernet and 00:11:2F:47:54:F2 together specify the MAC address of the client hosts.
    • fixed-address 10.19.168.50; tells the DHCP Server to allot only this IP against that particular MAC address.

    I’ve defined two systems here – but you are allowed to add in as many systems as you want. I’ve also got a networked laser printer which you can see defined in the third block.

    Be aware though – with every fixed MAC Address/IP combination you specify here, you IP Pool or IP Range that you specified for your subnet will get shorter by one free IP. In effect, if you’d specified around 250 hosts here manually – the whole IP Pool will be exhausted. In case some new system connects to your network – it wouldn’t be able to receive any free IPs. Besides if any of the client hosts has a malfunctioning NIC which has to be replaced – you’ll have to come back here and change the respective entry for its MAC address here and set it to the new one.

    Be very careful about the Opening and Closing Braces {} – if you miss out on any one of them the DHCP server will fail to start. If possible, use a GUI based editor with brace-matching, which helps to a considerable degree here.

    There’s something I forgot to mention though. Since these fixed IP specifications are for clients who are part of your subnet, this whole section should be enclosed within the subnet 10.19.168.0 netmask 255.255.255.0 {} declaration right after the line where you specify the IP Pool range (range 10.19.168.31 10.19.168.250;). If you are still unsure where to include this – see the attached sample config file and you’ll know right away.

    Save the file and quit :)

    Step 2 – Editing the /etc/rc.d/init.d/dhcpd file

    This is the file that actually starts up the DHCP Daemon during boot time, which in turn reads the configuration options from the dhcpd.conf in the /etc folder. This file is almost fully configured beforehand and we have to make only a few minor modifications. Scroll down till you come upon something that looks like a subroutine named start(). It should look like this:

    start() {
    # Start daemons.
    echo -n $"Starting $prog: "

    Below the second line with the “echo” add the following two lines…

    start() {
    # Start daemons.
    echo -n $"Starting $prog: "
    /sbin/route add -host 255.255.255.255 dev eth0 2> /dev/null
    daemon /usr/sbin/dhcpd eth0
    #daemon /usr/sbin/dhcpd ${DHCPDARGS}
    ...
    ...
    }

    The /sbin/route add -host 255.255.255.255 dev eth0 2> /dev/null sets up the DHCP Broadcast address to the global broadcast address of 255.255.255.255 and binds it to your primary NIC [b]eth0[/b]. Your system now knows that DHCP will broadcast its presence using this IP through your primary NIC.

    The second line daemon /usr/sbin/dhcpd eth0 is the actual command that starts your DHCP Server and tells it to listen on eth0 – which again, is your primary NIC. When you edit this file, you’ll probably see the third commented out line already present. You can either comment it out and insert the second line manually – or modify the same line and remove the ${DHCPDARGS} variable and put in eth0 there instead.

    Next scroll a little further down till you get to another similar sub routine titled stop(). Once again add the following line as shown…

    stop() {
    # Stop daemons.
    echo -n $"Shutting down $prog: "
    /sbin/route del -host 255.255.255.255 dev eth0 2> /dev/null
    ...
    ...
    }

    You have to add only the /sbin/route del -host 255.255.255.255 dev eth0 2> /dev/null line here which tells you system to stop broadcasting DHCP upon shutdown of the service and unhooks it from the global broadcast address.

    That’s it. Save the file and quit.

    We are now ready to start the DHCP server and put it to test. But before you do that there’s one last step that you got to perform. The DHCP Server stores all its lease information in a file called /var/lib/dhcp/dhcpd.leases by default. This file wouldn’t exist when you start the server – and on some systems, depending on the version of DHCP you are using it might spit out some error and cause DHCP to halt. Creating a blank file with that name solves the problem. We’ll just go ahead and do it anyway whether the file exists or not. So enter the following command…

    shell> touch /var/lib/dhcp/dhcpd.leases

    …and we are done.

    Step 3 – Starting the DHCP Server

    The DHCP Server can be started up in several ways. Do any of the following:
    shell> /etc/rc.d/init.d/dhcpd start

    OR

    shell> service dhcpd start

    Either way, you should get a message saying…

    Starting dhcpd: [ OK ]

    …which means all has gone well and your server is working fine.

    Step 4 – Starting your Windows System to check if DHCP is working properly

    Boot up your windows system and go to the Network and Dial-up Connections Panel. Right-click Local Area Connection and click on Properties. Then double-click on Internet Protocol (TCP/IP) and in the panel that comes up, make sure that the radio buttons next to Obtain an IP address automatically and Obtain DNS Server address automatically are both checked. If they are NOT, select them and click OK. Next Restart your system.

    Upon next boot – open a command line console type ipconfig /all. This should print out detailed information about your Network Card (NIC) and your present IP address. In my case, I booted up my development workstation – which if you recall from dhcpd.conf was set to have an IP address of 10.19.168.50 based on my hardware MAC address. That’s what I found my workstation to have. And if you didn’t allot fixed IP to any system, you’d find you Windows machine to have taken up the first free IP in your IP Pool, once again, the range of which was specified in the dhcpd.conf.

    One last cross-check that you can do – is to get back to your Linux Server and open the /var/lib/dhcp/dhcpd.leases file and view its content. It was blank when you created it – but now it should contain an entry corresponding to your Windows system(s) and should look like this…

    lease 10.19.168.50 {
    starts 2 2005/02/01 20:03:10;
    ends 3 2005/02/02 08:03:10;
    hardware ethernet 00:11:2F:47:54:F2;
    uid 01:00:00:e8:4c:5d:31;
    client-hostname "WorkStation";
    }

    Thats about it. Good luck and have fun. If you’ve any questions about any of the steps shown here, feel free to leave a comment :)

    Dec 08th by miCRoSCoPiC^eaRthLinG

    Page 1 of 38

      The Social Me

      Topics

      open all | close all

      Links

      Elsewhere on the Web…