<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NELUG - Durham Linux User Group</title>
	<atom:link href="http://www.nelug.org.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nelug.org.uk</link>
	<description>Also known as the North East Linux User Group</description>
	<lastBuildDate>Fri, 29 Mar 2013 22:19:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>March LUG &#8211; Kindling</title>
		<link>http://www.nelug.org.uk/march-lug-kindling/</link>
		<comments>http://www.nelug.org.uk/march-lug-kindling/#comments</comments>
		<pubDate>Fri, 29 Mar 2013 22:17:10 +0000</pubDate>
		<dc:creator>dougie</dc:creator>
				<category><![CDATA[LUG meetings]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=310</guid>
		<description><![CDATA[Somewhere out over the North Sea I took off my jacket, leaned back, and sipped on my beer. My jacket has a nice big inside pocket and, if I take the cover of my kindle, it fits perfectly in the &#8230; <a href="http://www.nelug.org.uk/march-lug-kindling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a title="Twitter Post from DFDS Seaways Ferry to Amsterdam" href="https://twitter.com/dougienisbet/status/312966113950588928">Somewhere</a> out over the North Sea I took off my jacket, leaned back, and sipped on my beer. My jacket has a nice big inside pocket and, if I take the cover of my kindle, it fits perfectly in the pocket. It&#8217;s a perfect fit. I mean, you wouldn&#8217;t know it was there &#8230;</p>
<p>A few days later I dug out my kindle and noticed the display was suffering from a split personality. The bottom half was telling me to switch it on, while the top half was still showing three little birds, outside my window, singing a sweet song. Oh dear. After a visit to the University of Google it became apparent to me that this problem is not uncommon. Weird, but not uncommon. Weird because you can run your finger across the screen and feel nothing; no cracks no blemishes. But it&#8217;s clearly broke. It may be silky smooth on the outside but it hides a shattered interior.</p>
<p>The forums on Amazon buzz with feel-good stories of customers phoning Amazon and getting great trade-in deals on their &#8216;just out of warranty&#8217; kindles. My Kindle was not just out of warranty, it was exceedingly, comfortably and generously out of warranty, and had been for a couple of years. Still worth a try &#8230;</p>
<p>Well that didn&#8217;t go anywhere useful. Nice chap all the same, and together across the ether we visited the Amazon website where we discussed the nice shiny new kindles and he advised me that I could &#8216;buy&#8217; one, at the price shown. Apparently bears also go to the bathroom in the woods. Ok, let&#8217;s go to ebay.</p>
<p>Aha &#8230; Now we&#8217;re cooking &#8230; <a title="Ebay listing for replacement screen" href="http://www.ebay.co.uk/itm/261183611124?ssPageName=STRK:MEWNX:IT&amp;_trksid=p3984.m1497.l2649">This</a> looks just the chap. A couple of days later a huge ball of bubble-wrap arrives at work, and somewhere inside, is a shiny new kindle screen. And there&#8217;s even a link to their Youtube video, yeah, well whatever. Why watch a youtube video when it&#8217;s NELUG night, and, well, you can run linux on a kindle can&#8217;t you? <a title="Jailbreaking your kindle" href="http://www.turnkeylinux.org/blog/kindle-root">Apparently</a>.</p>
<div id="attachment_311" class="wp-caption alignright" style="width: 324px"><a href="http://www.nelug.org.uk/wp-content/uploads/2013/03/Durham-kindle-nelug-Tue-19-Mar-2013-21-23-04-GMT_640x480.jpg"><img class=" wp-image-311 " title="Dissassembly" alt="Durham - kindle - nelug -- Tue 19 Mar 2013 21-23-04 GMT_640x480" src="http://www.nelug.org.uk/wp-content/uploads/2013/03/Durham-kindle-nelug-Tue-19-Mar-2013-21-23-04-GMT_640x480-300x225.jpg" width="314" height="240" /></a><p class="wp-caption-text">Richard takes the kindle to bits</p></div>
<p>That evening I turned up with a broken kindle, a new screen, and a random selection of small screwdrivers. I dumped them on the table and headed for the bar. A few minutes later I returned with my drink to find surgery was already underway. In the time it takes to say &#8220;a pint of Black Sheep please&#8221; Richard had prised open the cover, removed the battery, and was poking at various bits of the kindle&#8217;s anatomy with professional interest.</p>
<p>I made a perfunctory pretense of watching the instruction video on youtube but the Nelug hive mind was working quite well without it. With the new screen fitted re-assembly was, as they say, simply the reverse of disassembly. I stuck to the Black Sheep while Richard stuck to the screwdriver and, despite some frisky screws that had decided to go for a wander and wanted to live somewhere else for a while, it all ended well.</p>
<div id="attachment_316" class="wp-caption aligncenter" style="width: 810px"><a href="http://www.nelug.org.uk/wp-content/uploads/2013/03/Durham-kindle-nelug-Tue-19-Mar-2013-21-54-26-GMT_800x600.jpg"><img class=" wp-image-316 " title="Mission Accomplished" alt="Mission Accomplished" src="http://www.nelug.org.uk/wp-content/uploads/2013/03/Durham-kindle-nelug-Tue-19-Mar-2013-21-54-26-GMT_800x600.jpg" width="800" height="600" /></a><p class="wp-caption-text">The broken screen on the left with the repaired Kindle on the right</p></div>
<p><iframe style="background-color: #555555;" src="http://www.fellandforest.co.uk/zf/core/embedgallery.aspx?p=023c81ca0ff405211CCCCCC03e111111F5F5F5DDDDDD555555CCCCCC.2" height="360" width="480" frameborder="0" scrolling="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/march-lug-kindling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LUG meeting report, 18 September 2012</title>
		<link>http://www.nelug.org.uk/meeting-20120918/</link>
		<comments>http://www.nelug.org.uk/meeting-20120918/#comments</comments>
		<pubDate>Sun, 23 Sep 2012 13:20:02 +0000</pubDate>
		<dc:creator>olly-bh</dc:creator>
				<category><![CDATA[LUG meetings]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=299</guid>
		<description><![CDATA[Much fun was had learning about the difference between BIOS and UEFI booting, with the help of a Fedora 17 live USB: booting a BIOS system with this gives you syslinux, but a UEFI laptop loaded GRUB with a broken &#8230; <a href="http://www.nelug.org.uk/meeting-20120918/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Much fun was had learning about the difference between BIOS and UEFI booting, with the help of a Fedora 17 live USB: booting a BIOS system with this gives you syslinux, but a UEFI laptop loaded GRUB with a broken set of configurations. A few internet searches told us this was a <a href="https://bugzilla.redhat.com/show_bug.cgi?id=811389">known problem</a>, and we were able to fix the UEFI booting.</p>
<p>We also spent some time diagnosing CUPS and wireless driver problems, and discussing the implications of Google&#8217;s recent <a href="http://googleonlinesecurity.blogspot.co.uk/2012/09/adding-oauth-20-support-for-imapsmtp.html">announcement</a> that is supporting OAuth 2.0 authentication for several of its APIs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/meeting-20120918/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Brief Introduction To Regular Expressions</title>
		<link>http://www.nelug.org.uk/a-brief-introduction-to-regular-expressions/</link>
		<comments>http://www.nelug.org.uk/a-brief-introduction-to-regular-expressions/#comments</comments>
		<pubDate>Mon, 06 Aug 2012 18:23:15 +0000</pubDate>
		<dc:creator>olly-bh</dc:creator>
				<category><![CDATA[Tutorials and resourses]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=153</guid>
		<description><![CDATA[What is a Regular Expression? Purpose A regular expression is a flexible way of defining patterns of text. It is a formal language which is interpreted by a regular expression engine (which might be part of an application or a &#8230; <a href="http://www.nelug.org.uk/a-brief-introduction-to-regular-expressions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<style type="text/css">
code { background-color: lightgray; }
p.list-header { margin-bottom: 0em; }
</style>
<h1 id="what-is-regexp">What is a Regular Expression?</h1>
<h2 id="regexp-purpose">Purpose</h2>
<p>A regular expression is a flexible way of defining patterns of text.  It is a formal language which is interpreted by a regular expression engine (which might be part of an application or a programming language) that parses input text and compares it to the regular expression, and then performs operations on text that matches the regular expression.</p>
<p class="list-header">Common uses of regular expressions include:</p>
<ul>
<li>Matching text</li>
<li>Substituting text</li>
<li>Extracting text</li>
</ul>
<h2 id="regexp-syntax">Syntax</h2>
<p>The basic syntax of a regular expression is <code>/pattern/flags</code>.  The main part is the text pattern description, and the flags control the behaviour of the regular expression engine.</p>
<p>Different regular expression engines support different features, and also slightly vary in their syntax.	 After a overview of general regexp syntax we will look at some common applications and languages and how they support regular expressions.</p>
<p><span id="more-153"></span></p>
<h1 id="regexp-examples">Examples</h1>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">%\d\d?/\d\d?/\d\d\d?\d?%</pre></td></tr></table></div>

<p>This will match something that looks like a date, in a format like <code>dd/mm/yyyy</code> or <code>m/d/yy</code>.  Note that it does not check that it is a valid date, a string like <code>75/33/9876</code> would match.  Also note that a percentage mark has been used as the regexp delimiter; this can be clearer when the pattern contains slashes.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">/&lt;p( [^&gt;]*)?&gt;.*?&lt;/p&gt;/m</pre></td></tr></table></div>

<p>This regular will match a paragraph element and its contents in a HTML document.</p>
<p><a id="example-complex"></a></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">/
  (?:
    (?:(-?\d{1,3})m {0,3}(-?\d{1,4})y (?:\(( {0,2}-?\d{1,2})\))?)
    |
    (?: {0,2} (?:(-?\d{1,3})\/(\d)|(Junct))[ ]
      - {0,2} (?:(-?\d{1,3})\/(\d)|(Junct))
    )
  )
  \s+
  (C|C&amp;A&amp;T|C &amp; [AT]|L[234]|\*L4|SD[12])?
  \s+
  (?:\(((?:[ -]\d{2})|(?:\d\.\d))\))?
  \s+
  (-?\d+)?
  \s+
  (ALIG35|AL70|GAUGE|MT70|[LR]TOP
   | TW[35]M|CYC(?:[69]_|1[38])(?:BO|[LR]T))
  \s*=?\s* (-?\d{1,3}\.\d+)mm
  (?:\(1: ?(\d{2,3})\))?
  \s+
  \[ {0,2}(\d{1,3})\]
  \s*(.*)
  (?: +&gt; :)_+ *_+:_+\/_+\/_+
  \s+
  (?:to +(?:(-?\d{1,3})m {0,3}(-?\d{1,4})y[ ]
     (?:\(( {0,2}-?\d{1,2})\))?): *(\d+)cycles)?
  \s+
  ((?:P )?(?:IN)?VALID (?: BUT OFF ROUTE)?|OFF ROUTE|UNVERIFIED)?
/gmx</pre></td></tr></table></div>

<p>This is a much more complex example.  It is a regular expression that was written to match text in reports produced by a legacy system.  These reports had been designed to be printed and read; by using a regular expression it was possible to parse the report and extract the important information from it.  This regular expression matches a group of lines in the report and captures the bits of data that we are interested in.  It would be possible to use other methods to parse this report, but the flexibility of regular expressions make it well suited to cope with the quirks of the report formatting produced by different versions of the legacy software; the use of alternation and variable matches means that this regexp can match all formats of the report instead of having to rewrite the parsing code for each version.</p>
<h1 id="regexp-elements">Regexp elements</h1>
<h2 id="characters">Characters</h2>
<h3 id="normal characters">Normal characters</h3>
<p>Normal characters match themselves only.</p>
<ul>
<li><code>a</code> <code>b</code> <code>c</code> <code>X</code> <code>Y</code> <code>Z</code></li>
<li><code>0</code> <code>1</code> <code>2</code> <code>3</code> <code>4</code> <code>5</code> <code>6</code> <code>7</code> <code>8</code> <code>9</code></li>
<li><code>"</code> <code>_</code> <code>=</code> <code>#</code></li>
</ul>
<h3 id="special-characters">Special characters</h3>
<p>More exoctic characters are matched using character sequences.</p>
<dl>
<dt><code>.</code></dt>
<dd>The dot character will match almost any single character.  It does not usually match line break characters, unless the <code>/g</code> flag is set.</dd>
<dt><code>\*</code> <code>\?</code> <code>\}</code> <code>\[</code> <code>\]</code> <code>\/</code> <code>\\</code> <code>\^</code> <code>\$</code></dt>
<dd>If you need to match a literal character that has a special meaning in regular expresssions then it needs to be escaped using a backslash.</dd>
<dt><code>\n</code> <code>\t</code> <code>\e</code> <code>\a</code></dt>
<dd>There are several predefined sequences for non-printable characters.  <code>\n</code> is a new line character, <code>\t</code> is a tab, <code>\e</code> is an escape character and <code>\a</code> is a bell.  These will be familiar to anyone who has used C or many other programming languages.</dd>
<dt><code>\xB0</code> <code>\u0260</code></dt>
<dd>Some regular expression engines allow arbitrary hexadecimal or Unicode code points to be represented using a <code>\x00</code> or <code>\u0000</code> syntax.</dd>
</dl>
<h2 id="character-classes">Character classes</h2>
<p>By using [square brackets] you can match any of several different characters.</p>
<h3 id="character-collections">Collections of characters</h3>
<dl>
<dt><code>[abc]</code></dt>
<dd>The simplest form is a list of characters in square brackets, this will match any one of those characters.</dd>
<dt><code>[0-9]</code></dt>
<dt><code>[a-z]</code></dt>
<dt><code>[0-9a-zA-Z]</code></dt>
<dd>To make it simpler to match a large number of possible characaters you can specify ranges.</dd>
<dt><code>[-+0-9]</code></dt>
<dd>Simple characters and ranges can be combined as shown above.  Note that, due to its special meaning for ranges, to match a literal hyphen character then you can place it at the start of a character class (alternatively you can escape it with a backslash).</dd>
<dt><code>[^abc]</code></dt>
<dd>Negation is done by having a caret at the start of a character class.  The above example will match any character apart from <code>a</code>, <code>b</code>, or <code>c</code>.</dd>
</dl>
<h3 id="predifined-character-classes">Pre-defined character classes</h3>
<p>There are many predefined shorthand sequences for commonly used character classes.</p>
<dl>
<dt><code>\d</code></dt>
<dd>Any digit.</dd>
<dt><code>\d</code></dt>
<dd>Any character other than a digit.</dd>
<dt><code>\s</code></dt>
<dd>Any space character, e.g. space, tab.</dd>
<dt><code>\S</code></dt>
<dd>Any non-space character.</dd>
<dt><code>\w</code></dt>
<dd>Any word character.  The definition of word characters can vary, but it usually means any letter, any digit, or an underscore.</dd>
<dt><code>\W</code></dt>
<dd>Any non-word character.</dd>
<dt><code>[[:alpha:]]</code></dt>
<dd>Any letter character.  This is an example of a <a href="http://en.wikipedia.org/wiki/Regular_expression#POSIX_character_classes">POSIX character class</a>.  Note the double square brackets used here; the POSIX character class is <code>[:alpha:]</code> which can only be used inside the normal square brackets for character classes.  POSIX character classes can be combined with other elements within a character class, e.g. <code>[[:alpha::]ab[:digit:]]</code>.</dd>
</dl>
<h2 id="quantifiers">Repetition</h2>
<p>Quantifiers are used to control repetetive matching.  Greedy quantifiers will try and match as much text as possible, lazy quantifiers will try and match as little as possible.  Lazy quantifiers are used much less frequently than greedy quantifiers.</p>
<h4 id="normal-quantifiers">Normal quantifiers</h4>
<dl>
<dt><code>ab?c</code></dt>
<dd>The question mark character will match either zero or one occurrence of the preceding expression.  The above example will match either <code>ac</code> or <code>abc</code>, preferring the latter if possible.</dd>
<dt><code>ab*c</code></dt>
<dd>The asterisk character matches zero or more occurrences.  The above example will match <code>ac</code>, <code>abc</code>, <code>abbc</code>, <code>abbbc</code>, &hellip;</dd>
<dt><code>ab+c</code></dt>
<dd>The plus character matches one or more occurrences.  The above example will match <code>abc</code>, <code>abbc</code>, <code>abbbc</code>, &hellip;</dd>
</dl>
<h4 id="range-quantifiers">Range quantifiers</h4>
<dl>
<dt><code>ab{3}c</code></dt>
<dd>A number inside braces indicates an exact number of occurrences.  The above only will match <code>abbbc</code>.</dd>
<dt><code>ab{2,4}c</code></dt>
<dd>Two numbers inside braces, separated by a comma, indicates a range of occurrences.  This example will match <code>abbc</code>,  <code>abbbc</code>, or  <code>abbbbc</code>.</dd>
<dt><code>ab{2,}c</code></dt>
<dd>Omitting the second number, but keeping the comma, gives a minimum number of occurrences.  This example will match <code>abbc</code>,  <code>abbbc</code>, <code>abbbbc</code>, &hellip;</dd>
<dt><code>ab{,3}c</code></dt>
<dd>Omitting the first number, gives a maximum number of occurrences.  This example will match <code>ac</code>, <code>abc</code>, <code>abbc</code>, or <code>abbbc</code>.</dd>
</dl>
<h4 id="lazy-quantifiers">Lazy quantifiers</h4>
<dl>
<dt><code>ab??c</code></dt>
<dd>Like <code>ab?c</code> this will match either <code>ac</code> or <code>abc</code>, but the double question mark will make it prefer to match the former if this is possible.</dd>
<dt><code>ab*?c</code></dt>
<dd>This will match the same set of possibilities as <code>ab*c</code>, but if there are several possible matches then it will match as few <code>b</code> characters as it can.</dd>
<dt><code>ab+?c</code></dt>
<dd>This is the lazy equivalent of <code>ab+c</code>.</dd>
<dt><code>ab{1,2}?c</code></dt>
<dd>Similarly, putting a question mark after a range quantifier makes it lazy.</dd>
</dl>
<h3 id="alternation-grouping-matching">Alternation, grouping and matching</h3>
<h4 id="alternation">Alternation</h4>
<dl>
<dt><code>a|b</code></dt>
<dd>Matching one a set of possible different is done by using the pipe operator.  This will match either <code>a</code> or <code>b</code>.</dd>
<dt><code>foo|bar</code></dt>
<dd>The alternation operator has very low precedence, in particular lower than a sequence of characters.  This means that this example will match either <code>foo</code> or <code>bar</code>, not <code>fooar</code> or <code>fobar</code>.</dd>
<dt><code>foo|bar|baz</code></dt>
<dd>Matching one of more than two possibilities is simply done by using multiple pipe operators.  This will match any one of <code>foo</code>, <code>bar</code>, or <code>baz</code>.</dd>
</dl>
<h4 id="grouping">Grouping and matching</h4>
<ul>
<dt><code>foo(bar)?</code></dt>
<dd>Parentheses group a set of characters together.  Here the <code>?</code> quantifier applies to everything inside the brackets, so this will match either <code>foo</code> or <code>foobar</code>.</dd>
<dt><code>foo(bar|foo)</code></dt>
<dd>Parentheses can be combined with other operators, such as the pipe alternation operator.  This will match either <code>foobar</code> or <code>foofoo</code>.</dd>
<dt><code>(fooba[rz])</code></dt>
<dd>As well as grouping characters together, parentheses are used to capture elements within a regular expression which can then be examined later on.  This will match either <code>foobar</code> or <code>foobaz</code> and the matching text will be captured; in <code>sed</code> it will be stored as <code>/1</code>, in <code>perl</code> in the variable <code>$1</code>.</dd>
</dl>
<h4 id="non-matching">Grouping without matching</h4>
<dl>
<dt><code>(?:foo)</code></dt>
<dd>If you want to group a set of characters together without capturing them, then the <code>(?:&hellip;)</code> operator will do this.
<dd>
</dl>
<h3 id="positional-markers">Positional markers</h3>
<p>As well as matching text itself, you can control where the text occurs by using positional markers.  These markers do not match any text themselves, but control where the other patterns in the regular expression are able to match text.</p>
<h4 id="line-boundaries">Beginning/end of lines</h4>
<dl>
<dt><code>^foo</code></dt>
<dd><code>^</code> matches the start of a line or piece of text.  This example will only match <code>foo</code> if it is at the start of a line.</dd>
<dt><code>bar$</code></dt>
<dd><code>$</code> matches the end of a line or the end of the text.  This will match <code>bar</code> when it is at the end of a line.</dd>
</dl>
<h4 id="word-boundaries">Beginning and end of words</h4>
<dl>
<dt><code>\b</code></dt>
<dd>This batches word boundaries.  In the string <code>foo bar</code> it will match the start of the string, between the <code>o</code> and the space at the end of the word <code>foo</code>, between the space and the <code>b</code> at the start of the word <code>bar</code>, and at the end of the string.</dd>
<dt><code>\B</code></dt>
<dd>This is the opposite of <code>/b</code> and will match anywhere other than a word boundary, i.e. in the middle of words, and within sequences of non-word characters.</dd>
</dl>
<h4 id="lookaround">Lookaround</h4>
<dl>
<dt><code>foo(?=bar)</code></dt>
<dd>This is a positive lookahead: it will match if the text contains <code>foobar</code>, but will only match the <code>foo</code> part, and not the <code>bar</code> part.</dd>
<dt><code>foo(?!bar)</code></dt>
<dd>This is a negative lookahead: it will match <code>foo</code>, unless it is immediately followed by <code>bar</code>.</dd>
<dt><code>(?<=foo)bar</code></dt>
<dd>This is a positive lookbehind: it will match the text <code>bar</code>, but only if it occurs as <code>foobar</code>.  The text <code>foo</code> will not be part of the match.</dd>
<dt><code>(?&lt;!foo)bar</code></dt>
<dd>This is a negative lookbehind: it will match <code>bar</code> unless it is preceded by <code>foo</code>.</dd>
</dl>
<h3 id="flags">Flags</h3>
<p>Flags controls the overall behaviour of the regular expression.</p>
<dl>
<dt><code>i</code></dt>
<dd>The <code>i</code> (insensitive) flag tells the regular expression to match in a case insensitive manner.  <code>/foo/</code> will only match <code>foo</code>, but <code>/foo/i</code> will also match <code>FOO</code>, <code>fOo</code>, and so on.</dd>
<dt><code>g</code></dt>
<dd>The <code>g</code> (global) flag tells the regexp engine to match all possible instances of the regular expression.  Normally it will stop after the first match, but if this flag is set then it will look for any further matches.</dd>
<dt><code>m</code></dt>
<dd>The <code>m</code> (multiline) flag is for regular expressions that span more than one line of text.  Normally the match has to be on a single line, but if this flag is set then the match can span several lines.  This also changes the behaviour of the dot character class; it normally does not match line end characters, but will if the <code>m</code> flag is set.</dd>
<dt><code>x</code></dt>
<dd>Unlike the other flags, this does not alter the behaviour of the regexp engine.  Instead it allows you to write more legible regular expressions by splitting them across multiple lines: the lines will be concatenated with leading and trailing white space ignored.  The <a href="#example-complex">earlier example</a> used this flag to break up a very long regular expression.</dd>
</dl>
<h1 id="programs-languages">Programs and Languages</h1>
<h2 id="grep">grep</h2>
<p>grep is a simple program usually used to extract lines from text files that match a given pattern.  It is often used to match plain character sequences, so there are very few special characters: most regular expression operators have to be preceded by a backslash to give them their normal meaning.  Exceptions to this are the <code>*</code> quantifier and the <code>^</code> and <code>$</code> anchors which work as normal.</p>
<dl>
<dt>Metacharacters</dt>
<dd><code>.</code> <code>\n</code> <code>\t</code> <code>\s</code> <code>\S</code> <code>\w</code> <code>\W</code><br />
POSIX character classes, e.g. <code>[[:digit:]]</code></dd>
<dt>Repetition</dt>
<dd><code>\?</code> <code>*</code> <code>\+</code> <code>\{n,m\}</code></dd>
<dt>Alternation and grouping</dt>
<dd><code>\|</code> <code>\(&hellip;\)</code></dd>
<dt>Anchoring</dt>
<dd><code>^</code> <code>$</code> <code>\b</code> <code>\B</code> <code>\&lt;</code> <code>\&gt;</code></dd>
</dl>
<h3 id="examples-grep">Examples</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="grep" style="font-family:monospace;">grep 'FIXME\|TODO' */*.p[lm]</pre></td></tr></table></div>

<p>This will print any lines containing either <code>FIXME</code> or <code>TODO</code> from perl files.</p>
<h2 id="egrep">egrep</h2>
<p>Grep also has an extended mode which removes makes most of the operator characters behave as normal, so you do not need to prefix them with a backslash like in its basic mode.  If you are using anything other than very simple regular expressions with grep then is best to use this mode.</p>
<dl>
<dt>Metacharacters</dt>
<dd><code>.</code> <code>\n</code> <code>\t</code> <code>\s</code> <code>\S</code> <code>\w</code> <code>\W</code><br />
POSIX character classes, e.g. <code>[[:digit:]]</code></dd>
<dt>Repetition</dt>
<dd><code>?</code> <code>*</code> <code>+</code> <code>{n,m}</code></dd>
<dt>Alternation and grouping</dt>
<dd><code>|</code> <code>(&hellip;)</code></dd>
<dt>Anchoring</dt>
<dd><code>^</code> <code>$</code> <code>\b</code> <code>\B</code> <code>\&lt;</code> <code>\&gt;</code></dd>
</dl>
<h3 id="examples-egrep">Examples</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="grep" style="font-family:monospace;">grep -E 'FIXME|TODO' **/*.p[lm]</pre></td></tr></table></div>

<h2 id="sed">sed</h2>
<p>sed performs operations on streams of characters.  The most common operation is to replace strings, but many more powerful things are possible.  Its regexp syntax is very similar to the basic mode of grep.</p>
<dl>
<dt>Metacharacters</dt>
<dd><code>.</code> <code>\n</code> <code>\t</code> <code>\s</code> <code>\S</code> <code>\w</code> <code>\W</code><br />
POSIX character classes, e.g. <code>[[:digit:]]</code></dd>
<dt>Repetition</dt>
<dd><code>*</code> <code>\?</code> <code>\+</code> <code>\{m,n\}</code></dd>
<dt>Alternation and grouping</dt>
<dd><code>\|</code> <code>\(</code> <code>\)</code></dd>
<dt>Anchors</dt>
<dd><code>^</code> <code>$</code> <code>\b</code> <code>\B</code> <code>\`</code> <code>\'</code></dd>
</dl>
<h3 id="examples-sed">Examples</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sed" style="font-family:monospace;">sed 's%\(\d\d\)/\(\d\d\)/\(\d\d\)%20\3-\1-\2%'</pre></td></tr></table></div>

<p>This will transform dates from the format <code>mm/dd/yy</code> to the format <code>yyyy-mm-dd</code>, assuming that the date is in the 21st century.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sed" style="font-family:monospace;">sed '/^__END__$/,$d' foo.pl</pre></td></tr></table></div>

<p>This will strip the perlpod, and anything else that follows a <code>__END__</code> line, from a perl file.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sed" style="font-family:monospace;">sed 's/^\s\+//;s/\s\+$//'</pre></td></tr></table></div>

<p>This strips all leading and trailing spaces from text.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="sed" style="font-family:monospace;">sed 's/^\s*\(.*\S\)\?\s*$/\1/'</pre></td></tr></table></div>

<p>This also strips leading and trailing spaces from text.  The previous example uses two statements, one for leading space, and one for trailing space; this one using a single statement using a backreference.  This approach is <em>much</em> less efficient and will be several order of magnitudes slower than the previous example due to the increased memory requirements from the backreference.</p>
<h2 id="perl">perl</h2>
<p>Perl has by far the most comprehensive support for regular expression features.  Many features appear first in Perl before being copied by other languages and programs.</p>
<p>The Perl regular expression syntax is used in many applications and other programming languages through the <acronym title="Perl Compatible Regular Expression">PCRE</acronym> library.  This library is used by PHP, the Apache webserver, the Exim mailserver, and many others.</p>
<dl>
<dt>Metacharacters</dt>
<dd>All metacharacters are supported.</dd>
<dt>Repetition</dt>
<dd><code>?</code> <code>*</code> <code>+</code> <code>{n,m}</code> <code>??</code> <code>*?</code> <code>+?</code> <code>{n,m}?</code></dd>
<dt>Alternation and grouping</dt>
<dd><code>|</code> <code>(&hellip;)</code> <code>(?:&hellip;)</code></dd>
<dt>Anchors</dt>
<dd><code>^</code> <code>$</code> <code>\b</code> <code>\B</code> <code>(?=&hellip;)</code> <code>(?!&hellip;)</code> <code>(?&lt;=&hellip;)</code> <code>(?&lt;!&hellip;)</code></dd>
</dl>
<h3 id="example-perl">Perl Example 1</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/^ *ELR : +([A-Z]{3}\d?|[A-Z]{2}\d{2})/o</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$elr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/^ *Track Id : +\d(4})/o</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$tid</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/^ *\d{1,3}.\d{4}/o</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@data</span> <span style="color: #339933;">=</span> <span style="color: #000066;">unpack</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$template</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@data</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$i</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;"># every other element is a separator -- delete these</span>
        <span style="color: #000066;">splice</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@data</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;"># remove leading/trailing spaces</span>
        <span style="color: #0000ff;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^ +//</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/ +$//</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$elr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$tid</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@data</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3 id="example-perl2">Perl Example 2</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># decodes a standard deviation value</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%errcodes</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> NA <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> NF <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> NV <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
                 SS <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> ST <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> sdval <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$val</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$val</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/\d\.\d/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">return</span> <span style="color: #0000ff;">$val</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$val</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/\*\*/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">return</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$val</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">m/($errcodes)/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">return</span> <span style="color: #0000ff;">$errcodes</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">return</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h1 id="further-reading">Further reading</h1>
<ul>
<li><code>perldoc perlretut</code></li>
<li><cite>Mastering Regular Expressions</cite> by Jeffrey E F Friedl.<br />
2nd edition published by O'Reilly, 2002.</li>
</ul>
<hr />
<p>Based on a talk presented by Oliver Burnett-Hall at Durham LUG on 17 February 2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/a-brief-introduction-to-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Durham Linux User Group</title>
		<link>http://www.nelug.org.uk/durham-linux-user-group/</link>
		<comments>http://www.nelug.org.uk/durham-linux-user-group/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 13:32:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=20</guid>
		<description><![CDATA[We are in the process of updating this site&#8230; Apologies if the content you were looking for is no longer here&#8230; If you want to help, please get in touch. You can join the mailing list by going to http://mailman.lug.org.uk/mailman/listinfo/durham &#8230; <a href="http://www.nelug.org.uk/durham-linux-user-group/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>We are in the process of updating this site&#8230; Apologies if the content you were looking for is no longer here&#8230; If you want to help, please get in touch.</p>
<p>You can join the mailing list by going to <a title="Durham LUG Mailing List" href="http://mailman.lug.org.uk/mailman/listinfo/durham" target="_blank">http://mailman.lug.org.uk/mailman/listinfo/durham</a></p>
<p>Meetings are held in Durham (In the bar at Durham Rowing Club &#8211; See the <a title="Location" href="http://www.nelug.org.uk/location/" target="_blank">location</a> page).</p>
<p>We meet on the 3rd Tuesday of every month, from around 19:30, until around 22:30</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/durham-linux-user-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book review: &#8216;Digital Audio Essentials: A Comprehensive Guide to Creating, Recording, Editing, and Sharing Music and Other Audio&#8217;</title>
		<link>http://www.nelug.org.uk/digital-audio-essentials/</link>
		<comments>http://www.nelug.org.uk/digital-audio-essentials/#comments</comments>
		<pubDate>Wed, 18 Oct 2006 12:44:15 +0000</pubDate>
		<dc:creator>olly-bh</dc:creator>
				<category><![CDATA[Book reviews]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=155</guid>
		<description><![CDATA[Title: Digital Audio Essentials: A Comprehensive Guide to Creating, Recording, Editing, and Sharing Music and Other Audio Author: Bruce Fries, Marty Fries Price: £24.95 Publisher: O&#8217;Reilly Published: May 2005 Reviewed by: Dougie Nisbet Review date: October 2006 Rating: 4/5 Overview &#8230; <a href="http://www.nelug.org.uk/digital-audio-essentials/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-170" title="digital_audio_book" src="http://www.nelug.org.uk/wp-content/uploads/2006/10/digital_audio_book.jpg" alt="Book cover" width="194" height="240" /><br />
<strong>Title:</strong> Digital Audio Essentials: A Comprehensive Guide to Creating, Recording, Editing, and Sharing Music and Other Audio<br />
<strong>Author:</strong> Bruce Fries, Marty Fries<br />
<strong>Price:</strong> £24.95<br />
<strong>Publisher:</strong> O&#8217;Reilly<br />
<strong>Published:</strong> May 2005<br />
<strong>Reviewed by:</strong> Dougie Nisbet<br />
<strong>Review date:</strong> October 2006<br />
<strong>Rating:</strong> 4/5</p>
<h2>Overview</h2>
<p>This book presents itself an interesting challenge in that it attempts to present a comprehensive guide to digital audio in a book that isn&#8217;t the size of a brick. The authors do this successfully and the book is a worthwhile read.<span id="more-155"></span></p>
<h2>General</h2>
<p>The narrative is nicely pitched and soon settles down comfortably somewhere between a Dummies Guide and a dry reference book. The authors use simple elegant language to get across their message without sounding condescending or trivialising. They do not fall into the trap of presenting pages of space-wasting screen dumps and where they are used they are used sparingly and sensibly.</p>
<p>The book&#8217;s great strength is in astutely judging how much detail to delve into each subject. It does this in such a manner that each section can be read in as little or as much depth as desired, without any feeling that the narrative flow has been interrupted or that by skimming a particular section it will cause problems later. It is a well-paced book in the category of an enjoyable cover-to-cover read rather than a dry reference work.</p>
<p>The authors often refer to subjects that will be covered in more detail later in the book, rather than simply cross-referencing. This strikes a nice balance; you don&#8217;t feel compelled to jump forward to the referenced text that will be reached in due course anyway. This gives a good feeling of narrative flow.</p>
<p>Advice is always practical. For example, on &#8216;Purchasing&#8217; the book explains the importance of satisfying your own functional requirements and the diminishing returns of extra expenditure. Chapter 2 gives very good advice on how to choose hardware sensibly and how to go about intelligent cost-effective upgrades without getting sucked into impulse buys based on faster processors and higher clock-cycles.</p>
<p>The section on Minimizing Noise (chapter 4, page 61) is well explained and practical.</p>
<p>I found Chapter 8 a bit of a stumble. An abrubt blast of technical talk that could be quite challenging if the reader did not have some background experience of audio. However, as befits the style of the book, you can re-read or skim as desired without spoiling the overall narrative flow of the book.</p>
<p>The explanation of Digital Rights Management and file formats is well discussed and illuminating.</p>
<p>There is some repetition throughout the book but this tends to be more useful that irritating as it helps consolidate earlier explained material.</p>
<p>On page 160 Linux is mentioned in the discussion of formats, but barely mentioned elsewhere where a brief reference could be useful. There is a slight inconsistency here as the authors make clear that the book is geared towards Mac and Windows XP platforms, so it seems a bit pointless making the Linux reference at all. But since it has been mentioned, there are several opportunities in the book where a short reference could be made to Linux without any need to go into detail that would allow the reader to explore further if required. For example, it would take negligable space to mention in passing that there is a sizeable range of media players available on Linux.</p>
<p>The discussion on Perceptual Encoding in Chapter 10 is very interesting and clearly explained.</p>
<p>I found the section on Equalization (page 237) quite hard work. Perhaps too much was crammed in here in too short a space, and a longer, gentler explanation would have worked better. However I&#8217;m sure a few re-reads would have helped too.</p>
<p>In the section on Noise Reduction and recording from vinyl, I feel the authors should have made the point in passing that in many cases it is worth checking to see if the piece of work is already available as a digitally remastered CD. Even the most enthusiastic hobbyist may find that the time required and quality achieved from transferring vinyl to digital is not worth the effort when a professionally produced CD can be bought for a modest sum.</p>
<p>The book is full of interesting nuggets of information just waiting to be stumbled upon. I was intrigued to read about the lifetime of recorded versus unrecorded CD-Rs (p. 281), something that would never have occurred to me.</p>
<p>The wrapping up of the book with an in-depth explanation of internet streaming radio was of little interest to me and was the only part of the book that I felt was covered in too much detail. I was left wondering who the target audience was.</p>
<h2>Niggles</h2>
<p>On page 18, chapter 2, it might be worth mentioning that RAM upgrades can be limited by the BIOS or OS even if there are free slots.</p>
<p>The section on ripping (chapter 4, page 49) makes no mention of the perils of Copy Protected CDs. For a book that is generally very good at warning the reader of the pitfalls and legalities of ripping, this should be included.</p>
<p>The explanation on spyware (chapter 5, page 95) mentions always clicking on the &#8216;No&#8217; button on intrusive pop-up windows. With an increasing number of adverts now masquerading as pop-up windows with dialogues, where the whole pop-up is a clickable link, it would be safer to click on the &#8220;X&#8221; in the top-right hand corner of the window, or even close down the browser entirely.</p>
<p>Normally the US bias is not an issue. However there are times where the authors could give a nod to other countries and terminologies. For example, in the section on Broadcast Radio (chapter 6, page 99) it would be helpful to explain if or where the acronyms differed from other English speaking countries. The section on Broadcast Radio should certainly mention the excellent advert-free streaming and &#8220;Listen-Again&#8221; services available from the BBC RadioPlayer website.</p>
<p>The introduction to the book states clearly that it is written with the Windows and MAC user primarily in mind, so it is churlish to complain that there are no references to other operating systems. However it wouldn&#8217;t take much more space to mention that software such as RealPlayer is also available for Linux (chapter 6, page 103)</p>
<h2>Summary</h2>
<p>A nicely balanced book that can be read cover-to-cover as well as being retained as a reference work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/digital-audio-essentials/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book review: &#8217;802.11 Wireless Networks: The Definitive Guide (Second Edition)&#8217;</title>
		<link>http://www.nelug.org.uk/book-review-802-11-wireless-networks-the-definitive-guide-second-edition/</link>
		<comments>http://www.nelug.org.uk/book-review-802-11-wireless-networks-the-definitive-guide-second-edition/#comments</comments>
		<pubDate>Sun, 18 Dec 2005 13:50:34 +0000</pubDate>
		<dc:creator>olly-bh</dc:creator>
				<category><![CDATA[Book reviews]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=160</guid>
		<description><![CDATA[Title: 802.11 Wireless Networks: The Definitive Guide (Second Edition) Author: Matthew S. Gast Price: £31.95 Publisher: O&#8217;Reilly Published: April 2005 Reviewed by: Martin Ward Review Date: December 2005 Rating: 5/5 Calling your book &#8220;The Definitive Guide&#8221; sets the bar high &#8230; <a href="http://www.nelug.org.uk/book-review-802-11-wireless-networks-the-definitive-guide-second-edition/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-161" title="80211_book" src="http://www.nelug.org.uk/wp-content/uploads/2012/07/80211_book.gif" alt="Book cover" width="180" height="236" /><br />
<strong>Title:</strong> 802.11 Wireless Networks: The Definitive Guide (Second Edition)<br />
<strong>Author:</strong> Matthew S. Gast<br />
<strong>Price:</strong> £31.95<br />
<strong>Publisher:</strong> O&#8217;Reilly<br />
<strong>Published:</strong> April 2005<br />
<strong>Reviewed by:</strong> Martin Ward<br />
<strong>Review Date:</strong> December 2005<br />
<strong>Rating:</strong> 5/5<br />
<br/><br />
Calling your book &#8220;The Definitive Guide&#8221; sets the bar high at the start, and Gast does well to live up to his title and provide virtually everything you need to know about 802.11 networking.</p>
<p>If you are a wardriver looking for plans to make antennae out of Pringles cans, then you won&#8217;t find them here (but they are readily available on the Internet!) If you need to set up a wireless network of any size, or are just curious about how they actually work, then this is the book for you.<span id="more-160"></span></p>
<h2>Book Layout</h2>
<p>After an Introduction and Overview in Chapters 1 and 2, Chapter 3 looks at MAC (Media Access Controller) Fundamentals: everything between the device driver and the radio.</p>
<p>Chapter 4 describes frame layouts.</p>
<p>Chapter 5 discusses WEP (the so-called Wired Equivalent Privacy) and its many shortcomings.</p>
<p>Chapters 6 and 7 disciss 802.1X and 802.11i respectively.</p>
<p>Chapter 8 deals with management functions: scanning, preauthentication, association, power conserving etc.</p>
<p>Chapter 9 deals with PCF (Point Coordination Function), an as-yet unimplemented standard for contention-free access to the medium.</p>
<p>Chapters 10 to 14 deal with the physical aspects of RF propagation, frequency hopping and modulation techniques and so on.</p>
<p>Chapter 15 describes the competing proposed 802.11n standards, which will offer over 100Mbs of throughput over a wireless link.</p>
<p>Chapters 16 to 19 give detailed information on setting up wireless hardware and drivers on Windows Mac and Linux systems.</p>
<p>Chapters 20 and 21 discuss access points and the options for organising the logical wireless network architecture.</p>
<p>Chapter 22 discusses the important issue of the security architecture.</p>
<p>Chapter 23 describes site planning issues and some of the project management issues.</p>
<p>Chapters 24 and 25 look at network analysis and performance tuning.</p>
<p>Finally Chapter 26 concludes.</p>
<p>The book is very detailed and thorough, with a lot of useful information. There is some repetition: I lost count of the number of places where the reader is warned of the broken nature of static WEP security, for example! But this is probably inevitable in a book of this size and scope, when there is some attempt to make the various parts of the book self-contained.</p>
<p>Overall, &#8220;802.11 Wireless Networks: The Definitive Guide&#8221; lives up to its name and is highly recommended.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/book-review-802-11-wireless-networks-the-definitive-guide-second-edition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Net booting a diskless Sun3 from a Linux server</title>
		<link>http://www.nelug.org.uk/net-booting-a-diskless-sun3-from-a-linux-server/</link>
		<comments>http://www.nelug.org.uk/net-booting-a-diskless-sun3-from-a-linux-server/#comments</comments>
		<pubDate>Wed, 01 Sep 2004 21:40:58 +0000</pubDate>
		<dc:creator>olly-bh</dc:creator>
				<category><![CDATA[Tutorials and resourses]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=89</guid>
		<description><![CDATA[My system consists of a Linux server (basically Slackware-3.6 but with kernel 2.2.10 and various other irrelevant package upgrades) and 2 Sun3&#8242;s, only one of which is ever in use at any given time (thus they use the same swap &#8230; <a href="http://www.nelug.org.uk/net-booting-a-diskless-sun3-from-a-linux-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>My system consists of a Linux server (basically Slackware-3.6 but with kernel 2.2.10 and various other irrelevant package upgrades) and 2 Sun3&#8242;s, only one of which is ever in use at any given time (thus they use the same swap partition on the server &#8211; later).</p>
<p>The Sun3&#8242;s are diskless and hence boot from the Linux box, and mount all filesystems from it. The Sun&#8217;s run NetBSD 1.3.2 largely because the Sun 3 port of Linux was not very stable or mature when I set things up.<br />
<span id="more-89"></span><br />
OK, some basic info for future use:</p>
<table>
<thead>
<tr>
<th>Host</th>
<th>Hostname</th>
<th>Ethernet addr</th>
<th>IP addr</th>
</tr>
</thead>
<tbody>
<tr>
<td>Linux PC</td>
<td>moriah</td>
<td>00:00:C0:8C:AB:2E</td>
<td>192.168.200.1</td>
</tr>
<tr>
<td>Sun 3/60</td>
<td>hermon</td>
<td>08:00:20:00:49:16</td>
<td>192.168.200.2</td>
</tr>
<tr>
<td>Sun 3/50</td>
<td>carmel</td>
<td>08:00:20:06:1f:50</td>
<td>192.168.200.3</td>
</tr>
</tbody>
</table>
<p>The boot process for the Suns is basically as follows:</p>
<ol>
<li>tell the machine to boot from the ethernet device</li>
<li>it gets its IP address by rarp</li>
<li>it uses tftp to get a 2nd stage boot program **whose name is the IP address of the client** from the server</li>
<li>the 2nd stage boot loader gets boot parameters from the bootp server</li>
<li>the boot parameters specify where the root filesystem, containing the kernel, is located.</li>
<li>The boot loader nfs-mounts this remote root f/s and boots the kernel.</li>
<li>Once it has its root f/s the boot process is pretty standard as per a diskful machine.</li>
</ol>
<p>OK, in more detail:</p>
<p>Power on machine, hit <code>L1-A</code> if necessary to get a monitor prompt</p>
<p>Enter boot command, specifying ethernet interface as the boot device:</p>
<pre style="margin-bottom: 0.2in;">&gt; b le(0,0,0)</pre>
<p>First thing that happens is the machine broadcasts rarp requests saying &#8220;This is my ethernet addr, can somebody tell me my IP address please&#8221;.</p>
<p>My linux kernel is compiled with rarp support, and the kernel rarp table is populated at boot time by the following commands in rc.local:</p>
<pre>rarp -s hermon  08:00:20:00:49:16
rarp -s carmel  08:00:20:06:1F:50</pre>
<p>(/etc/hosts on moriah contains entries for hermon and carmel so the names are resolvable to numeric addresses)</p>
<p>(the forward-mapping arp table is also set up at boot time on moriah by <code>"arp -f /etc/ethers"</code> command &#8211; sadly rarp has no corresponding <code>-f</code>option so each entry must be added individually).</p>
<p>On receiving a response from moriah to the rarp request, the Sun contacts the tftp server on moriah and attempts to download the file <code>/tftpboot/&lt;my-IP-addr&gt;</code> from it. /tftpboot on moriah looks like:</p>
<pre>moriah% ls -lF /tftpboot/
total 16
lrwxrwxrwx   1 root     root            7 Aug  3 23:00 C0A8C802 -&gt; netboot*
lrwxrwxrwx   1 root     root            7 Aug  3 23:00 C0A8C803 -&gt; netboot*
-rwxr-xr-x   1 root     root        15360 Aug  1 22:56 netboot*</pre>
<p>where <code>netboot</code> is the NetBSD stage 2 boot program. IP addresses are in hex as you can see.</p>
<p>The tftp server <code>in.tftpd</code> runs from inetd on moriah &#8211; the relevant line from <code>/etc/inetd.conf</code> is:</p>
<pre>moriah% grep tftp /etc/inetd.conf
tftp    dgram   udp     wait    nobody  /usr/sbin/in.tftpd in.tftpd</pre>
<p>and from /etc/services:</p>
<pre>moriah% grep tftp /etc/services
tftp            69/udp</pre>
<p>Once dowloaded, the stage 2 boot program executes: its first task is to get its boot parameters from the bootp server. I had trouble getting the bootpd program which came with Slackware to work so I replaced it with bootparamd from the NetKit. <code>bootparamd</code> runs as a daemon, but could just as well run from inetd. It uses the file /etc/bootparams to hold boot config information:</p>
<pre>moriah% cat /etc/bootparams
hermon  root=moriah:/export/root/hermon swap=moriah:/export/swap
carmel  root=moriah:/export/root/carmel swap=moriah:/export/swap</pre>
<p>All that is specified in this case is the root and swap partitions for each of the 2 Sun&#8217;s &#8211; as I said they share a swap partition as only one is ever up at any one time.</p>
<p>From then on it&#8217;s plain sailing (you must of course have nfs working on the server so the clients can mount the filesystems). The boot loader mounts the root fs from the server, and loads the kernel (which in the case of NetBSD must be <code>/netbsd</code> &#8211; I only found this out by trial and error). The root fs in my case contains everything, but there&#8217;s no reason why you shouldn&#8217;t nfs mount other filesystems in the usual way of course once the kernel boots. Here&#8217;s the contents of <code>/export/root/hermon</code>, FWIW:</p>
<pre>moriah% ls -lF /export/root/hermon
total 3955
drwxr-xr-x   2 root     root         1024 Jan  5  1998 altroot/
drwxr-xr-x   2 root     root         1024 Jan  5  1998 bin/
-rw-------   1 root     root       458752 Aug 10 19:26 core
drwxr-xr-x   3 root     root         5120 Aug 17 01:35 dev/
drwxr-xr-x   8 root     root         2048 Aug 14 15:26 etc/
-rw-------   1 root     root        16656 Aug 13 15:58 getty.core
drwxr-xr-x   3 root     root         1024 Aug 13 15:55 home/
drwxr-xr-x   2 root     root         1024 Dec  6  1997 mnt/
lrwxrwxrwx   1 root     root           13 Aug 14 05:56 netbsd -&gt; netbsd.hermon*
-rw-r--r--   1 root     root      1025115 Aug  2 21:34 netbsd-gen
-rw-r--r--   1 root     root       769619 Aug  2 21:34 netbsd-inst
-rw-r--r--   1 root     root       983596 Aug  2 21:35 netbsd-rd
-rwxr-xr-x   1 root     root       750847 Aug 14 05:56 netbsd.hermon*
drwxr-xr-x   2 root     root         1024 Aug 10 00:21 proc/
drwxr-xr-x   3 root     root         1024 Aug 10 00:03 root/
drwxr-xr-x   2 root     root         2048 Jan  5  1998 sbin/
drwxr-xr-x   2 root     root         1024 Dec 19  1997 stand/
drwxr-xr-x   2 root     root         1024 Aug 13 16:06 swap/
lrwxrwxrwx   1 root     root           11 Aug 10 00:02 sys -&gt; usr/src/sys/
drwxrwxrwt   3 root     root         1024 Aug 17 01:18 tmp/
drwxr-xr-x  15 root     root         1024 Aug 13 15:45 usr/
drwxr-xr-x  19 root     root         1024 Dec  6  1997 var/</pre>
<p>There&#8217;s a few old kernels lying aroud, the one in use I configured and built for this machine. The only other thing that I had trouble figuring out was how to tell the Sun to swap on the server (on another partition). Here is <code>/export/root/hermon/etc/fstab</code> which specifies this (in this case no other f/s are mounted as the root contains everything):</p>
<pre>moriah% cat /export/root/hermon/etc/fstab

moriah:/export/swap none swap sw,nfsmntpt=/swap</pre>
<hr />
<p><a href="mailto:eddy@shofar.uklinux.net">Eddy Younger &lt;eddy@shofar.uklinux.net&gt;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/net-booting-a-diskless-sun3-from-a-linux-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux firewalls</title>
		<link>http://www.nelug.org.uk/linux-firewalls/</link>
		<comments>http://www.nelug.org.uk/linux-firewalls/#comments</comments>
		<pubDate>Thu, 11 Jan 2001 23:40:59 +0000</pubDate>
		<dc:creator>olly-bh</dc:creator>
				<category><![CDATA[Tutorials and resourses]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=79</guid>
		<description><![CDATA[Linux Firewalls What is a firewall? A firewall is a controlled gateway between one network and another (i.e. an intranet and the internet). It is not a universal panacea for computer security. You must follow other good security practices. Why &#8230; <a href="http://www.nelug.org.uk/linux-firewalls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h1>Linux Firewalls</h1>
<h2>What is a firewall?</h2>
<ul>
<li>A firewall is a controlled gateway between one network and another (i.e. an intranet and the internet).</li>
<li>It is not a universal panacea for computer security. You must follow other good security practices.</li>
</ul>
<h2>Why Firewalls?</h2>
<ul>
<li>You cannot trust everyone. Some people take pleasure in hacking into machines. Not all are malicious but some are!</li>
<li>Your computer holds private/confidential data an you have a duty to protect it.</li>
<li>You want to limit access from within your private network to specific external information/services (i.e. not mpeg3&#8242;s)</li>
<li>You want to monitor/record traffic for audit/security purposes. Beware of privacy laws!</li>
</ul>
<p><span id="more-79"></span></p>
<h2>Types of Firewall</h2>
<ul>
<li>Gateway based &#8211; you have to log onto a gateway machine which has restricted (if any) internal access and connect to external sites from the gateway.</li>
<li>Service based &#8211; A variation on the gateway based approach is to restrict the services which are available on machines which are visible externally.</li>
<li>Proxy based &#8211; provide external services via proxies which are accessible from within the private network. Only the proxies will have access to the external network.</li>
<li>Packet based &#8211; packets filters can control which network packets are forwarded between networks and may make access decisions based on the contents of the packets.</li>
<li>Masquerading &#8211; where all packets from a private network are rewritten in such a way that they appear to come from a single firewall (gateway) machine.</li>
</ul>
<h2>Gateway based</h2>
<p>A gateway system operates by having a gateway machine which does not forward packets at all. The user must log onto the gateway machine and from there access external sites.</p>
<p>In this setup the gateway machine typically has a very restricted set of services which are necessary for accessing external sites. You will often find that it does not export or import filesystems (via NFS) and that many system commands have been removed to limit the range of tools that a hacker can exploit. It is also typical that filesystems are mounted read-only to stop any trojan horse based attacks etc.</p>
<p>Accounts are strictly controlled on gateway machines and may require explicit authorisation to use them. In addition to this password ageing may be enabled ensuring that passwords are changed on a regular basis.</p>
<h2>Limited Service based</h2>
<p>Limiting services revolves around configuring system daemons to ensure that only the necessary daemons/services are available. In particular you may choose not to run services which give away information about users and system configuration. For example:</p>
<ul>
<li>finger &#8211; the finger service can give information about who is logged into your system, when they last logged in and other bits of information which are useful to hackers.</li>
<li>ident &#8211; information about users.</li>
<li>tftpd &#8211; allows access to (certain) files without any form of authorisation.</li>
</ul>
<p>These services/daemons are typically started at boot time or dynamically from inetd. The configuration/startup scripts are typically found in:</p>
<ul>
<li><code>/etc/inetd.conf</code></li>
<li><code>/etc/rc.d</code></li>
</ul>
<p>In general you should be very careful about giving external access to user daemons. Take special care over database daemons and similar user tools which may accept connections from anybody who cares to try.</p>
<h3>tcpd</h3>
<p>A simple but powerful method of protecting internet services is to use the tcpd wrapper program which is invoked in place of the normal service binary and first vets a connection to ensure that it is appropriate before invoking the normal binary with that connection. tcpd can only be used in place of daemons which have a one-to-one mapping between network connection and executable. In other words it is not possible to substitute a long running daemon (e.g. a database) with tcpd. The database must be configured correctly in this case.</p>
<h4>hosts_access(5)</h4>
<p>tcpd is primarily configured via the files <code>/etc/hosts.allow</code> and <code>/etc/hosts.deny</code>. These files contain a describe what action tcpd must take for specific services with connections coming from certains hosts/users.</p>
<p>An example which denies access to all hosts is</p>
<pre>
       /etc/hosts.deny:
          ALL: ALL
</pre>
<p>To allow authorised hosts to connect <code>/etc/hosts.allow</code> can be populated with entries similar to:</p>
<pre>
       /etc/hosts.allow:
          ALL: LOCAL @some_netgroup
          ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
</pre>
<p>The full configuration language is much more expressive than that described above and involve scripts which could be used to perform a reverse search on the connecting host to find out more information. A full description of this can be found in the <code>hosts_access</code> manual page which is found in section 5 of the manuals.</p>
<h4>tcpdchk</h4>
<p>The program tcpdchk can be used to check the configuration of tcpd to ensure that mistakes are not present which may provide security problems. It even checks if tcpd protection is appropriate for a particular daemon (note this is heuristic based &#8211; it is not magic!).</p>
<h2>Proxy based</h2>
<p>Proxies are very popular and are typically used to limit network usage by caching frequently accessed information and thus reducing bandwidth requirements.</p>
<p>In addition to this use it is possible to use proxies as controlled firewall breaches. By doing this you can monitor external traffic (for security purposes of course) and provide hackers with a limited scope for attacking your system.</p>
<p>Popular proxies include:</p>
<ul>
<li>tis firewall toolkit (www.tis.com) &#8211; includes sendmail, ftp, telnet proxies (amongst others) and also provides a generic proxy which can be used for other daemons.</li>
<li>socks &#8211; provides restricted access for many common tcp (and udp?) based services</li>
<li>squid &#8211; web based cacheing</li>
</ul>
<h2>Packet based</h2>
<p>A Packet based firewall involves selectively passing packets between different network interfaces based on the type of packet, source, destination and even the status of a connection.</p>
<p>Linux provides the IP chains facility (configured by the ipchains command) which allows a user to give the kernel about what should and should not be allowed between different interfaces.</p>
<p>A sample firewall configuration file is shown below. Note that this includes entries for IP masquerading.</p>
<h2>Masquerading</h2>
<p>An extension to packet based filtering is IP masquerading. Using this mechanism all external traffic has its IP headers rewritten in such a way that it appears that the packet has come from the gateway machine. For any external packets which are coming into the network the rewriting is reversed and the packet headers are rewritten to ensure that they go back to the appropriate internal machine. This hides all information about the internal network and makes it difficult for external sites to target specific machines within the network.</p>
<p>A common use for this technique is to allow an internal network which does not have proper addresses assigned to them to go via a single machine which does have an address assigned to it.</p>
<h2>Sample IP chains configuration</h2>
<pre>
#!/bin/sh
#
# Firewall rules.
# Invoked by rc.M after rc.inet?
#
# EJY 24/12/2000
#
# Flush all chains: start from a clean config.
/sbin/ipchains -F
/sbin/ipchains -X

# Create chain for input on ppp interface(s)
/sbin/ipchains -N ppp-in

# Default policy is deny on forward chain
/sbin/ipchains -P output ACCEPT 
/sbin/ipchains -P forward DENY 

# We trust anyone on the local ethernet,
# anything on ppp we don't
/sbin/ipchains -A input -i eth0 -j ACCEPT
/sbin/ipchains -A input -i ppp+ -j ppp-in

# Activate TOS mangling
/sbin/ipchains -A output -p tcp -d 0.0.0.0/0 telnet -t 0x01 0x10
/sbin/ipchains -A output -p tcp -d 0.0.0.0/0 ftp -t 0x01 0x10
/sbin/ipchains -A output -p tcp -s 0.0.0.0/0 ftp-data -t 0x01 0x08

# Deny spoofed addresses 
/sbin/ipchains -A ppp-in -j DENY -s 192.168.0.0/16
/sbin/ipchains -A ppp-in -j DENY -s 172.16.0.0/12
/sbin/ipchains -A ppp-in -j DENY -s 10.0.0.0/8

# Ditch multicast silently
/sbin/ipchains -A ppp-in -j DENY -d 224.0.0.0/4

# Do masquerading
/sbin/ipchains -A forward -j MASQ -s 192.168.200.0/24 -d ! 192.168.200.0/24

# Allow auth connections, as they're almost always requd.
/sbin/ipchains -A ppp-in -p tcp --destination-port auth -j ACCEPT

# 
# Log the skript kiddiez, just for fun...
#
/sbin/ipchains -A ppp-in -j DENY -l -p udp --destination-port 53
/sbin/ipchains -A ppp-in -j DENY -l -p udp --destination-port ftp
/sbin/ipchains -A ppp-in -j DENY -l -p tcp --destination-port 53
/sbin/ipchains -A ppp-in -j DENY -l -p tcp --destination-port ftp

# Deny all priveleged ports (previous rules have precedence ...
/sbin/ipchains -A ppp-in -p tcp --destination-port 1:1023 -j DENY
/sbin/ipchains -A ppp-in -p udp --destination-port 1:1023 -j DENY

# Block certain high-number ports, with logging ...

# Block NFS-server
/sbin/ipchains -A ppp-in -j DENY -l -p tcp -i  ppp0 --destination-port 2049
/sbin/ipchains -A ppp-in -j DENY -l -p udp -i  ppp0 --destination-port 2049

# Block X-server
/sbin/ipchains -A ppp-in -j DENY -l -p tcp -i  ppp0 --destination-port 6000:6016
/sbin/ipchains -A ppp-in -j DENY -l -p udp -i  ppp0 --destination-port 6000:6016

# Block IJB and Squid
/sbin/ipchains -A ppp-in -j DENY -l -p tcp -i  ppp0 --destination-port 8000
/sbin/ipchains -A ppp-in -j DENY -l -p udp -i  ppp0 --destination-port 8000
/sbin/ipchains -A ppp-in -j DENY -l -p tcp -i  ppp0 --destination-port 8080
/sbin/ipchains -A ppp-in -j DENY -l -p udp -i  ppp0 --destination-port 8080
#
# Block various known trojans
#
# ipchains -A ppp-in -p tcp --destination-port asp -j DENY -l
# ipchains -A ppp-in -p udp --destination-port asp -j DENY -l
ipchains -A ppp-in -p tcp --destination-port 31337 -j DENY -l
ipchains -A ppp-in -p udp --destination-port 31337 -j DENY -l
ipchains -A ppp-in -p tcp --destination-port 1243 -j DENY -l
ipchains -A ppp-in -p udp --destination-port 1243 -j DENY -l

# Allow remaining high-numbered ports ...
/sbin/ipchains -A ppp-in -p tcp --destination-port 1024: -j ACCEPT
/sbin/ipchains -A ppp-in -p udp --destination-port 1024: -j ACCEPT

</pre>
<h2>A more complex ipchains example</h2>
<p>This configuration was produced automatically by Robert Ziegler&#8217;s wonderful <a href="http://www.linux-firewall-tools.com/linux/firewall/index.html">Linux firewall design tool</a></p>
<pre>
#!/bin/sh

# ----------------------------------------------------------------------------
# Copyright (C) 1997, 1998, 1999, 2000  Robert L. Ziegler
#
#  Permission to use, copy, modify, and distribute this software and its
#  documentation for educational, research, private and non-profit purposes,
#  without fee, and without a written agreement is hereby granted. 
#  This software is provided as an example and basis for individual firewall
#  development.  This software is provided without warranty.
#
#  Any material furnished by Robert L. Ziegler is furnished on an 
#  "as is" basis.  He makes no warranties of any kind, either expressed 
#  or implied as to any matter including, but not limited to, warranty 
#  of fitness for a particular purpose, exclusivity or results obtained
#  from use of the material.
# ----------------------------------------------------------------------------

#  /etc/rc.d/rc.firewall
#  Invoked from /etc/ppp/ip-up, or
#  from /sbin/ifup-local, or
#  from /etc/sysconfig/network-scripts/ifup-post.

echo "Starting firewalling... "

# ----------------------------------------------------------------------------
#  Some definitions for easy maintenance.
#  EDIT THESE TO SUIT YOUR SYSTEM AND ISP.

EXTERNAL_INTERFACE="ppp0"               # Internet connected interface
LOOPBACK_INTERFACE="lo"                 # or your local naming convention
LOCAL_INTERFACE_1="eth0"                # internal LAN interface

IPADDR=$(/sbin/ifconfig | /bin/grep P-t-P | /usr/bin/cut -c 21-35)
LOCALNET_1="192.168.1.0/24"             # whatever private range you use

ANYWHERE="any/0"                        # match any IP address

DHCP_SERVER="any/0"
NAMESERVER_1="any/0"                    # everyone must have at least one

SMTP_SERVER="any/0"                     # Your ISP mail gateway. Your relay.
POP_SERVER="any/0"              # Your ISP pop mail server.
IMAP_SERVER="any/0"             # Your ISP imap mail server.

LOOPBACK="127.0.0.0/8"                  # reserved loopback address range
CLASS_A="10.0.0.0/8"                    # class A private networks
CLASS_B="172.16.0.0/12"                 # class B private networks
CLASS_C="192.168.0.0/16"                # class C private networks
BROADCAST_SRC="0.0.0.0"                 # broadcast source address
BROADCAST_DEST="255.255.255.255"        # broadcast destination address
PRIVPORTS="0:1023"                      # well known, privileged port range
UNPRIVPORTS="1024:65535"                # unprivileged port range

# ----------------------------------------------------------------------------

NFS_PORT="2049"                         # (TCP/UDP) NFS
SOCKS_PORT="1080"                       # (TCP) Socks
OPENWINDOWS_PORT="2000"                 # (TCP) openwindows

# X Windows port allocation begins at 6000 and increments to 6063
# for each additional server running.
XWINDOW_PORTS="6000:6063"               # (TCP) X windows

# traceroute usually uses -S 32769:65535 -D 33434:33523
TRACEROUTE_SRC_PORTS="32769:65535"
TRACEROUTE_DEST_PORTS="33434:33523"

# ----------------------------------------------------------------------------
# Default policy is DENY
# Explicitly accept desired INCOMING &amp; OUTGOING connections

    # Remove all existing rules belonging to this filter
    ipchains -F

    # Set the default policy of the filter to deny.
    ipchains -P input  DENY
    ipchains -P output REJECT
    ipchains -P forward REJECT

    # set masquerade timeout to 10 hours for tcp connections
    ipchains -M -S 36000 0 0


# ----------------------------------------------------------------------------

    # Enable IP Forwarding, if it isn't already
    echo 1 &gt; /proc/sys/net/ipv4/ip_forward

    # Enable TCP SYN Cookie Protection
    echo 1 &gt; /proc/sys/net/ipv4/tcp_syncookies

    # Enable always defragging Protection
    echo 1 &gt; /proc/sys/net/ipv4/ip_always_defrag

    # Enable broadcast echo  Protection
    echo 1 &gt; /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

    # Enable bad error message  Protection
    echo 1 &gt; /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses

    # Enable IP spoofing protection
    # turn on Source Address Verification
    for f in /proc/sys/net/ipv4/conf/*/rp_filter; do
        echo 1 &gt; $f
    done

    # Disable ICMP Redirect Acceptance
    for f in /proc/sys/net/ipv4/conf/*/accept_redirects; do
        echo 0 &gt; $f
    done

    # Disable Source Routed Packets
    for f in /proc/sys/net/ipv4/conf/*/accept_source_route; do
        echo 0 &gt; $f
    done

    # Log Spoofed Packets, Source Routed Packets, Redirect Packets
    for f in /proc/sys/net/ipv4/conf/*/log_martians; do
        echo 1 &gt; $f
    done


    # These modules are necessary to masquerade their respective services.
    /sbin/modprobe ip_masq_ftp

# ----------------------------------------------------------------------------
# LOOPBACK

    # Unlimited traffic on the loopback interface.

    ipchains -A input  -i $LOOPBACK_INTERFACE  -j ACCEPT 
    ipchains -A output -i $LOOPBACK_INTERFACE  -j ACCEPT 

# ----------------------------------------------------------------------------
# Unlimited traffic within the local network.

    # All internal machines have access to the fireall machine.

    ipchains -A input  -i $LOCAL_INTERFACE_1 -s $LOCALNET_1 -j ACCEPT 
    ipchains -A output -i $LOCAL_INTERFACE_1 -d $LOCALNET_1 -j ACCEPT 

# ----------------------------------------------------------------------------
# Masquerade internal traffic.

    # All internal traffic is masqueraded externally.
    ipchains -A forward -i $EXTERNAL_INTERFACE -s $LOCALNET_1 -j MASQ

# ----------------------------------------------------------------------------
# SPOOFING &amp; BAD ADDRESSES
# Refuse spoofed packets.
# Ignore blatantly illegal source addresses.
# Protect yourself from sending to bad addresses.

    # Refuse incoming packets pretending to be from the external address.
    ipchains -A input  -i $EXTERNAL_INTERFACE  -s $IPADDR -j DENY -l

# ----------------------------------------------------------------------------
# NOTE:
#      The symbolic names used in /etc/services for the port numbers vary by
#      supplier.  Using them is less error prone and more meaningful, though.

# ----------------------------------------------------------------------------
# TCP UNPRIVILEGED PORTS
# Avoid ports subject to protocol &amp; system administration problems.

    # NFS: establishing a TCP connection
    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $NFS_PORT -j DENY -l
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $NFS_PORT -j REJECT 

    # openwindows: establishing a connection
    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $OPENWINDOWS_PORT -j DENY -l
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $OPENWINDOWS_PORT -j REJECT 


    # Xwindows: establishing a connection
    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $XWINDOW_PORTS -j DENY -l
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $XWINDOW_PORTS -j REJECT 

    # SOCKS: establishing a connection
    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $SOCKS_PORT -j DENY -l
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp -y \
             --destination-port $SOCKS_PORT -j REJECT 

# ----------------------------------------------------------------------------
# UDP UNPRIVILEGED PORTS
# Avoid ports subject to protocol &amp; system administration problems.

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             --destination-port $NFS_PORT -j DENY -l

    # UDP INCOMING TRACEROUTE
    # traceroute usually uses -S 32769:65535 -D 33434:33523

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             --source-port $TRACEROUTE_SRC_PORTS \
             --destination-port $TRACEROUTE_DEST_PORTS -j DENY -l

# ----------------------------------------------------------------------------

    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp ! -y \
             -d $IPADDR -j ACCEPT 

    # ------------------------------------------------------------------

    # DNS server (53)
    # ---------------

    # DNS forward-only nameserver
    # ---------------------------

    # forward-only can use regular TCP protocol to forwarders

    ipchains -A output -i $EXTERNAL_INTERFACE -p udp  \
             -s $IPADDR 53 \
             -d $NAMESERVER_1 53 -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             -s $NAMESERVER_1 53 \
             -d $IPADDR 53 -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             -d $NAMESERVER_1 53 -j ACCEPT 

    # ------------------------------------------------------------------

    # HTTP client (80)
    # ----------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 80 -j ACCEPT 

    # ------------------------------------------------------------------

    # HTTPS client (443)
    # ------------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 443 -j ACCEPT 

    # ------------------------------------------------------------------

    # POP client (110)
    # ----------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 110 -j ACCEPT 

    # ------------------------------------------------------------------

    # IMAP client (143)
    # -----------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             -d $IMAP_SERVER 143 -j ACCEPT 

    # ------------------------------------------------------------------

    # SMTP client (25)
    # ----------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             -d $SMTP_SERVER 25 -j ACCEPT 

    # ------------------------------------------------------------------

    # TELNET client (23)
    # ------------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 23 -j ACCEPT 

    # ------------------------------------------------------------------

    # AUTH server (113)
    # -----------------

    # Reject, rather than deny, the incoming auth port. (NET-3-HOWTO)
    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp  \
             --source-port $UNPRIVPORTS \
             -d $IPADDR 113 -j REJECT 


    # AUTH client (113)
    # -----------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 113 -j ACCEPT 

    # ------------------------------------------------------------------

    # WHOIS client (43)
    # -----------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 43 -j ACCEPT 

    # ------------------------------------------------------------------

    # FINGER client (79)
    # ------------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 79 -j ACCEPT 

    # ------------------------------------------------------------------

    # FTP client (21)
    # ---------------

    # outgoing request
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 21 -j ACCEPT 


    # PORT mode data channel
    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp  \
             --source-port 20 \
             -d $IPADDR $UNPRIVPORTS -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp ! -y \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port 20 -j ACCEPT 


    # PASSIVE mode data channel creation
    ipchains -A output -i $EXTERNAL_INTERFACE -p tcp  \
             -s $IPADDR $UNPRIVPORTS \
             --destination-port $UNPRIVPORTS -j ACCEPT 

# ----------------------------------------------------------------------------
# UDP accept only on selected ports
# ---------------------------------


    # DHCP client (67, 68)
    # --------------------

    # allow dhcp server (67) to connect to dhcp client (68)
    # Note: the DHCP server is the only externel source of broadcast
    #       messages we should see, ever.

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             -s $DHCP_SERVER 67 \
             -d $IPADDR 68 -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p udp  \
             -s $IPADDR 68 \
             -d $DHCP_SERVER 67 -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             -s $DHCP_SERVER 67 \
             -d $BROADCAST_DEST 68 -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p udp  \
             -s $BROADCAST_SRC 68 \
             -d $DHCP_SERVER 67 -j ACCEPT 

    # Getting renumbered
    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             -s $BROADCAST_SRC 67 \
             -d $BROADCAST_DEST 68 -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p udp  \
             -s $BROADCAST_SRC 68 \
             -d $BROADCAST_DEST 67 -j ACCEPT 

    # As a result of the above, we're supposed to change our IP address with
    # this message, which is addressed to our new address before the dhcp
    # client has received the update.

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             -s $DHCP_SERVER 67 \
             --destination-port 68 -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             --source-port 67 \
             -d $IPADDR 68 -j DENY -l

    # ------------------------------------------------------------------

    # OUTGOING TRACEROUTE
    # -------------------
    ipchains -A output -i $EXTERNAL_INTERFACE -p udp  \
             -s $IPADDR $TRACEROUTE_SRC_PORTS \
             --destination-port $TRACEROUTE_DEST_PORTS -j ACCEPT -l

# ----------------------------------------------------------------------------
# ICMP

    #    To prevent denial of service attacks based on ICMP bombs, filter
    #    incoming Redirect (5) and outgoing Destination Unreachable (3).
    #    Note, however, disabling Destination Unreachable (3) is not
    #    advisable, as it is used to negotiate packet fragment size.

    # For bi-directional ping.
    #     Message Types:  Echo_Reply (0),  Echo_Request (8)
    #     To prevent attacks, limit the src addresses to your ISP range.
    # 
    # For outgoing traceroute.
    #     Message Types:  INCOMING Dest_Unreachable (3), Time_Exceeded (11)
    #     default UDP base: 33434 to base+nhops-1
    # 
    # For incoming traceroute.
    #     Message Types:  OUTGOING Dest_Unreachable (3), Time_Exceeded (11)
    #     To block this, deny OUTGOING 3 and 11

    #  0: echo-reply (pong)
    #  3: destination-unreachable, port-unreachable, fragmentation-needed, etc.
    #  4: source-quench
    #  5: redirect
    #  8: echo-request (ping)
    # 11: time-exceeded
    # 12: parameter-problem

    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type echo-reply \
             -d $IPADDR -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type destination-unreachable \
             -d $IPADDR -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type source-quench \
             -d $IPADDR -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type echo-request \
             -d $IPADDR -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type time-exceeded \
             -d $IPADDR -j ACCEPT 

    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type parameter-problem \
             -d $IPADDR -j ACCEPT 


    ipchains -A output -i $EXTERNAL_INTERFACE -p icmp  \
             -s $IPADDR echo-reply -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p icmp  \
             -s $IPADDR fragmentation-needed -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p icmp  \
             -s $IPADDR source-quench -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p icmp  \
             -s $IPADDR echo-request -j ACCEPT 

    ipchains -A output -i $EXTERNAL_INTERFACE -p icmp  \
             -s $IPADDR parameter-problem -j ACCEPT 

# ----------------------------------------------------------------------------
# Enable logging for selected denied packets

    ipchains -A input  -i $EXTERNAL_INTERFACE -p tcp  -j DENY -l

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             --destination-port $PRIVPORTS -j DENY -l

    ipchains -A input  -i $EXTERNAL_INTERFACE -p udp  \
             --destination-port $UNPRIVPORTS -j DENY -l


    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type 5 -j DENY -l
    ipchains -A input  -i $EXTERNAL_INTERFACE -p icmp  \
             --icmp-type 13:255 -j DENY -l

    ipchains -A output -i $EXTERNAL_INTERFACE  -j REJECT -l

# ----------------------------------------------------------------------------

echo "done"

exit 0


</pre>
<hr />
<address><a href="mailto:oldelvet@netscapeonline.co.uk">Richard Mortimer</a></address>
<p>Last modified: Thu Jan 11 23:40:46 GMT 2001</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/linux-firewalls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Configuring Email Systems</title>
		<link>http://www.nelug.org.uk/configuring-email-systems/</link>
		<comments>http://www.nelug.org.uk/configuring-email-systems/#comments</comments>
		<pubDate>Wed, 07 Jun 2000 06:09:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials and resourses]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=51</guid>
		<description><![CDATA[NELUG, 7/6/2000 Eddy Younger (eddy@shofar.uklinux.net) Software Components of the Email System There are principally three classes of software components involved in transfering a mail message from the sender to the recipient: MUA &#8211; mail user agent, used to read, compose &#8230; <a href="http://www.nelug.org.uk/configuring-email-systems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2 align="CENTER">NELUG, 7/6/2000</h2>
<h2 align="CENTER">Eddy Younger (<a href="mailto:eddy@shofar.uklinux.net">eddy@shofar.uklinux.net</a>)</h2>
<p align="CENTER">
<h2>Software Components of the Email System</h2>
<p>There are principally three classes of software components involved in transfering a mail message from the sender to the recipient:</p>
<ol>
<li>MUA &#8211; mail user agent, used to read, compose and post mail.</li>
<li>MTA &#8211; mail transport agent. MTA&#8217;s at the source and destination hosts (and possibly also intermediate hosts) pass the messages from one to another</li>
<li>MDA &#8211; mail delivery agent. At the ultimate destination host, the MDA receives the message from the local MTA and delivers it to its ultimate destination, usually the recipient&#8217;s mailbox file.</li>
</ol>
<p align="LEFT">In the modern world almost all email transport is achieved using SMTP &#8211; the Simple Mail Transport Protocol &#8211; or its Extended variant ESMTP. MTA&#8217;s speak to each other in (E)SMTP. You can send mail without using a MUA if you wanted to, by talking SMTP directly to the MTA, and it used to be possible to do all kinds of nefarious things by doing so, though thankfully most mail servers are much more secure in these days of Skript Kiddies and Spam.</p>
<p><span id="more-51"></span></p>
<h3>MUA&#8217;s</h3>
<h4>Reading Mail:</h4>
<p>Commonly there are three methods to access the mailbox:</p>
<ol>
<li>read the mailbox directly (/bin/mail, most Unix mail clients);</li>
<li>POP3 &#8211; Post-Office Protocol. Mail reader communicates with POP3 server which accesses the mailbox and transfers messages to the mail reader, which re-files them locally;</li>
<li>IMAP &#8211; another client/server system. The server is capable of transfering header information to the client without the message body, and of deleting messages from the mailbox on behalf of the client. The messages need only be uploaded to be read or filed.</li>
</ol>
<p>Modern Unix mail clients (pine, mutt, emacs VM) can handle POP, IMAP or a local mailbox. Others such as Netscape need to talk to a POP or IMAP server, even if the mailbox is local.</p>
<h4>Sending mail:</h4>
<p>MUA hands mail on to a MTA. This may be on the local host or on a remote host (maybe at your ISP), depending upon which MUA you&#8217;re using and how it&#8217;s configured. The MUA generally uses SMTP to talk to the MTA; in rarer (rarer on Unix, that is) case POP may be used to post mail as well as to read it.</p>
<h3>MTA&#8217;s</h3>
<p>Sendmail is the most widely used, most powerful, probably the most efficient, and (formerly) the hardest to configure. It originates from a time when memory and CPU bandwidth were expensive, and when there were many and varied networks other than the Internet (BITNET, EARN, JANET, UUCP &#8230;). Sendmail is capable of acting as a gateway between such different networks, as a mail-to-fax or mail-to usenet gateway, etc. It is very resource-efficient. Virtually every piece of mail which moves on the backbone is handled by sendmail at some point (chalk up one more for Open Source Software).</p>
<p>Since the virtual demise of all other networks, numerous other MTA&#8217;s with more limited capabilities have come along, e.g Exim, qmail, Postfix. These tend to lack the gateway capabilities of sendmail, for example, but as a result are simpler, and regarded by some as more secure. A major selling point seems to be that their configuration files are more readable than sendmail&#8217;s, which is undoubtably true but largely irrelevant as we shall see. Some very large sites are now running on these alternative MTA&#8217;s however &#8211; Freeserve runs on Exim for example.</p>
<h3>MDA&#8217;s</h3>
<p>The role of the MDA is to accept a message from the MTA on the final destination host and deliver it to its destination, usually a user&#8217;s mailbox. On Unix systems (ATT variants) the MDA for mail to a user&#8217;s mailbox is usually /bin/mail (though interestingly the MDA in the default sendmail.cf on Slackware Linux is procmail). For mail to a program (where allowed) it is /bin/sh.</p>
<h2>The obligatory diagram</h2>
<p><img src="http://old.nelug.org.uk/pix/mail-route.gif" alt="" name="Graphic1" width="675" height="358" align="LEFT" border="0" /><br clear="LEFT" /></p>
<p>This picture may be complicated by</p>
<ol>
<li>DNS MX records for the destination</li>
<li>Aliases, either at the source or destination</li>
</ol>
<h3>MX records</h3>
<p>Once the MTA has deciphered the destination address, it does a name-server lookup (usually DNS, but maybe NIS or whatever) to find it&#8217;s IP address. MX records are special DNS records used by the mail system: a destination (e.g durham.ac.uk) may one or more MX records associated with it which point to the IP adresses of hosts which will recieve mail on behalf of that destination. In such cases, the destination may be a host which is incapable of receiving mail (no MTA), or may not exist as a physical machine at all (e.g. durham.ac.uk or shofar.uklinux.net). The MX records for these destination point to a real machine to which mail will actually be routed (a destination may have several MX records, possibly with different preference values).</p>
<h3>Aliases</h3>
<p>There are two classes of aliases:</p>
<ol>
<li>system wide, defined in /etc/aliases or the mail.aliases nis map; these are expanded by the MTA</li>
<li>user&#8217;s aliases, usually defined in ~/.mailrc; these are expanded by the MUA when the message is posted</li>
</ol>
<h2>Configuring sendmail</h2>
<p>The main configuration file for sendmail, by default /etc/sendmail.cf, is large and difficult to read even in the simplest configuration. For this reason sendmail has a reputation for being hard to configure. However, nowadays sendmail.cf files may be generated using the <strong>m4</strong> macro processor from a source file of typically less than a dozen lines by calling out the pre-defined macros which form part of the sendmail distribution. Directly editing sendmail.cf is only necessary in unusual configurations.</p>
<p>sendmail.cf files contain a set of definitions (which essentially set values for macros used elsewhere) and rewriting rules which rewrite the headers of mail messages &#8211; most particularly the address portions &#8211; before delivering them to the destination (or next) MTA. The rules consist of a LHS which is a pattern to match against the input, and a RHS which defines how a matching input should be re-written. A rule is applied recursively until the match fails (or it is explicitly terminated), and rules may &#8220;call&#8221; other rules. The &#8220;entry point&#8221; is rule 3, confusingly enough.</p>
<p>You can now configure sendmail without knowing or understanding anything about the syntax of sendmail.cf</p>
<h2>Configuring email on a dial-up host</h2>
<p>There are two basic approaches, with various possible points in between:</p>
<h3>Local MUA only</h3>
<p>In this scenario, there is no mail service at all on the local machine. A mail client is used which can download mail from the dial-up service and can hand over sent mail directly to the MTA on the server. This is the approach taken by ISP&#8217;s in the software they supply to end users. This will work fine if you don&#8217;t need anything sophisticated like multi-drop mailbox capabilities, or to provide mail services to a lan through a dial-up gateway (though even that may be possible up to a point). Given the capabilities of a Linux box it&#8217;s pretty uninspiring though.</p>
<h2>A <em>real</em> email service</h2>
<p>As usual, there&#8217;s more than one way of doing it. We have to cope with the fact that the connection from the server to the internet (the dial-up connection) comes and goes. We will also usually need to deal with the fact that</p>
<ol>
<li>we only have one mailbox at the ISP into which all mail for &lt;any_user&gt;@&lt;ourname&gt;.isp.co.uk is delivered.</li>
<li>we have to collect email via POP or IMAP, and not SMTP through our local MTA.</li>
</ol>
<p>What follows is a case study based on my own setup, where one machine acts as a mail hub and also a dial-up gateway for a local area network. Sending mail to the outside world, and collecting mail from two separate ISP&#8217;s, are dealt with separately owing to the constraints of ISP&#8217;s and dial-up links.</p>
<h2>Sending mail</h2>
<p>Sending of mail is dealt with by MTA&#8217;s (in this case, sendmail) running on the LAN clients and the mail hub. Mail clients (MUA&#8217;s) hand over mail to the MTA on the local machine (in the case of Netscape mail and friends they <em>could </em>hand it straight to the mail hub). Sendmail on the clients uses the dumbest possible configuration, known as the &#8220;nullclient&#8221; configuration after the m4 macro used to generate it:</p>
<pre>include(`../m4/cf.m4')                                 include the boilerplate 
                                                       sendmail.cf content
VERSIONID(`@(#)generic-shofar.mc 8.9 (Berkeley)')      gets included as a comment 
                                                       in the .cf file
OSTYPE(linux)dnl                                       tells m4 which definitions 
                                                       to use for platform-specific 
                                                       paths, etc
DOMAIN(generic)dnl                                     include vanilla domain-
                                                       specific definitions
FEATURE(nullclient,moriah)                             hand over all mail to the 
                                                       MTA on the machine called
                                                       "moriah"</pre>
<p><strong>m4 configuration file for dumb lan clients</strong></p>
<p>This generates a sendmail.cf file of 642 lines. The only support this provides is for forwarding <strong>all</strong> mail to the named mail hub. No aliases are expanded on the originating host, nor are .forward files processed &#8211; this implies that user acounts should be visible on the mail hub if .forward files are to be used.</p>
<p>The sendmail configuration on the mail hub needs to be more complicated. It&#8217;s major job is to rewrite senders&#8217; mail addresses to be that of the ISP mailbox, in order that mail can be replied-to, and also to prevent anti-spam and anti-spoofing rules from rejecting the message. Well-configured MTA&#8217;s will refuse to accept messages whose &#8220;From:&#8221; address does not resolve to a valid host or MX record &#8211; this presents a problem for hosts or LAN&#8217;s with only dial-up connections, which <em>should be</em> using network addresses from the defined set of private ranges, and whose local host/domain names are not resolvable out in the real world. The second (though optional) function of the mail hub&#8217;s configuration is to define a &#8220;smart host&#8221; within the ISP to which all outgoing mail is passed. This has the advantage that if the ultimate destination of a message is temporarilly unavailable, the smarthost and not our mail hub will take care of retrying the delivery. It also means that if the link to the destination is very slow we don&#8217;t have to stay connected until the delivery is complete &#8211; the smarthost will accept the mail and we can hang up the phone and allow it to take care of the delivery. The disadvantage is that if delivery fails we won&#8217;t find out until we next connect to dowload our mail. Note that some ISP&#8217;s (e.g. Freeserve) interpose a smarthost whether you ask for one or not.</p>
<pre>include(`../m4/cf.m4')
VERSIONID(`@(#)mailhub-shofar.mc 8.8 (Berkeley)5/19/98')
OSTYPE(linux)dnl
DOMAIN(generic)dnl
define(SMART_HOST,smtp:mail.uklinux.net)          define the smart host and the 
                                                  mailer thru' which to access it
MASQUERADE_AS(shofar.uklinux.net)dnl              From: and Reply-To: addresses must 
                                                  be rewritten as this
MASQUERADE_DOMAIN(shofar.org.uk)dnl               all addresses in this domain are to 
                                                  be masqueraded as above
FEATURE(allmasquerade)dnl                         causes local aliases and To: 
                                                  addresses in above domain to 
                                                  be masqueraded
FEATURE(masquerade_entire_domain)dnl              rewrite &lt;any_host&gt;.shofar.org.uk to 
                                                  be shofar.uklinux.net
FEATURE(masquerade_envelope)dnl                   masquerade the envelope as well as 
                                                  the From: line (see below)
MAILER(local)dnl                                  mail will either be delivered to a 
                                                  local MDA
MAILER(smtp)dnl                                   or transferred via SMTP</pre>
<p><strong>m4 configuration file for dial-up mail hub</strong></p>
<p>Most of the masquerade features in this configuration are the result of the fact that I am using a bogus domain name (shofar.org.uk) on the local LAN. We want to be able to send mail to aliases defined locally (e.g. NELUG-announce) and have that rewritten as &lt;local_alias_name&gt;@shofar.uklinux.net ( hence FEATURE(allmasquerade) ), so that recipients can &#8220;reply-to-all&#8221; and it will work (but probably not the way they expect). We also want mail from any host on the LAN to have its address masqueraded ( FEATURE(masquerade_entire_domain) ). Most importantly, we want the envelope From address (not just the From and Reply_To in the header) to be masqueraded, as this is the address used to</p>
<ol>
<li>return bounces; and</li>
<li>check for spoofed sender-addresses</li>
</ol>
<p>It is therefore imperative that the envelope From address is resolvable to a valid address, which &#8220;eddy@shofar.org.uk&#8221; definitely is not (outside my private LAN).</p>
<p>Thus, all mail originating in the LAN is passed to sendmail on the mail hub, who will attempt to transfer the messages to the smarthost. If this fails, either because the dialup link isn&#8217;t up or the smarthost is broken, sendmail places the messages in a queue (by default /var/spool/mqueue), and will retry each message at intervals (the -q commabd-line parameter), warn the sender after a specified (in sendmail.cf) period, and give up and return the mail if a time limit (you guessed&#8230;) is exceeded. Because it is more usual for the link to be down than up, we don&#8217;t want to rely on sendmail happening to retry at a time when the link is actually there. So, one thing that the ip-up script does (whenever the link comes up, remember&#8230;) is to run &#8220;sendmail -q&#8221; which causes an instance of sendmail to start, process all queued message once, then terminate. Provided the smarthost isn&#8217;t broken, this will cause the queue to be flushed.</p>
<h3>Generating the .cf file</h3>
<p>Simplicity itself. Assuming you&#8217;ve created the m4 file and named it &#8220;&lt;hostname&gt;.mc&#8221; &#8211; a good idea if you&#8217;re going to produce config. files for several hosts &#8211; in the cf/cf directory of the sendmail distribution, simply &#8220;make &lt;hostname&gt;.cf&#8221; in the same directory, and your half-dozen lines of m4 source will be translated into many hundred lines of mystic runes. Copy the resulting &#8220;host.cf&#8221; to /etc/sendmail.cf on the target machine, kill and restart sendmail if it&#8217;s running in daemon mode. No, you don&#8217;t need to reboot, and you don&#8217;t need to insert the distribution cd several times over.</p>
<h2>Receiving mail</h2>
<p>To receive mail, we want to poll the mail services at two different ISP&#8217;s, which support only POP for mail retrieval, and deliver the messages to the appropriate mailboxes on the local mail hub. Client machines on the LAN all mount the mail spool directory (/var/mail) via NFS and so have direct access to the mailboxes. To provide for users of Netscape mail (or Windoze mail clients) we&#8217;d need to run a POP server on the mail hub, but up with that I no longer have to put.</p>
<p>The ISP mailboxes are multi-drop, i.e. if I requested an email address of &#8220;eddy@shofar.uklinux.net&#8221;, then &#8220;&lt;any_user_name_at_all&gt;@shofar.uklinux.net&#8221;, is a valid email address, and the mail will end up in the same mailbox at the ISP.</p>
<p>To collect mail, we use Eric Raymond&#8217;s most excellent fetchmail program, which deals quite nicely with all these requirements. It can be configured to poll a number of mailboxes (using POP3 or IMAP), retrieve the mail and forward via sendmail to either a single local user, or to map user-names in the recipient address of the message on a one-to-one basis to users on the local system and forward mail accordingly. User names in the mail address need not be the same as those on the local mail hub &#8211; fetchmail takes care of the mapping.</p>
<h3>Fetchmail configuration</h3>
<p>Fetchmail is run from the ip-up script whenever the dial-up link comes up; it is configured to poll the mailboxes at 5 minute intervals while the link remains up. The configuration file is .fetchmailrc (in root&#8217;s home directory since fetchmail runs as root from ip-up). In order for it to run without intervention, the .fetchmailrc file contains passwords to log in to the POP3 accounts, which represents a security risk in some environments despite it being unreadable except by root.</p>
<pre># Configuration created 11th May 2000 by hand
#
set syslog                        #error logging via syslog
set postmaster "postmaster"       #last-resort recipient if mappings fail
set no bouncemail                 #don't bounce mail to sender on error
#
# "Single-drop" ISP mailbox
#
poll pop.freeserve.net with proto POP3
       user "shofar.freeserve.co.uk" there with password "**********" 
       is eddy here options flush 
#
# "Multi-drop" ISP mailbox
#
poll mail.uklinux.net with proto POP3 aka shofar.uklinux.net
       user "shofar" with password "**********" to eddy nelug=eddy NELUG-admin 
nelug-approval=eddy NELUG-list root keith here options flush</pre>
<p><strong>.fetchmailrc for dial-up mail hub</strong></p>
<p>The first mailbox (pop.freeserve.net) is a simple case where we want all mail to be delivered to a single user on the local machine, regardless of what the username in the mail address might be. In the second case, the &#8220;to&#8221; keyword defines this to be a multidrop mailbox, and we list recipient names corresponding to local user names: remote-name=local-name specifies a mapping from the name in the mail address to a local user name; names without a corresponding &#8220;=local-name&#8221; mean that this name in the mail address should be mapped to the same local user name (equivalent for example to &#8220;eddy=eddy&#8221;, &#8220;NELUG-admin=NELUG-admin&#8221; in the above). Any mail address containing a username which is not listed will be delivered to the username specified in the postmaster variable set in the preamble (in this case &#8220;postmaster&#8221;).</p>
<p>In the second case, fetchmail will actively parse the mail headers in order to determine who the mail was addressed to (unlike the first case where it doesn&#8217;t care, it just forwards everything to &#8220;eddy&#8221;). For this reason, we need to specify using the &#8220;aka&#8221; keyword the host part of the mail address we should expect to find, as this is different from the hostname of the machine we are retrieving the mail from.</p>
<h2>Debugging</h2>
<p>Sendmail (and fetchmail if you &#8220;set syslog&#8221;) log messages via syslog to say what their doing. Sendmail in particular logs messages about every mail message it processes.</p>
<p><strong>Example:</strong></p>
<pre>Jun  6 18:13:42 moriah fetchmail[295]: POP3&gt; TOP 3 99999999 
Jun  6 18:13:42 moriah fetchmail[295]: POP3&lt; +OK Top of message follows 
Jun  6 18:13:42 moriah fetchmail[295]: reading message 3 of 4 (3512 octets) 
Jun  6 18:13:42 moriah fetchmail[295]: SMTP&gt; MAIL FROM:&lt;ey86798@herring.uk.sun.c
om&gt; BODY=7BIT SIZE=3512 
Jun  6 18:13:42 moriah fetchmail[295]: SMTP&lt; 250 &lt;ey86798@herring.uk.sun.com&gt;...
 Sender ok 
Jun  6 18:13:42 moriah fetchmail[295]: SMTP&gt; RCPT TO:&lt;eddy@localhost&gt;
Jun  6 18:13:42 moriah fetchmail[295]: SMTP&lt; 250 &lt;eddy@localhost&gt;... Recipient o
k 
Jun  6 18:13:42 moriah fetchmail[295]: SMTP&gt; DATA 
Jun  6 18:13:42 moriah fetchmail[295]: SMTP&lt; 354 Enter mail, end with "." on a l
ine by itself 
Jun  6 18:13:43 moriah fetchmail[295]: SMTP&gt;. (EOM) 
Jun  6 18:13:43 moriah sendmail[341]: SAA00341: from=&lt;ey86798@herring.uk.sun.com
&gt;, size=3530,, pri=33530, nrcpts=1, msgid=&lt;14652.56766.948321.273973@her
ring&gt;, bodytype=7BIT, proto=ESMTP, relay=root@localhost [127.0.0.1]
Jun  6 18:13:43 moriah fetchmail[295]: SMTP&lt; 250 SAA00341 Message accepted for d
elivery 
Jun  6 18:13:43 moriah fetchmail[295]:  flushed 
Jun  6 18:13:43 moriah fetchmail[295]: POP3&gt; DELE 3^M 
Jun  6 18:13:44 moriah fetchmail[295]: POP3&lt; +OK Message deleted 
Jun  6 18:13:44 moriah sendmail[342]: SAA00341: to=&lt;eddy@localhost&gt;, delay=00:00
:02, xdelay=00:00:01, mailer=local, stat=Sent
Jun  6 18:13:44 moriah sendmail[335]: SAA00334: to=eddy             , delay=00:0
0:06, xdelay=00:00:05, mailer=local, stat=Sent</pre>
<p>This shows fetchmail retrieving a message via POP3, forwarding it to sendmail for delivery, and subsequently deleting the message from the POP server. It also shows the messages logged by sendmail on receipt and delivery of the message (the two sets of messages are interleaved in the file &#8211; a not uncommon occurrence in log files).</p>
<p>Sendmail may also be run from the command line is debugging modes to allow one to see exactly how it&#8217;s processing addresses, for example to produce a trace of the rewrite rules as they fire, and to trace the rewriting of the address. See the bat book or the red book for details of debugging flags.</p>
<p>The mail headers themselves contain valuable information which can help debug bounces or mail forwarding loops. Each MTA adds its own &#8220;Received&#8230;&#8221; line as it processes the message. For sendmail, the format of the Received: line is defined in sendmail.cf.</p>
<p><strong>Example:</strong></p>
<pre>From paulmidgley@freeuk.com  Sat Jun  3 20:58:33 2000
Received: from localhost (root@localhost [127.0.0.1])
        by moriah.shofar.org.uk (8.9.3/8.9.1) with ESMTP id UAA00617
        for &lt;eddy@localhost&gt;; Sat, 3 Jun 2000 20:58:31 +0100
Received: from mail.uklinux.net
        by localhost with POP3 (fetchmail-5.1.2)
        for eddy@localhost (multi-drop); Sat, 03 Jun 2000 20:58:32 +0100 (BST)
Received: from scrabble.freeuk.net (scrabble.freeuk.net [212.126.144.6])
        by www.uklinux.net (8.9.3/8.8.7) with ESMTP id SAA09791
        for &lt;eddy@shofar.uklinux.net&gt;; Sat, 3 Jun 2000 18:26:30 +0100
Received: from [212.126.152.202] (helo=z4t4z8)
        by scrabble.freeuk.net with smtp (Exim 3.12 #1)
        id 12yHgW-00022v-00
        for eddy@shofar.uklinux.net; Sat, 03 Jun 2000 18:26:08 +0100
Message-ID: &lt;001301bfcd7f$fb61e220$ca987ed4@z4t4z8&gt;
MIME-Version: 1.0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Lookout Excess 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
From: "Paul Midgley" &lt;paulmidgley@freeuk.com&gt;
To: "Eddy Younger" &lt;eddy@shofar.uklinux.net&gt;
Subject: Internet access
Date: Sat, 3 Jun 2000 18:18:25 +0100</pre>
<p>Here we can see the route the message took from sender to recipient and the MTA&#8217;s involved at each stage. The message was generated by something called &#8220;Microsoft Outlook (??)&#8221;. It was transferred first of all to scrabble.freeuk.net which was running Exim 3.12. scrabble.freeuk.net passed the message to www.uklinux.net, which is running sendmail v8.9.3: this is despite the fact that the message was addressed to shofar.uklinux.net &#8211; this probably indicates that there is an MX record for shofar.uklinux.net pointing to www.uklinux.net. (The version numbers in parentheses are <em>sendmail-version</em>/<em>config-file-version</em>. <em>config-file-version </em>is actually the value of the macro <em>Z</em> defined in the config file). The message has now reached its destination according to the address in the envelope, but this is not the end of its travels, as fetchmail now comes along and removes it from the mailbox, rewrites its envelope address and re-inserts it into the email system by passing it to sendmail (v 8.9.3) on moriah.shofar.org.uk. As the envelope To address has been rewritten by fetchmail to be the local host, sendmail delivers it locally. It would be perfectly possible though for the envelope address written by fetchmail to be a local alias which expanded to a remote address, and hence for the message to be re-routed over the internet &#8211; this is how the old NELUG mailing list worked.</p>
<p><strong>Example 2:</strong> the above config. in action</p>
<pre>From owner-nelug-eddy=shofar.uklinux.net@lists.lug.org.uk  Thu Jun  1 21:12:45 2000
Received: from localhost (root@localhost [127.0.0.1])
        by moriah.shofar.org.uk (8.9.3/8.9.1) with ESMTP id VAA00390
        for &lt;eddy@localhost&gt;; Thu, 1 Jun 2000 21:12:44 +0100
Received: from mail.uklinux.net
        by localhost with POP3 (fetchmail-5.1.2)
        for eddy@localhost (multi-drop); Thu, 01 Jun 2000 21:12:44 +0100 (BST)
Received: from lug.org.uk (qmailr@lug.org.uk [195.92.249.253])
        by www.uklinux.net (8.9.3/8.8.7) with SMTP id VAA29981
        for &lt;eddy@shofar.uklinux.net&gt;; Thu, 1 Jun 2000 21:24:38 +0100
Received: (qmail 13274 invoked by uid 300); 1 Jun 2000 20:24:19 -0000
Delivered-To: nelug@lists.lug.org.uk
Received: (qmail 13265 invoked from network); 1 Jun 2000 20:24:19 -0000
Received: from ns0.uklinux.net (HELO www.uklinux.net) (root@212.1.130.10)
  by lug.org.uk with SMTP; 1 Jun 2000 20:24:19 -0000
Received: from moriah.shofar.org.uk (root@ppp-1-201.cvx1.telinco.net [212.1.136.201])
        by www.uklinux.net (8.9.3/8.8.7) with ESMTP id VAA29961;
        Thu, 1 Jun 2000 21:24:13 +0100
Received: (from eddy@localhost)
        by moriah.shofar.org.uk (8.9.3/8.9.1) id UAA00333
        for NELUG-announce; Thu, 1 Jun 2000 20:55:21 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-ID: &lt;14646.40424.81455.594113@moriah.shofar.org.uk&gt;
X-Mailer: VM 6.72 under 21.1 (patch 8) "Bryce Canyon" XEmacs Lucid
Precedence: bulk
Reply-To: nelug@lists.lug.org.uk
From: Eddy Younger &lt;eddy@shofar.uklinux.net&gt;
Sender: owner-nelug@lists.lug.org.uk
To: NELUG-announce@shofar.uklinux.net
Subject: [nelug] Reminder - NELUG meeting, Weds. 7th June
Date: Thu, 1 Jun 2000 18:31:20 +0100 (BST)</pre>
<h2>Recommended Reading</h2>
<ol>
<li>The Bat Book: &#8220;Sendmail&#8221; &#8211; Costales, Allman &amp; Rickert, O&#8217;Reilly 1993.</li>
<li>The red book: &#8220;Unix System Administration Handbook&#8221; &#8211; Nemeth, Snyder, Seebass &amp; Hein, Prentice-Hall 1995</li>
<li>The Crab Book; &#8220;TCP/IP Network Administration&#8221;, &#8211; Hunt, Craig, O&#8217;Reilly.</li>
<li>cf/README file from the sendmail distribution;</li>
<li>/usr/doc/fetchmail*/*, fetchmail man page.</li>
<li>RFC 821 (SMTP definition); RFC 822 (mail mesage structure); RFC 1425 (ESMPT definition); RFC 974 (DNS MX records and mail routing)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/configuring-email-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dial-up networking</title>
		<link>http://www.nelug.org.uk/dial-up-networking/</link>
		<comments>http://www.nelug.org.uk/dial-up-networking/#comments</comments>
		<pubDate>Wed, 12 Apr 2000 11:48:39 +0000</pubDate>
		<dc:creator>olly-bh</dc:creator>
				<category><![CDATA[Tutorials and resourses]]></category>

		<guid isPermaLink="false">http://www.nelug.org.uk/?p=115</guid>
		<description><![CDATA[NELUG, 12/4/2000 Eddy Younger &#60;eddy@shofar.uklinux.net&#62; Introduction Dial-up networking is a special case of TCP/IP (usually&#8230;) networking over point-to-point connections. Two machines are connected to one another via serial lines Complicated by the need initially to establish a connection thru&#8217; a &#8230; <a href="http://www.nelug.org.uk/dial-up-networking/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2 align="center">NELUG, 12/4/2000</h2>
<h2 align="center">Eddy Younger &lt;<a href="mailto:eddy@shofar.uklinux.net">eddy@shofar.uklinux.net</a>&gt;</h2>
<h2>Introduction</h2>
<ul>
<li>Dial-up networking is a special case of TCP/IP (usually&#8230;) networking over point-to-point connections.</li>
<li>Two machines are connected to one another via serial lines</li>
<li>Complicated by the need initially to establish a connection thru&#8217; a modem</li>
<li>See also PLIP (parallel-port connection)</li>
</ul>
<p><span id="more-115"></span></p>
<h2>PPP</h2>
<p>PPP &#8211; point-to-point protocol, consists of a scheme for transporting IP packets over a serial line, a protocol to control the establishment of the link and negotiation of link parameters &#8211; the Link Control Protocol (LCP), and a set of Network Control Protocols (NCP) which configure different network-layer protocols &#8211; Linux ppp supports both IP and IPX at the network level. Includes a variety of data-compression mechanisms, authentication mechanisms, address assignment etc. Earlier mechanism &#8211; SLIP (Serial-line IP) &#8211; now deprecated: no link control/negotiation scheme meant that the two ends of the link had to have parameters fixed in advance and known to the other end.</p>
<p>There are two parts to the Linux PPP implementation:</p>
<ol>
<li>The ppp driver, a kernel module (or compiled-in). Implements the ppp encapsulation and LCP protocols. Sits between the IP layer and the RS-232 data-link layer.</li>
<li>pppd &#8211; the ppp daemon. Responsible for bringing up a ppp instance on specified serial device, and handles negotiation of link parameters with the peer system. In the dial-up case, pppd invokes an external program &#8211; typically chat or dip &#8211; to initiate the connection. Once the link is up and negotiation is complete, pppd retires into the background until kicked into action by further LCP messages, or to tear down the connection.</li>
</ol>
<h2>Cast of characters</h2>
<p><a href="http://www.nelug.org.uk/wp-content/uploads/2000/04/dailup-arch.jpg"><img class="alignleft size-full wp-image-120" title="architecture" src="http://www.nelug.org.uk/wp-content/uploads/2000/04/dailup-arch.jpg" alt="Dial-up architecture" width="905" height="680" /></a><br />
<strong>ppp</strong> layer appears to the IP layer above like just another network device.</p>
<h3>chat</h3>
<p>Simple program used by pppd to talk to the modem in order to dial up, and optionally log in to the remote machine, start ppp on the remote machine, etc. Simple expect/response dialog program; a chat script consists of pairs of &#8220;expected string&#8221;/&#8221;response string&#8221; lines and a few simple commands:</p>
<pre>ABORT BUSY
ABORT "NO CARRIER"
ABORT VOICE
ABORT "NO DIALTONE"
ABORT "NO ANSWER"
"" ATZ
OK ATDT08456621598
CONNECT ""
ogin: &lt;user-name&gt;
assword: &lt;your-password&gt;
% ppp</pre>
<p>chat scripts may be used to log in to remote systems which issue &#8220;login:&#8221; and &#8220;password:&#8221; prompts, as in this example, but this is unusual for ISP&#8217;s and is less secure than CHAP authentication (see later).</p>
<h3>dip</h3>
<p>More sophisticated chat-like program, with inbuilt simple scripting language, and wider command set. Allows user interaction for example to enter user name and password at appropriate point in the dialogue. Useful for token-card users <img src='http://www.nelug.org.uk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<h3>wvdial</h3>
<p>More sophisticated still. Can function as a chat or dip replacement (subservient to pppd), or can function as the controlling process &#8211; initiating the connection and then invoking pppd. In this role it first dials up via the modem and attempts to analyse the data coming back from the modem in order to decide how to log into the remote system and establish the ppp connection as necessary. Configured by a file (/etc/wvdial.conf) consisting of a number of &#8220;sections&#8221; containing parameters such as phone number and login name for each of possible several remote connections (ISP&#8217;s).</p>
<h2>pppd options</h2>
<p>The correct pppd options are probably the most important and most troublesome aspect of dial-up networking. Options may be specified in the global options file (/etc/ppp/options unless otherwise specified by <em>file &lt;filename&gt;</em> argument to pppd), the file .ppprc in the user&#8217;s home directory. the device-specific options file (/etc/ppp/options.&lt;tty-name&gt;, eg. /etc/ppp/options.ttyS0, &#8230;./options.modem, etc), or on the pppd command-line, and are processed in that order. Different distributions provide several configuration programs to insulate the user from the business of writing options files directly, however doing it yourself is very easy, more instructive and arguably more reliable.</p>
<h3>Common options</h3>
<dl>
<dt>call &lt;isp&gt;</dt>
<dd>read options from the file /etc/ppp/peers/&lt;isp&gt;. This is the simplest way to configure pppd for a number of remote connections. The file /etc/ppp/peers/&lt;isp&gt; will contain options specific to the remote host, /etc/ppp/options will contain options common to all connections. e.g. <code>pppd call uklinux</code></dd>
<dt>device e.g. /dev/modem</dt>
<dd>specify the device to communicate over</dd>
<dt>user &lt;username&gt;</dt>
<dd>use username to authenticate the local system to the remote</dd>
<dt>demand</dt>
<dd>enable demand dialing. pppd will configure the ppp device, but will not attempt to dial in to the remote system until it detects traffic trying to use the link. Certain classes of traffic may be ignore by use of the active-filter option (see man page for more details).</dd>
<dt>idle &lt;seconds&gt;</dt>
<dd>the link will be dropped of there is no traffic across it for the specified number of seconds.</dd>
<dt>defaultroute</dt>
<dd>add a default route via the remote system to the routing table when the link is established. This is almost always required for a home system using a dial-up link as its only internet connection.</dd>
<dt>usepeerdns</dt>
<dd>ask the peer to provide up to 2 DNS server addresses when the link is established. These are passed to the ip-up script as environment variables DNS1 and DNS2; ip-up can use these to configure the local resolver to use these nameservers. Usually only essential if your ISP&#8217;s nameserver addresses are not fixed.</dd>
<dt>ipcp-accept-local</dt>
<dt>ipcp-accept-remote</dt>
<dd>allow the remote system to set the IP address of both our end and its end of the ppp link. Both are typically required as IP addresses are typically assigned dynamically by ISP&#8217;s (unless you have e.g. a Demon account with a static IP address assigned to you). (IPCP is the NCP specific to IP).</dd>
<dt>connect &lt;command&gt;</dt>
<dd>specify the command to be used to bring up the serial link. Typically this will be a chat or dip command.</dd>
<dt>no-chap, no-pap</dt>
<dd>refuse to authenticate using chap or pap, respectively.</dd>
<dt>novj, noccp</dt>
<dd>disable different compression schemes (maybe useful for debugging).</dd>
</dl>
<h3>ip-up/ip-down scripts</h3>
<p>These live in /etc/ppp also, and are run respectively when the IP connection is established and broken.</p>
<h2>Authentication</h2>
<p>ppp supports two authentication protocols, CHAP (challenge-handshake authentication protocol) and PAP (password authentication protocol). Each of the two communicating systems may be required to autenticate itself to the peer using either or only one of these protocols.</p>
<h3>CHAP</h3>
<p>CHAP is the more secure of the two authentication methods, as at no time is the password or <em>secret</em> transmitted over the link. The system demanding authentication sends a challenge string to the peer, which encrypts the challenge string using the secret as a key. The encrypted challenge is then sent back to the first system which decrypts it using its stored copy of the secret. If the decrypted version matches the original challenge then both systems used the same secret as the key and the authentication succeeds.</p>
<h3>PAP</h3>
<p>PAP is a more simple autentication scheme wherein one system authenticates itself to the other by sending an identifier/password pair, much like a user logging in to a Unix system with a user name and password. It is less secure than CHAP as the password is transmitted unencrypted and hence theoretically open to snooping if the link is compromised.</p>
<p>PAP and CHAP use secrets files in /etc/ppp to store authentication strings (/etc/ppp/pap-secrets and /etc/ppp/chap-secrets respectively). Both of these files have the same format, consisting of lines of the form <em>user-id peer-system-name</em> <em>secret</em>.</p>
<p>In general, systems will agree to authenticate using whichever scheme the peer system tries to use. The <strong>no-chap</strong> or <strong>no-pap</strong> options to pppd will cause it to refuse to use those protocols.</p>
<h2>Examples</h2>
<p><strong>/etc/ppp/options:</strong></p>
<pre># /etc/ppp/options
#
# Don't escape control chars
asyncmap 0
# Enable hardware handshaking
crtscts
# Enable connect-on-demand
demand
# Drop link after 2 mins idle
idle 120
# No default IP address
noipdefault
# Don't require remote system to authenticate itself
noauth
# Use ppp link as default route
defaultroute
# Accept local/remote IP addresses from remote system
ipcp-accept-remote
ipcp-accept-local
# verbose debugging from ppp driver
kdebug 7
# lock the serial device while link is up
lock</pre>
<p><strong>/etc/ppp/peers/uklinux:</strong></p>
<pre># device and line-speed to use
/dev/modem 115200  
# user name for authentication
user shofar 
# specify chat script to bring up connection
connect 'usr/sbin/chat -v -f /etc/ppp/chat-uklinux' 
# turn on pppd debug messages to syslogd
debug</pre>
<p><strong>/etc/ppp/chat-uklinux:</strong></p>
<pre>ABORT BUSY
ABORT "NO CARRIER"
ABORT VOICE
ABORT "NO DIALTONE"
ABORT "NO ANSWER"
"" ATZ
OK ATDT08456621598
CONNECT ""</pre>
<p><strong>/etc/ppp/chap-secrets:</strong></p>
<pre>shofar.freeserve.co.uk * &lt;my-password&gt;
shofar * &lt;another-password&gt;</pre>
<p><strong>/etc/ip-up:</strong></p>
<pre>#!/bin/sh
# Pick up my mail from the ISP servers
fetchmail  -v
# send any mail queued on the local system
/usr/bin/sendmail -q</pre>
<p><strong>N.B.</strong> Using <code>kdebug 7</code> option causes <em>every frame</em> to be logged by the ppp driver (usually to /var/log/debug); this not only generates voluminous log files but also slows down the driver &#8211; and hence the whole system. If you set this for debugging purposes, remove it as soon as things are working properly !</p>
<p>Similar chat-freeserve and /etc/ppp/peers/freeserve files exist for my freeserve account. Bringing up the link is simply a matter of</p>
<pre>pppd call uklinux  (or pppd call freeserve)</pre>
<p>The <em>demand</em> option means that dial-up only happens when something actually wants to use the link.</p>
<p>In contrast, linuxconf on a RedHat 6.1 system uses 6 or 7 files and of the order of 100&#8242;s of lines of shell to configure a ppp connection &#8211; difficult to follow and debug if anything goes wrong.</p>
<h2>Dial-up link as an internet gateway</h2>
<p>A local-area network might well wish to use a machine with a dial-up connection as an internet gateway. There are (at least) two ways to approach this depending upon the level of access required from the LAN:</p>
<ol>
<li><strong>Mail and WWW access only</strong>. Disable IP-forwarding on the gateway. Run a web proxy (squid, IJB or similar) on the gateway. All other machines on the LAN have their browsers set up to use the gateway as a proxy. Use fetchmail (run periodically as a cron job) to download mail periodically. Run pop server on the gateway, or mount /var/mail on clients via nfs. Set gateway as SMTP host for client mailers or use <em>nullclient</em> sendmail.cf files on client machines. On gateway run <code>sendmail -q</code> under cron periodically to send queued mail. In this scenario, no IP traffic is routed through the gateway machine.</li>
<li><strong>Full internet access.</strong> Set up IP-masquerading on the gateway. All clients on LAN have default route set to gateway, and gateway as DNS server. Use defaultroute and usepeerdns pppd options (or run bind) on gateway.</li>
</ol>
<h2>Debugging</h2>
<ol>
<li>Use debug and kdebug options to pppd and ppp respectively. These cause verbose logging thru&#8217; syslog and klogd, which usually will end up in /var/adm/messages (or possibly /var/log/syslog, depending upon your distribution) and /var/log/debug respectively.</li>
<li>Run tcpdump on the ppp interface (tcpdump -i ppp0) to look at IP traffic on the link (if you get the link up !).</li>
<li>Usual networking utilities (netstat, ifconfig) will work on the ppp device once the IP link is up:</li>
</ol>
<pre># ifconfig -a
dummy     Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST NOARP  MTU:1500  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 

eth0      Link encap:Ethernet  HWaddr 00:C0:F0:45:83:C9  
          inet addr:192.168.200.1  Bcast:192.168.200.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:655 errors:0 dropped:0 overruns:0 frame:0
          TX packets:646 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          Interrupt:11 Base address:0x6100 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:3924  Metric:1
          RX packets:1824 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1824 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 

ppp0      Link encap:Point-to-Point Protocol  
          inet addr:212.1.156.19  P-t-P:10.112.112.112  Mask:255.255.255.255
          POINTOPOINT NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:42 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10</pre>
<p>Sample debug output (from /var/adm/messages):</p>
<pre>Apr 11 20:47:15 moriah kernel: registered device ppp0
Apr 11 20:47:15 moriah pppd[410]: pppd 2.3.10 started by root, uid 0
Apr 11 20:47:15 moriah kernel: ppp_ioctl: set dbg flags to 10000
Apr 11 20:47:15 moriah kernel: ppp_tty_ioctl: set xmit asyncmap 0
Apr 11 20:47:15 moriah kernel: ppp_ioctl: set flags to 10000
Apr 11 20:47:15 moriah kernel: ppp_ioctl: set mru to 5dc
Apr 11 20:47:15 moriah kernel: ppp_tty_ioctl: set rcv asyncmap 0
Apr 11 20:47:15 moriah pppd[410]: Using interface ppp0
Apr 11 20:47:15 moriah pppd[410]: local  IP address 192.168.200.1
Apr 11 20:47:15 moriah pppd[410]: remote IP address 10.112.112.112
Apr 11 20:48:09 moriah pppd[410]: Starting link
Apr 11 20:48:10 moriah chat[414]: abort on (BUSY)
Apr 11 20:48:10 moriah chat[414]: abort on (NO CARRIER)
Apr 11 20:48:10 moriah chat[414]: abort on (VOICE)
Apr 11 20:48:10 moriah chat[414]: abort on (NO DIALTONE)
Apr 11 20:48:10 moriah chat[414]: abort on (NO ANSWER)
Apr 11 20:48:10 moriah chat[414]: send (ATZ^M^M)
Apr 11 20:48:10 moriah chat[414]: expect (OK)
Apr 11 20:48:10 moriah chat[414]: ATZ^M^M
Apr 11 20:48:10 moriah chat[414]: OK
Apr 11 20:48:10 moriah chat[414]:  -- got it 
Apr 11 20:48:10 moriah chat[414]: send (ATDT08456621598^M)
Apr 11 20:48:10 moriah chat[414]: expect (CONNECT)
Apr 11 20:48:10 moriah chat[414]: ^M
Apr 11 20:48:28 moriah chat[414]: ATDT08456621598^M^M
Apr 11 20:48:28 moriah chat[414]: CONNECT
Apr 11 20:48:28 moriah chat[414]:  -- got it 
Apr 11 20:48:28 moriah chat[414]: send (^M)
Apr 11 20:48:29 moriah kernel: ppp_ioctl: get unit: 0
Apr 11 20:48:29 moriah kernel: ppp_ioctl: set flags to 10000
Apr 11 20:48:29 moriah kernel: ppp_tty_ioctl: set xasyncmap
Apr 11 20:48:29 moriah kernel: ppp_tty_ioctl: set xmit asyncmap ffffffff
Apr 11 20:48:29 moriah kernel: ppp_ioctl: set flags to 10000
Apr 11 20:48:29 moriah kernel: ppp_ioctl: set mru to 5dc
Apr 11 20:48:29 moriah kernel: ppp_tty_ioctl: set rcv asyncmap ffffffff
Apr 11 20:48:29 moriah pppd[410]: Serial connection established.
Apr 11 20:48:29 moriah pppd[410]: Connect: ppp0 &lt;--&gt; /dev/modem
Apr 11 20:48:30 moriah kernel: ppp_tty_ioctl: set xmit asyncmap a0000
Apr 11 20:48:30 moriah kernel: ppp_ioctl: set flags to f010003
Apr 11 20:48:30 moriah kernel: ppp_ioctl: set mru to 5dc
Apr 11 20:48:30 moriah kernel: ppp_tty_ioctl: set rcv asyncmap 0
Apr 11 20:48:30 moriah kernel: ppp_ioctl: set flags to f010043
Apr 11 20:48:30 moriah kernel: PPP Deflate Compression module registered
Apr 11 20:48:31 moriah kernel: ppp_ioctl: set maxcid to 16
Apr 11 20:48:31 moriah kernel: ppp_ioctl: set flags to f01004f
Apr 11 20:48:31 moriah fetchmail[418]: 5.1.2 querying pop.freeserve.net (protoco
l POP3) at Tue, 11 Apr 2000 20:48:31 +0100 (BST)</pre>
<h2>Recommended Reading</h2>
<ol>
<li>ppp-HOWTO, ISP-HOWTO, Serial-HOWTO</li>
<li>/usr/doc/ppp-*/*</li>
<li>man pages: pppd, chat, dip, wvdial</li>
<li>The Crab Book &#8211; Hunt, Craig: TCP/IP Network Administration, O&#8217;Reilly.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.nelug.org.uk/dial-up-networking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
