<?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>Cypris&#039; lookout &#187; Linux</title>
	<atom:link href="http://blog.nkadesign.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nkadesign.com</link>
	<description>Renaud Bompuis on the interwebs!</description>
	<lastBuildDate>Sat, 14 Jan 2012 06:30:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Admin: Linux file server performance boost (ext4 version)</title>
		<link>http://blog.nkadesign.com/2010/admin-linux-file-server-performance-boost-ext4-version/</link>
		<comments>http://blog.nkadesign.com/2010/admin-linux-file-server-performance-boost-ext4-version/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 04:34:34 +0000</pubDate>
		<dc:creator>Renaud Bompuis</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.nkadesign.com/?p=665</guid>
		<description><![CDATA[In the previous article, I showed how to improve the performance of an existing file server by tweaking ext3 and mount settings. We can also take advantage of the availability of the now stable ext4 file system to further improve our file server performance. Some distribution, in particular RedHat/CentOS 5, do not allow us to [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/linux.png" alt="Linux" title="Linux" align="left" width="54" height="64" hspace="5" vspace="5" border="0" />In the previous article, I showed how to improve the performance of an existing file server by tweaking ext3 and mount settings.<br />
We can also take advantage of the availability of the now stable ext4 file system to further improve our file server performance.</p>

<p>Some distribution, in particular RedHat/CentOS 5, do not allow us to select ext4 as a formatting option during setup of the machine, so you will initially have to use ext3 as file system (on top of LVM preferably for easy extensibility).</p>

<h3>A small digression on partitioning</h3>

<p>Remember to create separate partitions for your file data: do not mix OS files with data files, they should live on different partitions.
In an enterprise environment, a minimal partition configuration for a file server could look like:</p>

<p>Hardware:</p>

<ul>
<li>2x 160GB HDD for the OS</li>
<li>4x 2TB HDD for the data</li>
</ul>

<p>The 160GB drives could be used as such:</p>

<ul>
<li>200MB RAID1 partition over the 2 drives for <code>/boot</code></li>
<li>2GB RAID1 partition over the 2 drives for swap</li>
<li>all remaining space as a RAID1 partition over the 2 drives for <code>/</code><br />
Note though that it is generally recommended to create additional partitions to further contain <code>/tmp</code> and <code>/var</code>.</li>
</ul>

<p>The 2TB drives could be used like this:</p>

<ul>
<li>all space as RAID6 over all drives (gives us 4TB of usable space) for <code>/data</code></li>
<li>alternatively, all space as RAID5 over all drives (gives us 6TB of usable space)
The point of using RAID6 is that it gives better redundancy than RAID5, so you can safely add more drives later without increasing the risk of failure of the whole array (which is not true of RAID5).</li>
</ul>

<h3>Moving to ext4</h3>

<p>If you are upgrading an existing system, backup first!</p>

<p>Let&#8217;s say that your <code>/data</code> partition is an LVM volume under <code>/dev/VolGroup01/LogVol00</code>.
First, make sure we have the ext4 tools installed on our machine, then unmount the partition to upgrade:</p>

<pre><code># yum -y install e4fsprogs
# umount /dev/VolGroup01/LogVol00
</code></pre>

<p>For a <strong>new system</strong>, <a href="http://www.cyberciti.biz/tips/fdisk-unable-to-create-partition-greater-2tb.html">create a large partition on the disk</a>, then format the volume (this will <strong>destroy all data</strong> on that volume!).</p>

<pre><code># mkfs -t ext4 -E stride=32 -m 0 -O extents,uninit_bg,dir_index,filetype,has_journal,sparse_super /dev/VolGroup01/LogVol00
# tune4fs -o journal_data_writeback /dev/VolGroup01/LogVol00
</code></pre>

<p><em>Note: on a RAID array, use the appropriate <code>-E stride,stripe-width</code> options, for instance, on a RAID5 array using 4 disks and 4k blocks, it could be: <code>-E stride=16,stripe-width=48</code></em></p>

<p>For an <strong>existing system</strong>, upgrading from ext3 to ext4 without damaging existing data is barely more complicated:</p>

<pre><code># fsck.ext3 -pf  /dev/VolGroup01/LogVol00
# tune2fs -O extents,uninit_bg,dir_index,filetype,has_journal,sparse_super /dev/VolGroup01/LogVol00
# fsck.ext4 -yfD /dev/VolGroup01/LogVol00
</code></pre>

<p>We can optionally give our volume a new label to easily reference it later:</p>

<pre><code># e4label /dev/VolGroup01/LogVol00 data
</code></pre>

<p>Then we need to persist the mount options in <code>/etc/fstab</code>:</p>

<pre><code>/dev/VolGroup01/LogVol00    /data    ext4    noatime,data=writeback,barrier=0,nobh,errors=remount-ro    0 0
</code></pre>

<p>And now we can remount our volume:</p>

<pre><code># mount /data
</code></pre>

<p>If you upgraded an existing filesystem from etx3, you may want to run the following to ensure the existing files are using <a href="http://en.wikipedia.org/wiki/Extent_%28file_systems%29">extents</a> for file attributes:</p>

<pre><code># find /data -xdev -type f -print0 | xargs -0 chattr +e
# find /data -xdev -type d -print0 | xargs -0 chattr +e
</code></pre>

<h3>Important notes</h3>

<p>The mounting options we use are somewhat a bit risky if your system is not adequately protected by a UPS.<br />
If your system crashes due to a power failure, you are more likely to lose data using these options than using the safer defaults.<br />
At any rate, you must have a proper backup strategy in place to safeguard data, regardless of what could damage them (hardware failure or user error).</p>

<ul>
<li>The <code>barrier=0</code> option disables <em>Write barriers</em> that enforce proper on-disk ordering of journal commits.</li>
<li>The <code>data=writeback</code> and <code>nobh</code> go hand in hand and allow the system to write data even after it has been committed to the journal.</li>
<li>The <code>noatime</code> ensures that the access time is not updated when we&#8217;re reading data as this is a big performance killer (this one is safe to use in any case).</li>
</ul>

<h3>References</h3>

<ul>
<li><a href="http://blog.smartlogicsolutions.com/2009/06/04/mount-options-to-improve-ext4-file-system-performance/">Mount options to improve ext4 file system performance</a></li>
<li><a href="https://ext4.wiki.kernel.org/index.php/Ext4_Howto">Ext4 Howto</a></li>
<li><a href="http://www.debian-administration.org/article/Migrating_a_live_system_from_ext3_to_ext4_filesystem">Migrating a live system from ext3 to ext4 filesystem</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.nkadesign.com/2010/admin-linux-file-server-performance-boost-ext4-version/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Admin: Linux file server performance boost (ext3 version)</title>
		<link>http://blog.nkadesign.com/2010/admin-linux-file-server-performance-boost/</link>
		<comments>http://blog.nkadesign.com/2010/admin-linux-file-server-performance-boost/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 10:36:47 +0000</pubDate>
		<dc:creator>Renaud Bompuis</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.nkadesign.com/?p=634</guid>
		<description><![CDATA[Using a Linux for an office file server is a no-brainer: it&#8217;s cheap, you don&#8217;t have to worry about unmanageable license costs and it just works. Default settings of most Linux distributions are however not optimal: they are meant to be as standard compliant and as general as possible so that everything works well enough [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/linux.png" alt="Linux" title="Linux" align="left" width="54" height="64" hspace="5" vspace="5" border="0" />
Using a Linux for an office file server is a no-brainer: it&#8217;s cheap, you don&#8217;t have to worry about unmanageable license costs and it just works.</p>

<p>Default settings of most Linux distributions are however not optimal: they are meant to be as standard compliant and as general as possible so that everything works well enough regardless of what you do.</p>

<p>For a file server hosting large numbers of files, these default settings can become a liability: everything slows down as the number of files creeps up and it makes your once-snappy fileserver as fas as a sleepy sloth.</p>

<p>There are a few things that we can do to ensure we get the most of our server.</p>

<h3>Checking our configuration</h3>

<p>First, a couple of commands that will help us investigate the current state of our configuration.</p>

<ul>
<li><p><code>df</code> will give us a quick overview of the filesystem:</p>

<pre><code># df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/md2      ext3    19840804   4616780  14199888  25% /
tmpfs        tmpfs      257580         0    257580   0% /dev/shm
/dev/md0      ext3      194366     17718    166613  10% /boot
/dev/md4      ext3     9920532   5409936   3998532  58% /var
/dev/md3      ext3      194366      7514    176817   5% /tmp
/dev/md5      ext3    46980272  31061676  13493592  70% /data
</code></pre></li>
<li><p><code>tune2fs</code> will help us configure the options for each ext3 partition.
If we want to check what is the current configuration of a given partition, says we want to know the current options for our <code>/data</code> mount:</p>

<pre><code># tune2fs -l /dev/md5
</code></pre>

<p>If I was using LVM as a Volume manager, I would type something like:</p>

<pre><code># tune2fs -l /dev/VolGroup00/LogVol02
</code></pre>

<p>This would give lots of information about the partition:</p>

<pre><code>tune2fs 1.40.2 (12-Jul-2007)
Filesystem volume name:   &lt;none&gt;
Last mounted on:          &lt;not available&gt;
Filesystem UUID:          d6850da8-af6f-4c76-98a5-caac2e10ba30
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal resize_inode dir_index filetype 
                          needs_recovery sparse_super large_file
Filesystem flags:         signed directory hash
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
....
</code></pre>

<p>The interesting options are listed under <code>Filesystem features</code> and <code>Default mount options</code>. For instance, here we know that the partition is using a journal and that it is using the <code>dir_index</code> capability, already a performance booster.</p></li>
<li><p><code>cat /proc/mounts</code> is useful to know the mounting options for our filesystem (just listed some interesting ones here):</p>

<pre><code>rootfs / rootfs rw 0 0
/dev/root / ext3 rw,data=ordered 0 0
/dev/md0 /boot ext3 rw,data=ordered 0 0
/dev/md4 /var ext3 rw,data=ordered 0 0
/dev/md3 /tmp ext3 rw,data=ordered 0 0
/dev/md5 /data ext3 rw,data=ordered 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
/dev/md4 /var/named/chroot/var/run/dbus ext3 rw,data=ordered 0 0
</code></pre>

<p>The <code>data=ordered</code> mount parameter tells us of the journaling configuration for the partition.</p></li>
</ul>

<h3>Journaling</h3>

<p>So what is <a href="http://en.wikipedia.org/wiki/Journaling_file_system">journaling</a>?<br />
It&#8217;s one of the great improvements of ext3: a journal is a special log on the disk that keeps track of changes about to be made. It ensures that, in case of failure, the filesystem can quickly recover without loss of information.</p>

<p>There are 3 settings for the journalling feature:</p>

<ul>
<li><code>data=journal</code> the most secure but also slowest option since all data and metadata is written to disk: the whole operation needs to be completed before any other operation can be completed. It&#8217;s sort of going to the bank for a deposit, filling the paperwork and making sure the teller puts the money in the vault before you leave.</li>
<li><code>data=ordered</code> is usually the default compromise: you fill-in the paperwork and remind the teller to put the money in the vault asap.</li>
<li><code>data=writeback</code> is the fastest but you can&#8217;t be absolutely sure that things will be done in time to prevent any loss if a problem occurs soon after you&#8217;ve asked for the data to be written.</li>
</ul>

<p>In normal circumstances all 3 end-up the same way: data is eventually written to disk and everything is fine.<br />
Now if there is a crash just as the data was written only option <code>journal</code> would guarantee that everything is safe. Option <code>ordered</code> is fairly safe too because the money should be in the vault soon after you left; most systems use this option by default.</p>

<p>If you want to boost your performance and use <code>writeback</code> you should make sure that:</p>

<ul>
<li>you have a good power-supply backup to minimise the risk of power failure</li>
<li>you have a good data backup strategy</li>
<li>you&#8217;re ok with the risk of losing the data that was written right before the crash.</li>
</ul>

<p>To change the journaling option you simply use <code>tune2fs</code> with the appropriate option:</p>

<pre><code># tune2fs -o journal_data_writeback /dev/md5
</code></pre>

<h3>Mount options</h3>

<p>Now that we&#8217;ve changed the available options for our partition, we need to tell the system to use them.<br />
Edit <code>/etc/fstab</code> and add <code>data=writeback</code> to the option columns:</p>

<pre><code>/dev/md5     /data    ext3    defaults,data=writeback   1 2
</code></pre>

<p>Next time our partition is mounted, it will use the new option. For that we can either reboot or remount the partition:</p>

<pre><code># mount - o remount /data
</code></pre>

<h3>noatime option</h3>

<p>There is another option that can have a very dramatic effect on performance, probably even more than the journaling options above.</p>

<p>By default, whenever you read a file the kernel will update its last access time, meaning that we end up with a write operation for every read!<br />
Since this is required for POSIX compliance, almost all Linux distributions leave this setting alone by default.<br />
For a file server, this can have such drastic consequence on performance.</p>

<p>To disable this time-consuming and not useful feature (for a file server), simply add the <code>noatime</code> option to the <code>fstab</code> mount options:</p>

<pre><code>/dev/md5     /data    ext3    defaults,noatime,data=writeback   1 2
</code></pre>

<p>Note that updating access times is sometimes required by some software, such as mail software (such as mutt). If you properly keep your company data in a dedicated partition, you can enable the mount options only for that partition and keep other options for the root filesystem.</p>

<h3>dealing with errors in fstab</h3>

<p>After doing the above on one of the servers, I realized that I made a typo when editing <code>/etc/fstab</code>.<br />
This resulted in the root filesystem being mounted read-only, making fstab impossible to edit&#8230;</p>

<p>To make matters worse, this machine was a few thousand miles away and could not be accessed physically&#8230;.</p>

<p>Remounting the root filesystem resulted in errors:</p>

<pre><code># mount -o remount,rw /
mount: / not mounted already, or bad option
</code></pre>

<p>After much trial and rebooting, this worked (you need to specify all mounting options, to avoid the wrong defaults from being read from etc/mtab`):</p>

<pre><code># mount  -o rw,remount,defaults /dev/md2 /
</code></pre>

<p>After that, I could edit <code>/etc/fstab</code> and correct the typo&#8230;</p>

<h3>Conclusions</h3>

<p>How much these options will improve performance really depends on how your data is used: the improvements should be perceptible if your directories are filled with large amounts of small files.<br />
Deletion should also be faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nkadesign.com/2010/admin-linux-file-server-performance-boost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sysadmin: Multiple ISP firewall &#8211; The setup</title>
		<link>http://blog.nkadesign.com/2009/sysadmin-multiple-isp-firewall-servers-and-redundancy/</link>
		<comments>http://blog.nkadesign.com/2009/sysadmin-multiple-isp-firewall-servers-and-redundancy/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 07:22:24 +0000</pubDate>
		<dc:creator>Renaud Bompuis</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://blog.nkadesign.com/?p=336</guid>
		<description><![CDATA[After suffering broadband trouble for the past 9 months, including interruptions that lasted a few days, I decided to get an additional line installed by a different ISP. I could have bought one of these multi-WAN devices but decided against it for a couple of reasons: I like a challenge and I wanted to achieve [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/linux.png" alt="Linux" title="Linux" align="left" width="54" height="64" hspace="5" vspace="5" border="0" />
After suffering broadband trouble for the past 9 months, including interruptions that lasted a few days, I decided to get an additional line installed by a different ISP.<br />
I could have bought one of these multi-WAN devices but decided against it for a couple of reasons: I like a challenge and I wanted to achieve a particular setup that I wasn&#8217;t sure could be answered by off-the-shelf products (for a reasonable price that is).</p>

<p>This long article is fairly detailed but if your setup is similar it should be enough to get you going quickly.</p>

<ul>
<li><a href="#basicsetup">The basic setup</a></li>
<li><a href="#objectives">Objectives</a></li>
<li><a href="#technologies">Technologies</a></li>
<li><a href="#thingstoknow">Things to know</a></li>
<li><a href="#thingstoread">Things to read</a></li>
<li><a href="#installingshorewall">Installing shorewall</a></li>
<li><a href="#preparingthesystem">Preparing the system</a></li>
<li><a href="#shorewallconfiguration">Shorewall configuration</a></li>
<li><a href="#installingourfirewallrules">Installing our firewall rules</a></li>
<li><a href="#dns">DNS</a></li>
<li><a href="#initialconclusions">Initial conclusions</a></li>
<li><a href="#references">References</a></li>
</ul>

<h3 id="basicsetup">The basic setup</h3>

<p>Without further ado, this is the network configuration:</p>

<p><img src="/wp-content/uploads/2009/02/20090203NetworkDiagram.png" alt="Network Diagram" /></p>

<h4>Notable things</h4>

<p>We have 2 broadband connections:</p>

<ul>
<li><strong>CYBR</strong>, a standard DSL line with a fixed IP <code>111.99.88.77</code> allocated through PPPoE.</li>
<li><strong>HKBN</strong>, a standard 100Mbps line with a fixed IP <code>30.40.50.62</code>.</li>
</ul>

<p>The network is split into different <em>zones</em>:</p>

<ul>
<li>the <strong>Internet zone</strong>, connected to our Firewall through interfaces <code>eth0</code> (<code>ppp0</code>) and <code>eth1</code>.</li>
<li>a <strong>Firewall zone</strong>, delimited by the firewall system itself</li>
<li>a <strong><a href="http://en.wikipedia.org/wiki/DMZ_(computing)">DMZ</a> zone</strong> connected through interface <code>eth2</code> for the servers we want to make visible from the Internet.<br />
The DMZ has its own private subnet delimited by <code>192.168.254.0/255.255.255.0</code>.</li>
<li>a <strong>LAN zone</strong> connected through interface <code>eth3</code> so local computers can access the Internet and be protected from it.<br />
The DMZ has its own private subnet delimited by <code>192.168.0.0/255.255.255.0</code>.  </li>
</ul>

<h3 id="objectives">Objectives</h3>

<p>What we want from our setup:</p>

<ol>
<li>our <em>firewall</em> protects our DMZ and LAN from unwanted access.</li>
<li>our <em>win</em> server can host websites or other services.</li>
<li>our <em>linux</em> server can handle receiving and sending email or other services.</li>
<li>our <em>firewall</em> can handle incoming traffic from either ISP.</li>
<li>our <em>firewall</em> can load-balance local outgoing traffic across both ISP.</li>
<li>If one line fails, <em>incoming</em> traffic switches to the other line.</li>
<li>If one line fails, <em>outgoing</em> traffic switches to the other line.</li>
<li>Eventually, we want both the <em>linux</em> and <em>win</em> servers to be able to host different websites and we want the firewall to send incoming requests to the right server.</li>
</ol>

<p>In this first article, I&#8217;ll present the setup for items 1-5.<br />
The remaining topics will be the subject of subsequent articles of their own.</p>

<h3 id="technologies">Technologies</h3>

<p>The firewall is our primary subject. What is being discussed here is pretty much distribution-independent and should work on all flavours of Linux.</p>

<h4>OS on the firewall system</h4>

<p>I chose <a href="http://www.centos.org/">CentOS</a> on the firewall.<br />
Being an almost byte-for-byte identical copy of <a href="http://www.redhat.com/rhel/">RedHat Enterprise Linux</a>, all configuration will be identical on RedHat and its derivatives such as Fedora.</p>

<h4>Firewall software, first try</h4>

<p>When my firewall needs are simpler, I use the <a href="http://tldp.org/HOWTO/IP-Masquerade-HOWTO/stronger-firewall-examples.html">Stronger IP Firewall Ruleset</a> from the <a href="http://tldp.org/HOWTO/IP-Masquerade-HOWTO/index.html">Linux IP Masquerade HOWTO</a>.<br />
I started to modify the script to adapt it to my new Multi-ISP setup but things got complicated once I needed to debug routing tables.<br />
I got it 80% of the way but tracing network connections and packet routing is complicated and time-consuming.<br />
After a couple of days of peering into log files and <a href="http://www.wireshark.org/">wireshark</a> capture screens, I gave up manual configuration and decided to go with something else.</p>

<h4>Firewall software, final</h4>

<p>The product I chose in the end is <a href="http://shorewall.net/">shorewall</a>: it&#8217;s a very flexible firewall system that create the necessary iptable rules and configure most of the routing needs to properly handle complex network setup.<br />
Shorewall is Open Source, very stable, has been out for a long time, is actively maintained and has lots of excellent documentation and examples.</p>

<h3 id="thingstoknow">Things to know</h3>

<p>Before we get into the meat of the article, you should brush up on the following topics:</p>

<ul>
<li>You have some knowledge of Linux system administration, know how to configure network connections, know how to enable/disable/stop/start  services, able to edit config files.</li>
<li>Networking: you should know what a netmask is, what a gateway is, what a subnet is and have a passing understanding of IP classes, IP notation, what ports are for, what&#8217;s the difference between the tcp, udp, icmp protocols, what Dynamic Port Forwarding (DNAT) is, what Network Address Translation (NAT) is, what <em>masquerading</em> means.</li>
<li>Some basic understanding of DNS and local host name resolving (using <code>host.conf</code> and <code>resolv.conf</code>)</li>
<li>Some basic knowledge of what <em>routing</em> is for and how it works.</li>
<li>Some knowledge of how the linux kernel handles network packets (NetFilter, basics of iptables).</li>
</ul>

<p>You don&#8217;t need to be a specialist in any of these areas but any knowledge helps.<br />
I&#8217;m far from being well versed into Netfilter and routing, it&#8217;s not often that I have to deal directly with these topics, but brushing up on these topics helped.</p>

<h4 id="thingstoread">Things to read</h4>

<p>Shorewall has very extensive documentation. So much so that it can be a bit daunting, not knowing where to start.<br />
I found the following documents helpful to get me started:</p>

<ul>
<li><a href="http://shorewall.net/shorewall_setup_guide.htm">Setup Guide for multiple interfaces</a>.</li>
<li><a href="http://shorewall.net/Shorewall_and_Routing.html">Routing article</a></li>
<li><a href="http://shorewall.net/MultiISP.html">Guide for handling Multi-ISP</a></li>
</ul>

<h3 id="installingshorewall">Installing shorewall</h3>

<p>Go to the download site list [http://shorewall.net/download.htm#Sites]  and download the most appropriate binary package for your distribution.</p>

<p>If you get RPMs for RedHat systems, you only need to install (<code>rpm -ivh</code>) the following packages:</p>

<pre><code>shorewall-4.X.X-X.noarch.rpm
shorewall-perl-4.X.X-X.noarch.rpm 
</code></pre>

<p>If you install from source, only download, compile and install the <em>common</em>, <em>doc</em> and <em>perl</em> packages.</p>

<h3 id="preparingthesystem">Preparing the system</h3>

<p>For shorewall to properly handle both our firewall and packet routing needs, we need to make sure that the other parts of the system are not interfering with it.</p>

<h4>Internet lines</h4>

<p>Make sure that your multiple internet lines are properly working on their own!</p>

<h4>Disable routing</h4>

<ul>
<li>Make sure that you don&#8217;t define a <code>GATEWAY</code> in the configuration of your network interfaces (in <code>/etc/sysconfig/network-scripts/ifcfg-XXX</code>) .</li>
<li>If you use an (A)DSL connection, also set <code>DEFROUTE=no</code> if its <code>ifcfg-XXX</code> file as well.</li>
<li>Remove the <code>GATEWAY</code> from the <code>/etc/sysconfig/network</code> file if there is one.</li>
<li>Edit your <code>/etc/sysctl.conf</code> file and set <code>net.ipv4.conf.default.rp_filter = 0</code>.</li>
</ul>

<h4>Disable firewall</h4>

<p>Disable the current firewall, for instance using the <code>system-config-securitylevel</code> helper tool.<br />
Be careful if you&#8217;re directly connected to the Internet, you will be left without protection!<br />
You can actually wait until shorewall is properly configured to disable the firewall.</p>

<h3 id="shorewallconfiguration">Shorewall configuration</h3>

<p>Shorewall uses a set of simple configuration files, all located under <code>/etc/shorewall/</code>.
For exact detail of each configuration files, have a look at the list of <a href="http://shorewall.net/Manpages.html">man pages</a>.</p>

<h4>Zones</h4>

<p><code>zones</code> are probably the simplest configuration file.<br />
Details in the <a href="http://shorewall.net/manpages/shorewall-zones.html">zones man page</a>.
Here we just name the various zones we want our firewall to handle:</p>

<pre><code>################################################################
#ZONE   TYPE          OPTIONS       IN                  OUT
#                                   OPTIONS             OPTIONS
fw      firewall
net     ipv4
loc     ipv4
dmz     ipv4
</code></pre>

<p>This just reflects our setup as highlighted in the diagram above.</p>

<p>Note that the <code>fw</code> zone is often referred to as the  <code>$FW</code> variable instead in various configuration files.</p>

<h4>Interfaces</h4>

<p>Here we list all the network interfaces connected to our firewall and for which zone they apply.<br />
Details in the <a href="http://shorewall.net/manpages/shorewall-interfaces.html">interfaces man page</a>.</p>

<pre><code>################################################################
#ZONE   INTERFACE       BROADCAST       OPTIONS
net     ppp0            detect
net     eth1            detect
dmz     eth2            detect
loc     eth3            detect
</code></pre>

<p>Note that for our <code>net</code> zone, we list the 2 interfaces connected to our ISPs.<br />
If you&#8217;re using PPPoE to connect, don;t use the interface name <code>eth0</code> but use <code>ppp0</code> instead.</p>

<h4>Policy</h4>

<p>The <code>policy</code> file tells shorewall which default actions should be taken when traffic is moving from one zone to another.<br />
These default actions are taken if no other special action was specified in other configuration files.<br />
View the <code>policy</code> file as a list of default actions for the firewall.<br />
Details about this configuration file as in its <a href="http://shorewall.net/manpages/shorewall-policy.html">man page</a>.</p>

<pre><code>################################################################
#SOURCE DEST    POLICY          LOG     LIMIT:      CONNLIMIT:
#                               LEVEL   BURST       MASK
net     net     DROP            info
loc     net     ACCEPT
dmz     net     ACCEPT
loc     dmz     ACCEPT
loc     $FW     ACCEPT
dmz     $FW     ACCEPT
$FW     net     ACCEPT
dmz     loc     DROP            info
net     all     DROP            info
all     all     DROP            info
</code></pre>

<p>Traffic from one zone to another needs to be explicitely <code>ACCEPTed</code>, <code>REJECTed</code> or <code>DROPped</code>.<br />
For instance, <code>loc net ACCEPT</code> means that we allow all traffic from our local LAN to the Internet, while <code>net all DROP</code> means we don&#8217;t allow incoming traffic from the internet to anyone (remember this is the default action, in most cases we will override this for specific types of traffic in the <code>rules</code> file).<br />
When we set the default action to <code>DROP</code>, we can tell shorewall to keep a trace of the details in the <code>/var/log/messages</code> log.</p>

<h4>Providers</h4>

<p>The providers file is generally only used in a multi-ISP environment.<br />
Here we define how we want to <em>mark</em> packets originating from one ISP with a unique ID so we can tell the kernel to route these packets to the right interface.<br />
Not doing this would get packets received from one interface to be routed to the default gateway instead.<br />
The details of this configuration file are explained in the <a href="http://shorewall.net/manpages/shorewall-providers.html">providers man page</a> for it.</p>

<pre><code>#############################################################################
#NAME NUMBER MARK DUPLICATE INTERFACE GATEWAY      OPTIONS          COPY
CYBR  1      0x1  main      ppp0      -            track,balance=1  eth2,eth3
HKBN  2      0x2  main      eth1      30.40.50.61  track,balance=5  eth2,eth3
</code></pre>

<p>Note that the <code>DUPLICATE</code> columns tells shorewall that it should make a copy of the main default routing table for this particular routing table (called <code>CYBR</code> or <code>HKBN</code> depending on which ISP we refer to).<br />
Packets are marked with number 0&#215;1 or 0&#215;2 so we can distinguish them during their travel through the system.<br />
For PPPoE connections, don&#8217;t specify a <code>GATEWAY</code> since it&#8217;s most likely that your ISP didn&#8217;t give you one.</p>

<p>The most interesting part of this file are the <code>OPTIONS</code>: <code>track</code> means that we want the packets to be tracked as they travel through the system; <code>balance</code> tells the kernel that we want traffic coming out to be spread over both interfaces.<br />
Additionally, we want HKBN to receive more or less 5 times more traffic than CYBR (note that this has no effect on reply packets).</p>

<p>The <code>COPY</code> columns will ensure that the routing tables created for CYBR and HKBN are copied for each internal interface, so our <code>eth2</code> and <code>eth3</code> interfaces know how to route packets to the right ISP.</p>

<h4>Route Rules</h4>

<p>For our purpsose, the <code>route_rules</code> file only describes how traffic should be routed through one or the other ISP we set up in <code>/etc/shorewall/providers</code>.<br />
Details are in the <a href="http://shorewall.net/manpages/shorewall-route_rules.html">route_rules file man page</a>.</p>

<pre><code>#####################################################################
#SOURCE             DEST               PROVIDER        PRIORITY
ppp0                -                  CYBR            1000
eth1                -                  HKBN            1000
</code></pre>

<p>Here we simply say that all traffic through the <code>CYBR</code> table should be sent to <code>ppp0</code>.<br />
The <code>PRIORITY</code> is an ordering number that tell shorewall to consider this routing rule before it marks the packets. Since we know the packets originated from <code>ppp0</code> or <code>eth1</code> we don&#8217;t really need to mark them.</p>

<h4>Masq</h4>

<p>The <code>masq</code> file will contain the masquerading rules for our private interfaces: in essence, we want traffic from the local LAN and DMZ to be hidden behind our limited number of external IPs.<br />
See the <a href="http://shorewall.net/manpages/shorewall-masq.html">masq manpage</a> for all the details.</p>

<pre><code>#####################################################################
#INTERFACE              SOURCE           ADDRESS                 
# Ensure that traffic originating on the firewall and redirected via 
# packet marks always has the source IP address corresponding to the 
# interface that it is routed out of.
# See http://shorewall.net/MultiISP.html#Example1
ppp0                    30.40.50.62      111.99.88.77
eth1                    111.99.88.77     30.40.50.62
ppp0                    eth2             111.99.88.77
eth1                    eth2             30.40.50.62
ppp0                    eth3             111.99.88.77
eth1                    eth3             30.40.50.62
</code></pre>

<p>The first part ensures that the traffic coming out of our public interfaces but originating from the other is actually rewritten as originating from the right IP for the interface.<br />
This ensures that packets leaving <code>eth1</code> for instance don&#8217;t come out with the wrong source address of the <em>other</em> interface.<br />
The second part of the ensures that packets from our LAN or DMZ leaving either public interfaces are doing so with the right IP address, so traffic from my desktop going through <code>ppp0</code> for instance, will have its source address as <code>100.90.80.70</code>.</p>

<h4>Rules</h4>

<p>This is the main file where we tell shorewall our basic configuration and how we want packets to be handled in the general case.<br />
The <code>/etc/shorewall/rules</code> file contains the specific instructions on where to direct traffic that will override the default actions defined in the <code>/etc/shorewall/policy</code> file.</p>

<pre><code>#####################################################################
#ACTION    SOURCE                DEST                   PROTO  
#                                                                     
SECTION NEW
# Drop and log packets that come from the outside but pretend 
# to have a local address
DROP:info  net:192.168.0.0/24    all
DROP:info  net:192.168.254.0/24  all

# Redirect incoming traffic to the correct server for WWW and email
DNAT       all                   dmz:192.168.254.20     tcp   www
DNAT       all                   dmz:192.168.254.10     tcp   110
DNAT       all                   dmz:192.168.254.10     tcp   143
DNAT       all                   dmz:192.168.254.10     tcp   25
</code></pre>

<p>In its most basic form, what we&#8217;ve just defined here is that we want all traffic from anywhere destined for port 80 (www) to be sent to our <em>win</em> server.<br />
All mail traffic, POP3 (port 110), IMAP (port 143) and SMTP (port 25) is to be redirected to our <em>linux</em> server in the DMZ.</p>

<p>There are a few more useful rules that we can include, for instance, I want to be able to access my servers  through either ISPs from home (IP <code>123.45.67.89</code>) and disallow everyone else from accessing it.</p>

<pre><code>#####################################################################
#ACTION    SOURCE                DEST                   PROTO  
#                                                                     
# Allow SSH to the firewall from the outside only from home

ACCEPT     net:123.45.67.89      $FW                    tcp   ssh
# Redirect input traffic to the correct server for RDP, VNC and SSH 
DNAT       net:123.45.67.89      dmz:192.168.254.10:22  tcp   2222
DNAT       net:123.45.67.89      dmz:192.168.254.10     tcp   5901
DNAT       net:123.45.67.89      dmz:192.168.254.20     tcp   3389
</code></pre>

<p>When I SSH to <code>30.40.50.62</code> or <code>100.90.80.70</code>, on the normal port 22, I will access the firewall.<br />
Now if I SSH to the non-standard port 2222, I will instead access the <em>linux</em> server.<br />
Ports 5901 are for remoting through VNC on the <em>linux</em> machine, and port 3389 will be used for Remote Desktop connections to the <em>win</em> server.</p>

<p>To make sure my machines are up and running, I like to be able to ping them:</p>

<pre><code>#####################################################################
#ACTION    SOURCE              DEST              PROTO  
#                                                                     
# Accept pings between zones
ACCEPT     dmz                 loc               icmp  echo-request
ACCEPT     loc                 dmz               icmp  echo-request
</code></pre>

<p>Note that ping will only work between the LAN and the DMZ and pinging my firewall from the Internet will result in the requests being silently dropped.<br />
I usually prefer that configuration as it makes discovering the servers by random bots slightly less likely.</p>

<p>There are lots of other cool things we can do with forwarding but that will do for now.</p>

<h4>shorewall.conf</h4>

<p>The last file we&#8217;re going to look at is the main configuration file for shorewall.<br />
See details about each option from the <a href="http://shorewall.net/manpages/shorewall.conf.html">man page for <code>shorewall.conf</code></a>.</p>

<p>Most options are OK by default. The only ones that I have had to change are:</p>

<pre><code>STARTUP_ENABLED=Yes
MARK_IN_FORWARD_CHAIN=Yes
FASTACCEPT=Yes
OPTIMIZE=1
</code></pre>

<p>The first option tells shorewall that we want it to start automatically when the system boots.<br />
That&#8217;s not enough though, so make sure that the service will be started:</p>

<pre><code># chkconfig shorewall --levels 235 on
</code></pre>

<h3 id="installingourfirewallrules">Installing our firewall rules</h3>

<p>Shorewall configuration files need to be compiled without error before the firewall is actually loaded by shorewall.<br />
The command:</p>

<pre><code># shorewall restart
</code></pre>

<p>will stop and recompile the current configuration.<br />
If there are any errors, the current firewall rules will be unchanged.<br />
There are lots of other commands that can be issued. Check the man page for a complete list.</p>

<p>If you use PPPoE, you will want the firewall to be restarted every time the line reconnects.<br />
The simplest way is to create a file <code>/etc/ppp/if-up.local</code> with only a single line:</p>

<pre><code>shorewall restart
</code></pre>

<h3 id="dns">DNS</h3>

<p>There is one remaining issue with our firewall: if a user on the LAN attempts to access the web server by its name the request will probably fail.<br />
Same for accessing our mail server: we can configure our desktop to connect to <code>192.168.254.10</code> to get and send emails, but on the laptop we would usually use something like <code>pop.acme.com</code> instead so we can read our emails from outside the office.</p>

<p>Similarly, trying to access <code>www.acme.com</code> hosted on the <em>win</em> server from the <em>linux</em> server will fail.</p>

<p>One solution is to route traffic through the firewall but that&#8217;s actually fairly complicated to setup properly.<br />
The shorewall FAQ 2 discourages this and instead recommends the use of <a href="http://en.wikipedia.org/wiki/Split-horizon_DNS">split-DNS</a>: it&#8217;s very easy to setup and it works like a charm.</p>

<h4>dnsmasq</h4>

<p>Just install  <a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a> on the firewall. There are ready-made packages available for it and a simple <code>yum install dsnmasq</code> should suffice.</p>

<p>Dnsmasq provides a simple DNS forwarding and DHCP service. I had already configured <code>dhcpd</code> -which is already fairly simple to configure- on my firewall so I won&#8217;t need DHCP from dnsmasq but you can easily set it up if you want.</p>

<p>On the DNS side, dnsmasq can be told to first try to resolve hostnames by looking at the standard <code>/etc/hosts</code> file and then query the DNS servers defined in <code>/etc/resolv.conf</code> if necessary.</p>

<p>This simple trick means that we can:</p>

<ul>
<li>Keep our normal DNS service pointing to say <code>100.90.80.70</code> for <code>www.acme.com</code> so that people on the Internet will properly resolve their web requests to our <em>win</em> server.</li>
<li>Add an entry in the firewall&#8217;s <code>hosts</code> file to point local clients to <code>192.168.254.20</code> instead.</li>
</ul>

<p>To achieve this, simply edit  <code>/etc/hosts</code>and add entries matching all your services:</p>

<pre><code># Acme's services. 
# One line for each DNS entries accessible from the Internet
192.168.254.20        acme.com
192.168.254.20        www.acme.com
192.168.254.10        pop.acme.com
192.168.254.10        mail.acme.com
</code></pre>

<h4>dsnmasq configuration</h4>

<p>Edit the <code>/etc/dsnmasq.conf</code> and uncomment or add the following lines:</p>

<pre><code># Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
# listen on DMZ and LAN interfaces
interface=eth2
interface=eth3
# don't want dnsmasq to provide dhcp
no-dhcp-interface=eth2
no-dhcp-interface=eth3
</code></pre>

<p>Then make sure that dsnmasq will start on boot:</p>

<pre><code># chkconfig dnsmasq --levels 235 on
# service dnsmasq restart
</code></pre>

<h4 id="dnsresolution">DNS resolution</h4>

<p>There may be one last issue with DNS: in your <code>/etc/resolv.conf</code> you will have listed the DNS servers of one or both of your ISPs.<br />
The problem is that some ISPs don&#8217;t allow access to their name servers from a network different than theirs.</p>

<p>The result is that each time any of the systems issues a DNS request it may fail and need to be sent to the next server instead, which may also fail and introduce delays in accessing named resources on the Internet.</p>

<p>One easy way out is to not use the ISPs DNS servers but instead only list the free <a href="http://opendns.org/">OpenDNS</a> name servers in your <code>resolv.conf</code>:</p>

<pre><code>search acme.com
nameserver 208.67.222.222
nameserver 208.67.220.220
</code></pre>

<p>Then make sure that you disable DNS in your <code>/etc/sysconfig/network-config/ifcfg-XXX</code> configuration file for your PPPoE connection:</p>

<pre><code>PEERDNS=no
</code></pre>

<p>Failure to do so will result in your <code>/etc/resolv.conf</code> file being rewritten with the DNS servers of one of your ISP every time you reconnect to them.</p>

<h4>DHCP configuration</h4>

<p>If you use <code>dhcpd</code> for local users, then you will need to make sure that its DNS server is set to the firewall&#8217;s:</p>

<pre><code># DHCP Server Configuration file.
ddns-update-style none;
ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {
    option routers                  192.168.0.1;
    option subnet-mask              255.255.255.0;
    option domain-name              "acme.com";
    option domain-name-servers      192.168.0.1;
    range 192.168.0.200 192.168.0.250;
    default-lease-time 86400;
    max-lease-time 132000;
}
</code></pre>

<p>On your local machines that use DHCP, make sure to renew your IP.<br />
All other machines should be configured to use <code>192.168.0.1</code> as their unique DNS server and the machines in the DMZ should have their DNS set to <code>192.168.254.1</code>.</p>

<p>Unless you reboot, don&#8217;t forget and flush the local DNS cache of each machine:<br />
On Windows, from the command line:</p>

<pre><code>C:\&gt; ipconfig /flushdns
</code></pre>

<p>On Mac, from the terminal:</p>

<pre><code>bash-x.xxx$ dnscacheutil -flushcache
</code></pre>

<h3 id="initialconclusions">Initial conclusions</h3>

<p>I believe this type of firewall setup is fairly common and I hope that the -rather long- article helped you get your own setup in place.<br />
In the -much shorter- follow-up articles, we&#8217;ll make our system as redundant as possible so our web and email services stay online even when one of the broadband connections fails.</p>

<p>In the meantime, don&#8217;t hesitate to leave your comments and corrections below.</p>

<h3 id="history">History</h3>

<ul>
<li>06FEB2009: added info about restarting the firewall on <a href="#installingourfirewallrules">PPPoE reconnection</a> and disabling <a href="#dnsresolution">ISP&#8217;s DNS resolution</a>.</li>
<li>04FEB2009: initial release.</li>
</ul>

<h3 id="references">References</h3>

<ul>
<li><a href="http://shorewall.net/">Shorewall</a>&#8216;s main site.</li>
<li>Shorewall&#8217;s [man page][manpage] list for all configuration files.</li>
<li><a href="http://opendns.org/">OpenDNS</a> free worldwide DNS service (and more).</li>
<li><a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">dnsmasq</a> DNS forwarder (for easily setting up <a href="http://en.wikipedia.org/wiki/Split-horizon_DNS">split-horizon-DNS</a>).</li>
<li><a href="http://www.centos.org/">CentOS</a> linux distribution, based on <a href="http://www.redhat.com/rhel/">RedHat Enterprise Linux</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.nkadesign.com/2009/sysadmin-multiple-isp-firewall-servers-and-redundancy/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Linux: AutoCAD DWG to SVG preview conversion.</title>
		<link>http://blog.nkadesign.com/2008/linux-autocad-dwg-to-svg-preview-conversion/</link>
		<comments>http://blog.nkadesign.com/2008/linux-autocad-dwg-to-svg-preview-conversion/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 09:16:15 +0000</pubDate>
		<dc:creator>Renaud Bompuis</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.nkadesign.com/?p=95</guid>
		<description><![CDATA[Years ago I did a small utility to convert DWG or DXF files into a vector-graphic, zoomable, SVG preview. The Linux command-line utility was used in a larger drawing management application that I had built before I left that company for greener pastures. The Linux server-based application would scan the vast (100,000s of CAD drawings) [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/linux.png" alt="Linux" title="Linux" align="left" width="54" height="64" hspace="5" vspace="5" border="0" />
Years ago I did a <a href="http://etc.nkadesign.com/Download/Cad2svg">small utility</a> to convert <a href="http://en.wikipedia.org/wiki/.dwg">DWG</a> or <a href="http://en.wikipedia.org/wiki/AutoCAD_DXF">DXF</a> files into a vector-graphic, zoomable, <a href="http://en.wikipedia.org/wiki/Svg">SVG</a> preview.
The Linux command-line utility was used in a larger drawing management application that I had built before I left that company for greener pastures.</p>

<p>The Linux server-based application would scan the vast (100,000s of <a href="http://en.wikipedia.org/wiki/Computer-aided_design">CAD drawings</a>) and, depending on their format, attempt to create thumbnails and extract textual information from them and populate a database so we could easily find related drawings through a simple web-interface.</p>

<p><img src='/wp-content/uploads/2008/07/sshot-390.png' alt='CAD File'  style="float:right;margin-left:10px;margin-bottom:5px"/> The software would present thumbnails of the drawings; when the drawing was in DWG or DXF format, the thumbnail would be an SVG vector representation of the original drawing instead of an image. That made the preview much more useful as you could zoom in and still retain enough detail to ascertain if the drawings was actually what you were looking for.</p>

<p>Other file formats (<a href="http://en.wikipedia.org/wiki/Tagged_Image_File_Format">TIFF</a>, <a href="http://en.wikipedia.org/wiki/HPGL">HPGL</a> plots, etc) were transformed into <a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</a> image previews that were saved into 2 size: a small thumbnail, good enough to be displayed in a list, and a larger one that would show more details.</p>

<p>The server software was written in <a href="http://www.perl.org/">Perl</a>, with some of the converters in <a href="http://en.wikipedia.org/wiki/C_(programming_language)">C</a>. Every night, the server would go through the whole tree of drawings on the filesystem, looking for drawings it hadn&#8217;t seen before and it would pass them to the appropriate plug-in for extracting text -where possible- and create thumbnails.</p>

<p>Memories of fun projects&#8230;</p>

<h3>Download links:</h3>

<ul>
<li>cad2svg: <a href="http://etc.nkadesign.com/Download/Cad2svg">http://etc.nkadesign.com/Download/Cad2svg</a></li>
<li>cad2text: <a href="http://etc.nkadesign.com/Download/Cad2text">http://etc.nkadesign.com/Download/Cad2text</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.nkadesign.com/2008/linux-autocad-dwg-to-svg-preview-conversion/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Linux sysadmin: a short RAID trouble-shooting story</title>
		<link>http://blog.nkadesign.com/2008/linux-sysadmin-a-short-troubleshooting-story/</link>
		<comments>http://blog.nkadesign.com/2008/linux-sysadmin-a-short-troubleshooting-story/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 11:15:29 +0000</pubDate>
		<dc:creator>Renaud Bompuis</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.nkadesign.com/?p=86</guid>
		<description><![CDATA[I recently had an issue at a remote location (12000km away) where the old multi-purpose Linux server that had been working for the past 5 years wouldn&#8217;t boot again after a nasty power failure. The server was used as a firewall, a local email store, a file server and a backup server, so its failure [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/linux.png" alt="Linux" title="Linux" align="left" width="54" height="64" hspace="5" vspace="5" border="0" />
I recently had an issue at a remote location (12000km away) where the old multi-purpose Linux server that had been working for the past 5 years wouldn&#8217;t boot again after a nasty power failure.<br />
The server was used as a firewall, a local email store, a file server and a backup server, so its failure is a big deal for the small business that was using it.<br />
<center><img src="http://blog.nkadesign.com/wp-content/uploads/2008/06/266169495_863b3d935f.jpg" alt="RAID explained" /><br />
<small>RAID configurations explained</small></center>
You can&#8217;t always have complete redundancy, so some amount of bad crash is to be expected over the years. Fortunately, I always construct my servers around a simple software RAID1 array and that leaves some hope for recovery.<br />
In this instance, the server would start and then miserably fail in a fashion that would suggest a hardware failure of some sort. Not being able to be physically present and having no dedicated system admin on location, I directed the most knowledgeable person there to use a spare internet router to recover Internet connectivity and connect one of the disk to another Linux server (their fax server) through a USB external drive.</p>

<p>Doing this, I was able to remotely connect to the working server and access the disk, mount it and access the data.</p>

<h3>Salvaging the data</h3>

<p>Once one of the RAID1 drives was placed into the USB enclosure and connected to the other available Linux box it was easy to just remount the drives:</p>

<p><code>fdisk</code> will tell us which partitions are interesting, assuming that <code>/dev/sdc</code> is our usb harddrive:</p>

<pre><code>[root@fax ~]# fdisk -l /dev/sdc

Disk /dev/sdc: 81.9 GB, 81964302336 bytes
16 heads, 63 sectors/track, 158816 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes  

Device      Boot    Start         End      Blocks   Id  System
/dev/sdc1   *           1         207      104296+  fd  Linux raid autodetect
/dev/sdc2             208       20526    10240776   fd  Linux raid autodetect
/dev/sdc3           20527       22615     1052856   fd  Linux raid autodetect
/dev/sdc4           22616      158816    68645304    f  W95 Ext'd (LBA)
/dev/sdc5           22616      158816    68645272+  fd  Linux raid autodetect
</code></pre>

<p>We can&#8217;t simply <code>mount</code> the partitions, they need to be assembled into a RAID partition first:</p>

<pre><code>[root@fax ~]# mdadm --assemble /dev/md6 /dev/sdc1 --run
mdadm: /dev/md6 has been started with 1 drive (out of 2).
</code></pre>

<p>The <code>--run</code> argument forces the RAID partition to be assembled, otherwise, <code>mdadm</code> will complain that there is only a single drive available instead of the 2 -or more- it would expect.</p>

<p>Now simply mount the assembled partition to make it accessible in <code>/mnt</code> for instance:</p>

<pre><code>[root@fax ~]# mount /dev/md6 /mnt
</code></pre>

<p>We can now salvage our data by repeating this process for every partition.<br />
Using RAID1 means you have at least 2 disks to choose from, so if one is damaged beyond repair, you may be lucky and the mirror one on the other drive should work.</p>

<p>If the drives are not physically damaged but they won&#8217;t boot, you can always use a pair (or more) of USB HDD enclosures and reconstruct the RAID arrays manually from another Linux box.</p>

<h3>Planning for disasters</h3>

<p>The lesson here is about planning: you can&#8217;t foresee every possible event and have contingencies for each one of them, either because of complexity or cost,  but you can easily make your life much easier by planning ahead a little bit.</p>

<p>Most small businesses cannot afford dedicated IT staff, so they will usually end-up having the least IT-phobic person become their &#8216;system administrator&#8217;.<br />
It&#8217;s your job as a consultant/technical support to ensure that they have the minimum tools at hand to perform emergency recovery, especially if you cannot intervene yourself quickly.</p>

<h3>On-Site emergency tools</h3>

<p>In every small business spare parts closet there should be at least:</p>

<ul>
<li>Whenever possible, a <strong>spare Linux box</strong>, even if it&#8217;s just using older salvaged components (like a decommissioned PC). Just have a generic Linux install on it and make sure it is configured so it can be plugged in and accessed from the network.</li>
<li>a <strong>spare US$50 router</strong>, preferably pre-configured to be a temporary drop-in replacement for the existing router/firewall. Ideally, configure it to forward port 22 (SSH) to the spare Linux box so you can easily access the spare box from outside.</li>
<li>USB external <strong>hard-drive enclosure</strong>.</li>
<li>a spare PC <strong>power supply</strong>.</li>
<li>some network cables, a couple of screwdrivers.</li>
</ul>

<p>There are many more tools, such as rescue-CDs (like bootable Linux distributions), spare HDD, etc that can be kept but you have to remember that your point of contact need to be able to be your eyes and hands, so the amount of tools you provide should match their technical abilities.<br />
Don&#8217;t forget to clearly label confusing things like network ports (LAN, WAN) on routers, cables and PCs.</p>

<p>The point is that if you can&#8217;t be on site within a short period of time, then having these cheap tools and accessories already on site mean that your customers can quickly recover just by following your instructions on the phone.<br />
Once everything is plugged-in, you should be able to remotely carry-out most repairs.</p>

<h3>Resources</h3>

<ul>
<li><a href="http://www.linuxconfig.org/Linux_Software_Raid_1_Setup">Linux software RAID1 setup</a></li>
<li><a href="http://dailypackage.fedorabook.com/index.php?/categories/11-System-Recovery-Week">Fedora System Recovery Week</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.nkadesign.com/2008/linux-sysadmin-a-short-troubleshooting-story/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MediaWiki: Formating and colouring Code</title>
		<link>http://blog.nkadesign.com/2007/mediawiki-formating-and-colouring-code/</link>
		<comments>http://blog.nkadesign.com/2007/mediawiki-formating-and-colouring-code/#comments</comments>
		<pubDate>Tue, 20 Feb 2007 07:57:37 +0000</pubDate>
		<dc:creator>Renaud Bompuis</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://blog.nkadesign.com/?p=39</guid>
		<description><![CDATA[MediaWiki is the wiki software behind WikiPedia. The issue, when using it as a software development tool, is formatting code in a pretty way. As we did with WordPress before, here are some details to make dp.SyntaxHighlighter work fairly seamlessly with MediaWiki. Install the client-side highlighter Download dp.SyntaxHighlighter. Uncompress its content under a new /skins/common/SyntaxHighlighter [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/technology01.png" alt="technology01.png" title="technology01.png" align="left" width="64" height="64" hspace="5" vspace="5" border="0" /><a href="http://www.mediawiki.org">MediaWiki </a>is the wiki software behind <a href="http://www.wikipedia.org">WikiPedia</a>.<br />
The issue, when using it as a software development tool, is formatting code in a pretty way.
<a href="http://blog.nkadesign.com/?p=30">As we did with WordPress before</a>, here are some details to make <a href="http://www.dreamprojections.com/syntaxhighlighter/">dp.SyntaxHighlighter</a> work fairly seamlessly with MediaWiki.</p>

<h3>Install the client-side highlighter</h3>

<p>Download <a href="http://www.dreamprojections.com/syntaxhighlighter/">dp.SyntaxHighlighter</a>.
Uncompress its content under a new <code>/skins/common/SyntaxHighlighter</code> folder in your MediaWiki installation (don&#8217;t forget to make sure the files can be read by the web server; for instance, on Linux you may use <code>chown apache.apache -R *</code>).</p>

<p>In the skin template you are using for your MediaWiki site, insert the necessary code as required. In my example, I use the default <code>/skins/MonoBook.php</code> template into which I added the following:</p>

<p>Just before the closing <code>&lt;/head&gt;</code> tag:<br />
<textarea name="code" class="xml:nogutter:nocontrols">
<!-- http://www.dreamprojections.com/syntaxhighlighter/ -->
<link type="text/css" rel="stylesheet" href="/skins/common/SyntaxHighlighter/Styles/SyntaxHighlighter.css"></link></textarea>Just before the closing <code>&lt;/body&gt;</code> tag:<textarea name="code" class="xml:nogutter:nocontrols"><!-- http://www.dreamprojections.com/syntaxhighlighter/ -->
<script language="javascript" src="/skins/common/SyntaxHighlighter/Scripts/shCore.js"></script>
<script language="javascript" src="/skins/common/SyntaxHighlighter/Scripts/shBrushCSharp.js"></script>
<script language="javascript" src="/skins/common/SyntaxHighlighter/Scripts/shBrushXml.js"></script>
<script language="javascript" src="/skins/common/SyntaxHighlighter/Scripts/shBrushSql.js"></script>
<script language="javascript" src="/skins/common/SyntaxHighlighter/Scripts/shBrushJScript.js"></script>
<script language="javascript" src="/skins/common/SyntaxHighlighter/Scripts/shBrushPhp.js"></script>
<script language="javascript">
    dp.SyntaxHighlighter.HighlightAll('code');
</script></textarea></p>

<blockquote>
  <p><em>Note that you must include a reference to each source file corresponding to the type of programming language you want to highlight.<br />
  Have a look under the <code>/skins/common/SyntaxHighlighter/Scripts/</code> folder to see which languages you can highlight; there are a lot more than the few I use on my site.</em></p>
</blockquote>

<h3>Install the WikiMedia extension</h3>

<p>I&#8217;ve created a small extension to WikiMedia to allow us to enclose any source code in a new <code>&lt;codesyntax&gt;</code> tag.
Click on the <em>View Plain</em> option below and copy-paste the following code into a new file that you will save under <code>/extensions/syntaxhighlighter.php</code> (again, make sure this is readable by the webserver).<br />
<textarea name="code" class="php:nogutter">&lt;?php
/************************************************************
** Simple WikiMedia extension to create a new &lt;codesyntax&gt; tag that renders 
** syntax highlighted through the dp.SyntaxHighlighter javascript helper
** See http://www.dreamprojections.com/syntaxhighlighter/
** See http://meta.wikimedia.org/wiki/Extending_wiki_markup
** (c) Renaud Bompuis, 2007
** ------------------------------------------------------------------------------
** v1.0 - 20EFB2007 : first version. Uses the &lt;pre&gt; tag to ensure that the content of 
** the &lt;textarea&gt; containing the source code will not be messed up by WikiMedia.
** There are certainly better ways to do this, but they seem more complicated than this 
** (registering hooks, recording content before it is expanded and then replacing 
**  messed up content with the original)
************************************************************/
$wgExtensionFunctions[] = "wfSyntaxHighlighterExtension";

function wfSyntaxHighlighterExtension() {
    global $wgParser;
    $wgParser->setHook( "codesyntax", "renderCodeSyntax" );
}

// The callback function for converting the input text to HTML output
function renderCodeSyntax( $input, $argv, &$parser ) {
	$output = "&lt;pre style='border:0;padding:0;margin:0;'&gt;"
			  ."&lt;textarea name='code' class='".$argv["lang"]."'&gt;"
			  .Xml::escapeTagsOnly($input)
			  ."&lt;/textarea&gt;&lt;/pre&gt;" ;
    return $output;
}
?&gt;</textarea><br />
Add the following line to the end of your <code>LocalSettings.php</code> file, right before the closing <code>?&gt;</code> tag.<br />
<textarea name="code" class="php:nogutter:nocontrols">
require_once 'extensions/syntaxhighlighter.php';
</textarea></p>

<h3>Usage</h3>

<p>To highlight code in your MediaWiki pages, just enclose your source code with the new <code>&lt;codesyntax&gt;</code> tag. This tag takes a <code>lang</code> attribute to specify the options that normally would be listed in the <code>class</code> attribute in the <em>dp.SyntaxHighlighter</em> documentation.</p>

<p>For example:<br />
<textarea name="code" class="php:nogutter:nocontrols">
&lt;codesyntax lang="c#"&gt;
string url = "&lt;a href=\"" + someObj.getUrl() + "\" target=\"_blank\"&gtl;";
// single line comments
// second single line
override protected void OnLoad(EventArgs e)
{
	if(Attributes["class"] != null)
	{
		//_year.CssClass = Attributes["class"];
	}
//	base.OnLoad(e);
}
&lt;/codesyntax&gt;
</textarea><br />
Will display as:<br />
<textarea name="code" class="c#">string url = "&lt;a href=\"" + someObj.getUrl() + "\" target=\"_blank\"&gt;";
// single line comments
// second single line
override protected void OnLoad(EventArgs e)
{
	if(Attributes["class"] != null)
	{
		//_year.CssClass = Attributes["class"];
	}
//	base.OnLoad(e);
}
</textarea></p>

<p>For more information on using <em>dp.SyntaxHighlighter</em> see:<br />
<a href="http://www.dreamprojections.com/syntaxhighlighter/Usage.aspx">http://www.dreamprojections.com/syntaxhighlighter/Usage.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nkadesign.com/2007/mediawiki-formating-and-colouring-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

