<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.3" -->
<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/"
	>

<channel>
	<title>Frsky’s blog .</title>
	<link>http://frsky.net</link>
	<description>Rejoicing in hope, patient in tribulation.</description>
	<pubDate>Wed, 21 Jan 2009 15:13:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>
	<language>en</language>
			<item>
		<title>Bad block HOWTO for smartmontools</title>
		<link>http://frsky.net/?p=102</link>
		<comments>http://frsky.net/?p=102#comments</comments>
		<pubDate>Wed, 21 Jan 2009 15:13:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=102</guid>
		<description><![CDATA[

Bad block HOWTO for smartmontools

Bruce Allen


      &#60;smartmontools-support@lists.sourceforge.net&#62;
     

Douglas Gilbert


      &#60;smartmontools-support@lists.sourceforge.net&#62;
     
Copyright © 2004, 2005, 2006, 2007 Bruce Allen
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no [...]]]></description>
			<content:encoded><![CDATA[<p lang="en" class="article">
<p class="titlepage">
<h2 class="title"><a name="index"></a>Bad block HOWTO for smartmontools</h2>
<p class="author">
<h3 class="author"><span class="firstname">Bruce</span> <span class="surname">Allen</span></h3>
<p class="affiliation">
<p class="address">
      <code class="email"><font face="Courier New">&lt;</font><a href="mailto:smartmontools-support@lists.sourceforge.net" class="email"><font face="Courier New">smartmontools-support@lists.sourceforge.net</font></a><font face="Courier New">&gt;</font></code><br />
     </p>
<p class="author">
<h3 class="author"><span class="firstname">Douglas</span> <span class="surname">Gilbert</span></h3>
<p class="affiliation">
<p class="address">
      <code class="email"><font face="Courier New">&lt;</font><a href="mailto:smartmontools-support@lists.sourceforge.net" class="email"><font face="Courier New">smartmontools-support@lists.sourceforge.net</font></a><font face="Courier New">&gt;</font></code><br />
     </p>
<p class="copyright">Copyright © 2004, 2005, 2006, 2007 Bruce Allen</p>
<p class="legalnotice"><a name="id2755670"></a>Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts.</p>
<p>For an online copy of the license see <a target="_top" href="http://www.fsf.org/copyleft/fdl.html" class="ulink"><code class="literal"><font face="Courier New">www.fsf.org/copyleft/fdl.html</font></code></a>.</p>
<p class="pubdate">2007-01-23</p>
<p class="revhistory">
<table border="1" summary="Revision history" width="100%">
<tr>
<th colSpan="3" align="left" vAlign="top"><strong>Revision History</strong></th>
</tr>
<tr>
<td align="left">Revision 1.1</td>
<td align="left">2007-01-23</td>
<td align="left">dpg</td>
</tr>
<tr>
<td colSpan="3" align="left">add sections on ReiserFS and partition table damage</td>
</tr>
<tr>
<td align="left">Revision 1.0</td>
<td align="left">2006-11-14</td>
<td align="left">dpg</td>
</tr>
<tr>
<td colSpan="3" align="left">merge BadBlockHowTo.txt and BadBlockSCSIHowTo.txt</td>
</tr>
</table>
<p class="abstract">
<p class="title"><strong>Abstract</strong></p>
<p>This article describes what actions might be taken when smartmontools detects a bad block on a disk. It demonstrates how to identify the file associated with an unreadable disk sector, and how to force that sector to reallocate.</p>
<hr />
<p class="toc"><strong>Table of Contents</strong></p>
<dl>
<dt><span class="sect1"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#intro">Introduction</a></span> </dt>
<dt><span class="sect1"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#rfile">Repairs in a file system</a></span> </dt>
<dd>
<dl>
<dt><span class="sect2"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#e2_example1">ext2/ext3 first example</a></span> </dt>
<dt><span class="sect2"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#e2_example2">ext2/ext3 second example</a></span> </dt>
<dt><span class="sect2"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#unassigned">Unassigned sectors</a></span> </dt>
<dt><span class="sect2"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#reiserfs_ex">ReiserFS example</a></span></dt>
</dl>
</dd>
<dt><span class="sect1"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#sdisk">Repairs at the disk level</a></span> </dt>
<dd>
<dl>
<dt><span class="sect2"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#partition">Partition table problems</a></span> </dt>
<dt><span class="sect2"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#lvm">LVM repairs</a></span> </dt>
<dt><span class="sect2"><a href="http://smartmontools.sourceforge.net/badblockhowto.html#bb">Bad block reassignment</a></span></dt>
</dl>
</dd>
</dl>
<p lang="en" class="sect1">
<p class="titlepage">
<h2 style="clear: both" class="title"><a name="intro"></a>Introduction</h2>
<p>Handling bad blocks is a difficult problem as it often involves decisions about losing information. Modern storage devices tend to handle the simple cases automatically, for example by writing a disk sector that was read with difficulty to another area on the media. Even though such a remapping can be done by a disk drive transparently, there is still a lingering worry about media deterioration and the disk running out of spare sectors to remap.</p>
<p>Can smartmontools help? As the <acronym class="acronym">SMART</acronym> acronym <sup>[<a name="id2717542" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2717542" class="footnote">1</a>]</sup> suggests, the <span class="command"><strong>smartctl</strong></span> command and the <span class="command"><strong>smartd</strong></span> daemon concentrate on monitoring and analysis. So apart from changing some reporting settings, smartmontools will not modify the raw data in a device. Also smartmontools only works with physical devices, it does not know about partitions and file systems. So other tools are needed. The job of smartmontools is to alert the user that something is wrong and user intervention may be required.</p>
<p>When a bad block is reported one approach is to work out the mapping between the logical block address used by a storage device and a file or some other component of a file system using that device. Note that there may not be such a mapping reflecting that a bad block has been found at a location not currently used by the file system. A user may want to do this analysis to localize and minimize the number of replacement files that are retrieved from some backup store. This approach requires knowledge of the file system involved and this document uses the Linux ext2/ext3 and ReiserFS file systems for examples. Also the type of content may come into play. For example if an area storing video has a corrupted sector, it may be easiest to accept that a frame or two might be corrupted and instruct the disk not to retry as that may have the visual effect of causing a momentary blank into a 1 second pause (while the disk retries the faulty sector, often accompanied by a telltale clicking sound).</p>
<p>Another approach is to ignore the upper level consequences (e.g. corrupting a file or worse damage to a file system) and use the facilities offered by a storage device to repair the damage. The SCSI disk command set is used elaborate on this low level approach.</p>
<p lang="en" class="sect1">
<p class="titlepage">
<h2 style="clear: both" class="title"><a name="rfile"></a>Repairs in a file system</h2>
<p>This section contains examples of what to do at the file system level when smartmontools reports a bad block. These examples assume the Linux operating system and either the ext2/ext3 or ReiserFS file system. The various Linux commands shown have man pages and the reader is encouraged to examine these. Of note is the <span class="command"><strong>dd</strong></span> command which is often used in repair work <sup>[<a name="id2717619" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2717619" class="footnote">2</a>]</sup> and has a unique command line syntax.</p>
<p>The authors would like to thank Sergey Vlasov, Theodore Ts&#8217;o, Michael Bendzick, and others for explaining this approach. The authors would like to add text showing how to do this for other file systems, in particular XFS, and JFS: please email if you can provide this information.</p>
<p lang="en" class="sect2">
<p class="titlepage">
<h3 class="title"><a name="e2_example1"></a>ext2/ext3 first example</h3>
<p>In this example, the disk is failing self-tests at Logical Block Address LBA = 0&#215;016561e9 = 23421417. The LBA counts sectors in units of 512 bytes, and starts at zero.</p>
<pre class="programlisting">root]# smartctl -l selftest /dev/hda:  SMART Self-test log structure revision number 1 Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error # 1  Extended offline    Completed: read failure       90%       217         0x016561e9</pre>
<p>Note that other signs that there is a bad sector on the disk can be found in the non-zero value of the Current Pending Sector count:</p>
<pre class="programlisting">root]# smartctl -A /dev/hda ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE   5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0 196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0 197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       1 198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       1</pre>
<p>First Step: We need to locate the partition on which this sector of the disk lives:</p>
<pre class="programlisting">root]# fdisk -lu /dev/hda  Disk /dev/hda: 123.5 GB, 123522416640 bytes 255 heads, 63 sectors/track, 15017 cylinders, total 241254720 sectors Units = sectors of 1 * 512 = 512 bytes     Device Boot    Start       End    Blocks   Id  System /dev/hda1   *        63   4209029   2104483+  83  Linux /dev/hda2       4209030   5269319    530145   82  Linux swap /dev/hda3       5269320 238227884 116479282+  83  Linux /dev/hda4     238227885 241248104   1510110   83  Linux</pre>
<p>The partition <code class="filename"><font face="Courier New">/dev/hda3</font></code> starts at LBA 5269320 and extends past the &#8216;problem&#8217; LBA. The &#8216;problem&#8217; LBA is offset 23421417 - 5269320 = 18152097 sectors into the partition <code class="filename"><font face="Courier New">/dev/hda3</font></code>.</p>
<p>To verify the type of the file system and the mount point, look in <code class="filename"><font face="Courier New">/etc/fstab</font></code>:</p>
<pre class="programlisting">root]# grep hda3 /etc/fstab /dev/hda3 /data ext2 defaults 1 2</pre>
<p>You can see that this is an ext2 file system, mounted at <code class="filename"><font face="Courier New">/data</font></code>.</p>
<p>Second Step: we need to find the block size of the file system (normally 4096 bytes for ext2):</p>
<pre class="programlisting">root]# tune2fs -l /dev/hda3 | grep Block Block count:              29119820 Block size:               4096</pre>
<p>In this case the block size is 4096 bytes. Third Step: we need to determine which File System Block contains this LBA. The formula is:</p>
<pre class="programlisting">  b = (int)((L-S)*512/B) where: b = File System block number B = File system block size in bytes L = LBA of bad sector S = Starting sector of partition as shown by fdisk -lu and (int) denotes the integer part.</pre>
<p>In our example, L=23421417, S=5269320, and B=4096. Hence the &#8216;problem&#8217; LBA is in block number</p>
<pre class="programlisting">   b = (int)18152097*512/4096 = (int)2269012.125 so b=2269012.</pre>
<p>Note: the fractional part of 0.125 indicates that this problem LBA is actually the second of the eight sectors that make up this file system block.</p>
<p>Fourth Step: we use debugfs to locate the inode stored in this block, and the file that contains that inode:</p>
<pre class="programlisting">root]# debugfs debugfs 1.32 (09-Nov-2002) debugfs:  open /dev/hda3 debugfs:  icheck 2269012 Block   Inode number 2269012 41032 debugfs:  ncheck 41032 Inode   Pathname 41032   /S1/R/H/714197568-714203359/H-R-714202192-16.gwf</pre>
<p>In this example, you can see that the problematic file (with the mount point included in the path) is: <code class="filename"><font face="Courier New">/data/S1/R/H/714197568-714203359/H-R-714202192-16.gwf</font></code></p>
<p>To force the disk to reallocate this bad block we&#8217;ll write zeros to the bad block, and sync the disk:</p>
<pre class="programlisting">root]# dd if=/dev/zero of=/dev/hda3 bs=4096 count=1 seek=2269012 root]# sync</pre>
<p><span class="emphasis"><em>NOTE:</em></span> This last step has <span class="emphasis"><em>permanently </em></span>and irretrievably <span class="emphasis"><em>destroyed</em></span> some of the data that was in this file. Don&#8217;t do this unless you don&#8217;t need the file or you can replace it with a fresh or correct version.</p>
<p>Now everything is back to normal: the sector has been reallocated. Compare the output just below to similar output near the top of this article:</p>
<pre class="programlisting">root]# smartctl -A /dev/hda ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE   5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       1 196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       1 197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0 198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       1</pre>
<p>Note: for some disks it may be necessary to update the SMART Attribute values by using <span class="command"><strong>smartctl -t offline /dev/hda</strong></span></p>
<p>The disk now passes its self-tests again:</p>
<pre class="programlisting">root]# smartctl -t long /dev/hda  [wait until test completes, then] root]# smartctl -l selftest /dev/hda  SMART Self-test log structure revision number 1 Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error # 1  Extended offline    Completed without error       00%       239         - # 2  Extended offline    Completed: read failure       90%       217         0x016561e9 # 3  Extended offline    Completed: read failure       90%       212         0x016561e9 # 4  Extended offline    Completed: read failure       90%       181         0x016561e9 # 5  Extended offline    Completed without error       00%        14         - # 6  Extended offline    Completed without error       00%         4         -</pre>
<p>and no longer shows any offline uncorrectable sectors:</p>
<pre class="programlisting">root]# smartctl -A /dev/hda ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE   5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       1 196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       1 197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0 198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0</pre>
<p lang="en" class="sect2">
<p class="titlepage">
<h3 class="title"><a name="e2_example2"></a>ext2/ext3 second example</h3>
<p>On this drive, the first sign of trouble was this email from smartd:</p>
<pre class="programlisting">    To: ballen     Subject: SMART error (selftest) detected on host: medusa-slave166.medusa.phys.uwm.edu      This email was generated by the smartd daemon running on host:     medusa-slave166.medusa.phys.uwm.edu in the domain: master001-nis      The following warning/error was logged by the smartd daemon:     Device: /dev/hda, Self-Test Log error count increased from 0 to 1</pre>
<p>Running <span class="command"><strong>smartctl -a /dev/hda</strong></span> confirmed the problem:</p>
<pre class="programlisting">Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error # 1  Extended offline    Completed: read failure       80%       682         0x021d9f44  Note that the failing LBA reported is 0x021d9f44 (base 16) = 35495748 (base 10)      ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE   5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0 196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0 197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       3 198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       3</pre>
<p>and one can see above that there are 3 sectors on the list of pending sectors that the disk can&#8217;t read but would like to reallocate.</p>
<p>The device also shows errors in the SMART error log:</p>
<pre class="programlisting">Error 212 occurred at disk power-on lifetime: 690 hours   After command completion occurred, registers were:   ER ST SC SN CL CH DH   -- -- -- -- -- -- --   40 51 12 46 9f 1d e2  Error: UNC 18 sectors at LBA = 0x021d9f46 = 35495750    Commands leading to the command that caused the error were:   CR FR SC SN CL CH DH DC   Timestamp  Command/Feature_Name   -- -- -- -- -- -- -- --   ---------  --------------------   25 00 12 46 9f 1d e0 00 2485545.000  READ DMA EXT</pre>
<p>Signs of trouble at this LBA may also be found in SYSLOG:</p>
<pre class="programlisting">[root]# grep LBA /var/log/messages | awk '{print $12}' | sort | uniq  LBAsect=35495748  LBAsect=35495750</pre>
<p>So I decide to do a quick check to see how many bad sectors there really are. Using the bash shell I check 70 sectors around the trouble area:</p>
<pre class="programlisting">[root]# export i=35495730 [root]# while [ $i -lt 35495800 ]         &gt; do echo $i         &gt; dd if=/dev/hda of=/dev/null bs=512 count=1 skip=$i         &gt; let i+=1         &gt; done   &lt;SNIP&gt;     35495734 1+0 records in 1+0 records out 35495735 dd: reading `/dev/hda': Input/output error 0+0 records in 0+0 records out  &lt;SNIP&gt;  35495751 dd: reading `/dev/hda': Input/output error 0+0 records in 0+0 records out 35495752 1+0 records in 1+0 records out  &lt;SNIP&gt;</pre>
<p>which shows that the seventeen sectors 35495735-35495751 (inclusive) are not readable.</p>
<p>Next, we identify the files at those locations. The partitioning information on this disk is identical to the first example above, and as in that case the problem sectors are on the third partition <code class="filename"><font face="Courier New">/dev/hda3</font></code>. So we have:</p>
<pre class="programlisting">     L=35495735 to 35495751      S=5269320      B=4096</pre>
<p>so that b=3778301 to 3778303 are the three bad blocks in the file system.</p>
<pre class="programlisting">[root]# debugfs debugfs 1.32 (09-Nov-2002) debugfs:  open /dev/hda3 debugfs:  icheck 3778301 Block   Inode number 3778301 45192 debugfs:  icheck 3778302 Block   Inode number 3778302 45192 debugfs:  icheck 3778303 Block   Inode number 3778303 45192 debugfs:  ncheck 45192 Inode   Pathname 45192   /S1/R/H/714979488-714985279/H-R-714979984-16.gwf debugfs:  quit</pre>
<p>And finally, just to confirm that this is really the damaged file:</p>
<pre class="programlisting">[root]# md5sum /data/S1/R/H/714979488-714985279/H-R-714979984-16.gwf md5sum: /data/S1/R/H/714979488-714985279/H-R-714979984-16.gwf: Input/output error</pre>
<p>Finally we force the disk to reallocate the three bad blocks:</p>
<pre class="programlisting">[root]# dd if=/dev/zero of=/dev/hda3 bs=4096 count=3 seek=3778301 [root]# sync</pre>
<p>We could also probably use:</p>
<pre class="programlisting">[root]# dd if=/dev/zero of=/dev/hda bs=512 count=17 seek=35495735</pre>
<p>At this point we now have:</p>
<pre class="programlisting">ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE   5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0 196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0 197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0 198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0</pre>
<p>which is encouraging, since the pending sectors count is now zero. Note that the drive reallocation count has not yet increased: the drive may now have confidence in these sectors and have decided not to reallocate them..</p>
<p>A device self test:</p>
<pre class="programlisting">  [root#] smartctl -t long /dev/hda (then wait about an hour) shows no unreadable sectors or errors:  Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error # 1  Extended offline    Completed without error       00%       692         - # 2  Extended offline    Completed: read failure       80%       682         0x021d9f44</pre>
<p lang="en" class="sect2">
<p class="titlepage">
<h3 class="title"><a name="unassigned"></a>Unassigned sectors</h3>
<p>This section was written by Kay Diederichs. Even though this section assumes Linux and the ext2/ext3 file system, the strategy should be more generally applicable.</p>
<p>I read your badblocks-howto at and greatly benefited from it. One thing that&#8217;s (maybe) missing is that often the <span class="command"><strong>smartctl -t long</strong></span> scan finds a bad sector which is <span class="emphasis"><em>not</em></span> assigned to any file. In that case it does not help to run debugfs, or rather debugfs reports the fact that no file owns that sector. Furthermore, it is somewhat laborious to come up with the correct numbers for debugfs, and debugfs is slow &#8230;</p>
<p>So what I suggest in the case of presence of Current_Pending_Sector/Offline_Uncorrectable errors is to create a huge file on that file system.</p>
<pre class="programlisting">  dd if=/dev/zero of=/some/mount/point bs=4k</pre>
<p>creates the file. Leave it running until the partition/file system is full. This will make the disk reallocate those sectors which do not belong to a file. Check the <span class="command"><strong>smartctl -a</strong></span> output after that and make sure that the sectors are reallocated. If any remain, use the debugfs method. Of course the usual caveats apply - back it up first, and so on.</p>
<p lang="en" class="sect2">
<p class="titlepage">
<h3 class="title"><a name="reiserfs_ex"></a>ReiserFS example</h3>
<p>This section was written by Joachim Jautz with additions from Manfred Schwarb.</p>
<p>The following problems were reported during a scheduled test:</p>
<pre class="programlisting">smartd[575]: Device: /dev/hda, starting scheduled Offline Immediate Test. [... 1 hour later ...] smartd[575]: Device: /dev/hda, 1 Currently unreadable (pending) sectors smartd[575]: Device: /dev/hda, 1 Offline uncorrectable sectors</pre>
<p>[Step 0] The SMART selftest/error log (see <span class="command"><strong>smartctl -l selftest</strong></span>) indicated there was a problem with block address (i.e. the 512 byte sector at) 58656333. The partition table (e.g. see <span class="command"><strong>sfdisk -luS /dev/hda</strong></span> or <span class="command"><strong>fdisk -ul /dev/hda</strong></span>) indicated that this block was in the <code class="filename"><font face="Courier New">/dev/hda3</font></code> partition which contained a ReiserFS file system. That partition started at block address 54781650.</p>
<p>While doing the initial analysis it may also be useful to take a copy of the disk attributes returned by <span class="command"><strong>smartctl -A /dev/hda</strong></span>. Specifically the values associated with the &#8220;Reallocated_Sector_Ct&#8221; and &#8220;Reallocated_Event_Count&#8221; attributes (for ATA disks, the grown list (GLIST) length for SCSI disks). If these are incremented at the end of the procedure it indicates that the disk has re-allocated one or more sectors.</p>
<p>[Step 1] Get the file system&#8217;s block size:</p>
<pre class="programlisting"># debugreiserfs /dev/hda3 | grep '^Blocksize' Blocksize: 4096</pre>
<p>[Step 2] Calculate the block number:</p>
<pre class="programlisting"># echo "(58656333-54781650)*512/4096" | bc -l 484335.37500000000000000000</pre>
<p>It is re-assuring that the calculated 4 KB damaged block address in <code class="filename"><font face="Courier New">/dev/hda3</font></code> is less than &#8220;Count of blocks on the device&#8221; shown in the output of <span class="command"><strong>debugreiserfs</strong></span> shown above.</p>
<p>[Step 3] Try to get more info about this block =&gt; reading the block fails as expected but at least we see now that it seems to be unused. If we do not get the `Cannot read the block&#8217; error we should check if our calculation in [Step 2] was correct <img src='http://frsky.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<pre class="programlisting"># debugreiserfs -1 484335 /dev/hda3 debugreiserfs 3.6.19 (2003 http://www.namesys.com)  484335 is free in ondisk bitmap The problem has occurred looks like a hardware problem.</pre>
<p>If you have bad blocks, we advise you to get a new hard drive, because once you get one bad block that the disk drive internals cannot hide from your sight, the chances of getting more are generally said to become much higher (precise statistics are unknown to us), and this disk drive is probably not expensive enough for you to risk your time and data on it. If you don&#8217;t want to follow that advice then if you have just a few bad blocks, try writing to the bad blocks and see if the drive remaps the bad blocks (that means it takes a block it has in reserve and allocates it for use for of that block number). If it cannot remap the block, use <span class="command"><strong>badblock</strong></span> option (-B) with reiserfs utils to handle this block correctly.</p>
<pre class="programlisting">bread: Cannot read the block (484335): (Input/output error).  Aborted</pre>
<p>So it looks like we have the right (i.e. faulty) block address.</p>
<p>[Step 4] Try then to find the affected file <sup>[<a name="id2764899" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2764899" class="footnote">3</a>]</sup>:</p>
<pre class="programlisting">tar -cO /mydir | cat &gt;/dev/null</pre>
<p>If you do not find any unreadable files, then the block may be free or located in some metadata of the file system.</p>
<p>[Step 5] Try your luck: bang the affected block with <span class="command"><strong>badblocks -n</strong></span> (non-destructive read-write mode, do unmount first), if you are very lucky the failure is transient and you can provoke reallocation <sup>[<a name="id2764945" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2764945" class="footnote">4</a>]</sup>:</p>
<pre class="programlisting"># badblocks -b 4096 -p 3 -s -v -n /dev/hda3 `expr 484335 + 100` `expr 484335 - 100`</pre>
<p><sup>[<a name="id2764959" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2764959" class="footnote">5</a>]</sup></p>
<p>check success with <span class="command"><strong>debugreiserfs -1 484335 /dev/hda3</strong></span>. Otherwise:</p>
<p>[Step 6] Perform this step <span class="emphasis"><em>only</em></span> if Step 5 has failed to fix the problem: overwrite that block to force reallocation:</p>
<pre class="programlisting"># dd if=/dev/zero of=/dev/hda3 count=1 bs=4096 seek=484335 1+0 records in 1+0 records out 4096 bytes transferred in 0.007770 seconds (527153 bytes/sec)</pre>
<p>[Step 7] If you can&#8217;t rule out the bad block being in metadata, do a file system check:</p>
<pre class="programlisting">reiserfsck --check</pre>
<p>This could take a long time so you probably better go for lunch &#8230;</p>
<p>[Step 8] Proceed as stated earlier. For example, sync disk and run a long selftest that should succeed now.</p>
<p lang="en" class="sect1">
<p class="titlepage">
<h2 style="clear: both" class="title"><a name="sdisk"></a>Repairs at the disk level</h2>
<p>This section first looks at a damaged partition table. Then it ignores the upper level impact of a bad block and just repairs the underlying sector so that defective sector will not cause problems in the future.</p>
<p lang="en" class="sect2">
<p class="titlepage">
<h3 class="title"><a name="partition"></a>Partition table problems</h3>
<p>Some software failures can lead to zeroes or random data being written on the first block of a disk. For disks that use a DOS-based partitioning scheme this will overwrite the partition table which is found at the end of the first block. This is a single point of failure so after the damage tools like <span class="command"><strong>fdisk</strong></span> have no alternate data to use so they report no partitions or a damaged partition table.</p>
<p>One utility that may help is <a target="_top" href="http://www.cgsecurity.org/wiki/TestDisk" class="ulink"><code class="literal"><font face="Courier New">testdisk</font></code></a> which can scan a disk looking for partitions and recreate a partition table if requested. <sup>[<a name="id2765062" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2765062" class="footnote">6</a>]</sup></p>
<p>Programs that create DOS partitions often place the first partition at logical block address 63. In Linux a loop back mount can be attempted at the appropriate offset of a disk with a damaged partition table. This approach may involve placing the disk with the damaged partition table in a working computer or perhaps an external USB enclosure. Assuming the disk with the damaged partition is <code class="filename"><font face="Courier New">/dev/hdb</font></code>. Then the following read-only loop back mount could be tried:</p>
<pre class="programlisting"># mount -r /dev/hdb -o loop,offset=32256 /mnt</pre>
<p>The offset is in bytes so the number given is (63 * 512). If the file system cannot be identified then a &#8216;-t &lt;fs_type&gt;&#8217; may be needed (although this is not a good sign). If this mount is successful, a backup procedure is advised.</p>
<p>Only the primary DOS partitions are recorded in the first block of a disk. The extended DOS partition table is placed elsewhere on a disk. Again there is only one copy of it so it represents another single point of failure. All DOS partition information can be read in a form that can be used to recreate the tables with the <span class="command"><strong>sfdisk</strong></span> command. Obviously this needs to be done beforehand and the file put on other media. Here is how to fetch the partition table information:</p>
<pre class="programlisting"># sfdisk -dx /dev/hda &gt; my_disk_partition_info.txt</pre>
<p>Then <code class="filename"><font face="Courier New">my_disk_partition_info.txt</font></code> should be placed on other media. If disaster strikes, then the disk with the damaged partition table(s) can be placed in a working system, let us say the damaged disk is now at <code class="filename"><font face="Courier New">/dev/hdc</font></code>, and the following command restores the partition table(s):</p>
<pre class="programlisting"># sfdisk -x -O part_block_prior.img /dev/hdc &lt; my_disk_partition_info.txt</pre>
<p>Since the above command is potentially destructive it takes a copy of the block(s) holding the partition table(s) and puts it in <code class="filename"><font face="Courier New">part_block_prior.img</font></code> prior to any changes. Then it changes the partition tables as indicated by <code class="filename"><font face="Courier New">my_disk_partition_info.txt</font></code>. For what it is worth the author did test this on his system! <sup>[<a name="id2765181" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2765181" class="footnote">7</a>]</sup></p>
<p>For creating, destroying, resizing, checking and copying partitions, and the file systems on them, GNU&#8217;s <a target="_top" href="http://www.gnu.org/software/parted" class="ulink"><code class="literal"><font face="Courier New">parted</font></code></a> is worth examining. The <a target="_top" href="http://www.tldp.org/HOWTO/Large-Disk-HOWTO.html" class="ulink"><code class="literal"><font face="Courier New">Large Disk HOWTO</font></code></a> is also a useful resource.</p>
<p lang="en" class="sect2">
<p class="titlepage">
<h3 class="title"><a name="lvm"></a>LVM repairs</h3>
<p>This section was written by Frederic BOITEUX. It was titled: &#8220;HOW TO LOCATE AND REPAIR BAD BLOCKS ON AN LVM VOLUME&#8221;.</p>
<p>Smartd reports an error in a short test :</p>
<pre class="programlisting"># smartctl -a /dev/hdb ... SMART Self-test log structure revision number 1 Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error # 1  Short offline       Completed: read failure       90%        66         37383668</pre>
<p>So the disk has a bad block located in LBA block 37383668</p>
<p>In which physical partition is the bad block ?</p>
<pre class="programlisting"># sfdisk -luS /dev/hdb  # or 'fdisk -ul /dev/hdb'  Disk /dev/hdb: 9729 cylinders, 255 heads, 63 sectors/track Units = sectors of 512 bytes, counting from 0     Device Boot    Start       End   #sectors  Id  System /dev/hdb1            63    996029     995967  82  Linux swap / Solaris /dev/hdb2   *    996030   1188809     192780  83  Linux /dev/hdb3       1188810 156296384  155107575  8e  Linux LVM /dev/hdb4             0         -          0   0  Empty</pre>
<p>It&#8217;s in the <code class="filename"><font face="Courier New">/dev/hdb3</font></code> partition, a LVM2 partition. From the LVM2 partition beginning, the bad block has an offset of</p>
<pre class="programlisting">(37383668 - 1188810) = 36194858</pre>
<p>We have to find in which LVM2 logical partition the block belongs to.</p>
<p>In which logical partition is the bad block ?</p>
<p><span class="emphasis"><em>IMPORTANT</em></span> : LVM2 can use different schemes dividing its physical partitions to logical ones : linear, striped, contiguous or not&#8230; The following example assumes that allocation is linear !</p>
<p>The physical partition used by LVM2 is divided in PE (Physical Extent) units of the same size, starting at pe_start&#8217; 512 bytes blocks from the beginning of the physical partition.</p>
<p>The &#8216;pvdisplay&#8217; command gives the size of the PE (in KB) of the LVM partition :</p>
<pre class="programlisting">#  part=/dev/hdb3 ; pvdisplay -c $part | awk -F: '{print $8}' 4096</pre>
<p>To get its size in LBA block size (512 bytes or 0.5 KB), we multiply this number by 2 : 4096 * 2 = 8192 blocks for each PE.</p>
<p>To find the offset from the beginning of the physical partition is a bit more difficult : if you have a recent LVM2 version, try :</p>
<pre class="programlisting"># pvs -o+pe_start $part</pre>
<p>Either, you can look in /etc/lvm/backup :</p>
<pre class="programlisting"># grep pe_start $(grep -l $part /etc/lvm/backup/*)                         pe_start = 384</pre>
<p>Then, we search in which PE is the badblock, calculating the PE rank in which the faulty block of the partition is : physical partition&#8217;s bad block number / sizeof(PE) =</p>
<pre class="programlisting">36194858 / 8192 = 4418.3176</pre>
<p>So we have to find in which LVM2 logical partition is used the PE number 4418 (count starts from 0) :</p>
<pre class="programlisting"># lvdisplay --maps |egrep 'Physical|LV Name|Type'   LV Name                /dev/WDC80Go/racine     Type                linear     Physical volume     /dev/hdb3     Physical extents    0 to 127   LV Name                /dev/WDC80Go/usr     Type                linear     Physical volume     /dev/hdb3     Physical extents    128 to 1407   LV Name                /dev/WDC80Go/var     Type                linear     Physical volume     /dev/hdb3     Physical extents    1408 to 1663   LV Name                /dev/WDC80Go/tmp     Type                linear     Physical volume     /dev/hdb3     Physical extents    1664 to 1791   LV Name                /dev/WDC80Go/home     Type                linear     Physical volume     /dev/hdb3     Physical extents    1792 to 3071   LV Name                /dev/WDC80Go/ext1     Type                linear     Physical volume     /dev/hdb3     Physical extents    3072 to 10751   LV Name                /dev/WDC80Go/ext2     Type                linear     Physical volume     /dev/hdb3     Physical extents    10752 to 18932</pre>
<p>So the PE #4418 is in the <code class="filename"><font face="Courier New">/dev/WDC80Go/ext1</font></code> LVM logical partition.</p>
<p>Size of logical block of file system on <code class="filename"><font face="Courier New">/dev/WDC80Go/ext1 </font></code> :</p>
<p>It&#8217;s a ext3 fs, so I get it like this :</p>
<pre class="programlisting"># dumpe2fs /dev/WDC80Go/ext1 | grep 'Block size' dumpe2fs 1.37 (21-Mar-2005) Block size:               4096</pre>
<p>bad block number for the file system :</p>
<p>The logical partition begins on PE 3072 :</p>
<pre class="programlisting"> (# PE's start of partition * sizeof(PE)) + parttion offset[pe_start] =  (3072 * 8192) + 384 = 25166208</pre>
<p>512b block of the physical partition, so the bad block number for the file system  is :</p>
<pre class="programlisting">(36194858 - 25166208) / (sizeof(fs block) / 512) = 11028650 / (4096 / 512)  = 1378581.25</pre>
<p>Test of the fs bad block :</p>
<pre class="programlisting">dd if=/dev/WDC80Go/ext1 of=block1378581 bs=4096 count=1 skip=1378581</pre>
<p>If this dd command succeeds, without any error message in console or syslog, then the block number calculation is probably wrong ! *Don&#8217;t* go further, re-check it and if you don&#8217;t find the error, please renounce !</p>
<p>Search / correction follows the same scheme as for simple partitions :</p>
<p class="itemizedlist">
<ul type="disc">
<li>find possible impacted files with debugfs (icheck &lt;fs block nb&gt;, then ncheck &lt;icheck nb&gt;).</li>
<li>reallocate bad block writing zeros in it, *using the fs block size* :</li>
</ul>
<pre class="programlisting">dd if=/dev/zero of=/dev/WDC80Go/ext1 count=1 bs=4096 seek=1378581</pre>
<p>Et voilà !</p>
<p lang="en" class="sect2">
<p class="titlepage">
<h3 class="title"><a name="bb"></a>Bad block reassignment</h3>
<p>The SCSI disk command set and associated disk architecture are assumed in this section. SCSI disks have their own logical to physical mapping allowing a damaged sector (usually carrying 512 bytes of data) to be remapped irrespective of the operating system, file system or software RAID being used.</p>
<p>The terms <span class="emphasis"><em>block</em></span> and <span class="emphasis"><em>sector</em></span> are used interchangeably, although block tends to get used in higher level or more abstract contexts such as a <span class="emphasis"><em>logical block</em></span>.</p>
<p>When a SCSI disk is formatted, defective sectors identified during the manufacturing process (the so called primary list: PLIST), those found during the format itself (the certification list: CLIST), those given explicitly to the format command (the DLIST) and optionally the previous grown list (GLIST) are not used in the logical block map. The number (and low level addresses) of the unmapped sectors can be found with the READ DEFECT DATA SCSI command.</p>
<p>SCSI disks tend to be divided into zones which have spare sectors and perhaps spare tracks, to support the logical block address mapping process. The idea is that if a logical block is remapped, the heads do not have to move a long way to access the replacement sector. Note that spare sectors are a scarce resource.</p>
<p>Once a SCSI disk format has completed successfully, other problems may appear over time. These fall into two categories:</p>
<p class="itemizedlist">
<ul type="disc">
<li>recoverable: the Error Correction Codes (ECC) detect a problem but it is small enough to be corrected. Optionally other strategies such as retrying the access may retrieve the data.</li>
<li>unrecoverable: try as it may, the disk logic and ECC algorithms cannot recover the data. This is often reported as a <span class="emphasis"><em>medium error</em></span>.</li>
</ul>
<p>Other things can go wrong, typically associated with the transport and they will be reported using a term other than <span class="emphasis"><em>medium error</em></span>. For example a disk may decide a read operation was successful but a computer&#8217;s host bus adapter (HBA) checking the incoming data detects a CRC error due to a bad cable or termination.</p>
<p>Depending on the disk vendor, recoverable errors can be ignored. After all, some disks have up to 68 bytes of ECC above the payload size of 512 bytes so why use up spare sectors which are limited in number <sup>[<a name="id2765597" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2765597" class="footnote">8</a>]</sup> ? If the disk can recover the data and does decide to re-allocate (reassign) a sector, then first it checks the settings of the ARRE and AWRE bits in the read-write error recovery mode page. Usually these bits are set <sup>[<a name="id2765617" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2765617" class="footnote">9</a>]</sup> enabling automatic (read or write) re-allocation. The automatic re-allocation may also fail if the zone (or disk) has run out of spare sectors.</p>
<p>Another consideration with RAIDs, and applications that require a high data rate without pauses, is that the controller logic may not want a disk to spend too long trying to recover an error.</p>
<p>Unrecoverable errors will cause a <span class="emphasis"><em>medium error</em></span> sense key, perhaps with some useful additional sense information. If the extended background self test includes a full disk read scan, one would expect the self test log to list the bad block, as shown in the <a href="http://smartmontools.sourceforge.net/badblockhowto.html#rfile" title="Repairs in a file system" class="xref">the section called “Repairs in a file system”</a>. Recent SCSI disks with a periodic background scan should also list unrecoverable read errors (and some recoverable errors as well). The advantage of the background scan is that it runs to completion while self tests will often terminate at the first serious error.</p>
<p>SCSI disks expect unrecoverable errors to be fixed manually using the REASSIGN BLOCKS SCSI command since loss of data is involved. It is possible that an operating system or a file system could issue the REASSIGN BLOCKS command itself but the authors are unaware of any examples. The REASSIGN BLOCKS command will reassign one or more blocks, attempting to (partially ?) recover the data (a forlorn hope at this stage), fetch an unused spare sector from the current zone while adding the damaged old sector to the GLIST (hence the name &#8220;grown&#8221; list). The contents of the GLIST may not be that interesting but <span class="command"><strong>smartctl</strong></span> prints out the number of entries in the grown list and if that number grows quickly, the disk may be approaching the end of its useful life.</p>
<p>Here is an alternate brute force technique to consider: if the data on the SCSI or ATA disk has all been backed up (e.g. is held on the other disks in a RAID 5 enclosure), then simply reformatting the disk may be the least cumbersome approach.</p>
<p lang="en" class="sect3">
<p class="titlepage">
<h4 class="title"><a name="sexample"></a>Example</h4>
<p>Given a &#8220;bad block&#8221;, it still may be useful to look at the <span class="command"><strong>fdisk</strong></span> command (if the disk has multiple partitions) to find out which partition is involved, then use <span class="command"><strong>debugfs</strong></span> (or a similar tool for the file system in question) to find out which, if any, file or other part of the file system may have been damaged. This is discussed in the <a href="http://smartmontools.sourceforge.net/badblockhowto.html#rfile" title="Repairs in a file system" class="xref">the section called “Repairs in a file system”</a>.</p>
<p>Then a program that can execute the REASSIGN BLOCKS SCSI command is required. In Linux (2.4 and 2.6 series), FreeBSD, Tru64(OSF) and Windows the author&#8217;s <span class="command"><strong>sg_reassign</strong></span> utility in the sg3_utils package can be used. Also found in that package is <span class="command"><strong>sg_verify</strong></span> which can be used to check that a block is readable.</p>
<p>Assume that logical block address 1193046 (which is 123456 in hex) is corrupt <sup>[<a name="id2765838" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2765838" class="footnote">10</a>]</sup> on the disk at <code class="filename"><font face="Courier New">/dev/sdb</font></code>. A long selftest command like <span class="command"><strong>smartctl -t long /dev/sdb</strong></span> may result in log results like this:</p>
<pre class="programlisting"># smartctl -l selftest /dev/sdb smartctl version 5.37 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen Home page is http://smartmontools.sourceforge.net/   SMART Self-test log Num  Test              Status            segment  LifeTime  LBA_first_err [SK ASC ASQ]      Description                         number   (hours) # 1  Background long   Failed in segment      -     354           1193046 [0x3 0x11 0x0] # 2  Background short  Completed              -     323                 - [-   -    -] # 3  Background short  Completed              -     194                 - [-   -    -]</pre>
<p>The <span class="command"><strong>sg_verify</strong></span> utility can be used to confirm that there is a problem at that address:</p>
<pre class="programlisting"># sg_verify --lba=1193046 /dev/sdb verify (10):  Fixed format, current;  Sense key: Medium Error  Additional sense: Unrecovered read error   Info fld=0x123456 [1193046]   Field replaceable unit code: 228   Actual retry count: 0x008b medium or hardware error, reported lba=0x123456</pre>
<p>Now the GLIST length is checked before the block reassignment:</p>
<pre class="programlisting"># sg_reassign --grown /dev/sdb &gt;&gt; Elements in grown defect list: 0</pre>
<p>And now for the actual reassignment followed by another check of the GLIST length:</p>
<pre class="programlisting"># sg_reassign --address=1193046 /dev/sdb  # sg_reassign --grown /dev/sdb &gt;&gt; Elements in grown defect list: 1</pre>
<p>The GLIST length has grown by one as expected. If the disk was unable to recover any data, then the &#8220;new&#8221; block at lba 0&#215;123456 has vendor specific data in it. The <span class="command"><strong>sg_reassign</strong></span> utility can also do bulk reassigns, see <span class="command"><strong>man sg_reassign</strong></span> for more information.</p>
<p>The <span class="command"><strong>dd</strong></span> command could be used to read the contents of the &#8220;new&#8221; block:</p>
<pre class="programlisting"># dd if=/dev/sdb iflag=direct skip=1193046 of=blk.img bs=512 count=1</pre>
<p>and a hex editor <sup>[<a name="id2765955" href="http://smartmontools.sourceforge.net/badblockhowto.html#ftn.id2765955" class="footnote">11</a>]</sup> used to view and potentially change the <code class="filename"><font face="Courier New">blk.img</font></code> file. An altered <code class="filename"><font face="Courier New">blk.img</font></code> file (or <code class="filename"><font face="Courier New">/dev/zero</font></code>) could be written back with:</p>
<pre class="programlisting"># dd if=blk.img of=/dev/sdb seek=1193046 oflag=direct bs=512 count=1</pre>
<p>More work may be needed at the file system level, especially if the reassigned block held critical file system information such as a superblock or a directory.</p>
<p>Even if a full backup of the disk is available, or the disk has been &#8220;ejected&#8221; from a RAID, it may still be worthwhile to reassign the bad block(s) that caused the problem (or simply format the disk (see <span class="command"><strong>sg_format</strong></span> in the sg3_utils package)) and re-use the disk later (not unlike the way a replacement disk from a manufacturer might be used).</p>
<p>CVS $Id: badblockhowto.xml,v 1.5 2008/07/17 18:24:14 chrfranke Exp $</p>
<p class="footnotes">
<hr width="100" align="left" />
<p class="footnote"><sup>[<a name="ftn.id2717542" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2717542" class="para">1</a>] </sup>Self-Monitoring, Analysis and Reporting Technology -&gt; SMART</p>
<p class="footnote"><sup>[<a name="ftn.id2717619" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2717619" class="para">2</a>] </sup>Starting with GNU coreutils release 5.3.0, the <span class="command"><strong>dd</strong></span> command in Linux includes the options &#8216;iflag=direct&#8217; and &#8216;oflag=direct&#8217;. Using these with the <span class="command"><strong>dd</strong></span> commands should be helpful, because adding these flags should avoid any interaction with the block buffering IO layer in Linux and permit direct reads/writes from the raw device. Use <span class="command"><strong>dd &#8211;help</strong></span> to see if your version of dd supports these options. If not, the latest code for dd can be found at <a target="_top" href="http://alpha.gnu.org/gnu/coreutils" class="ulink"><code class="literal"><font face="Courier New">alpha.gnu.org/gnu/coreutils</font></code></a>.</p>
<p class="footnote"><sup>[<a name="ftn.id2764899" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2764899" class="para">3</a>] </sup>Do not use <span class="command"><strong>tar -c -f /dev/null</strong></span> or <span class="command"><strong>tar -cO /mydir &gt;/dev/null</strong></span>. GNU tar does not actually read the files if <code class="filename"><font face="Courier New">/dev/null</font></code> is used as archive path or as standard output, see <span class="command"><strong>info tar</strong></span>.</p>
<p class="footnote"><sup>[<a name="ftn.id2764945" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2764945" class="para">4</a>] </sup>Important: set blocksize range is arbitrary, but do not only test a single block, as bad blocks are often social. Not too large as this test probably has not 0% risk.</p>
<p class="footnote"><sup>[<a name="ftn.id2764959" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2764959" class="para">5</a>] </sup>The rather awkward `expr 484335 + 100` (note the back quotes) can be replaced with $((484335+100)) if the bash shell is being used. Similarly the last argument can become $((484335-100)) .</p>
<p class="footnote"><sup>[<a name="ftn.id2765062" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2765062" class="para">6</a>] </sup><span class="command"><strong>testdisk</strong></span> scans the media for the beginning of file systems that it recognizes. It can be tricked by data that looks like the beginning of a file system or an old file system from a previous partitioning of the media (disk). So care should be taken. Note that file systems should not overlap apart from the fact that extended partitions lie wholly within a extended partition table allocation. Also if the root partition of a Linux/Unix installation can be found then the <code class="filename"><font face="Courier New">/etc/fstab</font></code> file is a useful resource for finding the partition numbers of other partitions.</p>
<p class="footnote"><sup>[<a name="ftn.id2765181" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2765181" class="para">7</a>] </sup>Thanks to Manfred Schwarb for the information about storing partition table(s) beforehand.</p>
<p class="footnote"><sup>[<a name="ftn.id2765597" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2765597" class="para">8</a>] </sup>Detecting and fixing an error with ECC &#8220;on the fly&#8221; and not going the further step and reassigning the block in question may explain why some disks have large numbers in their read error counter log. Various worried users have reported large numbers in the &#8220;errors corrected without substantial delay&#8221; counter field which is in the &#8220;Errors corrected by ECC fast&#8221; column in the <span class="command"><strong>smartctl -l error</strong></span> output.</p>
<p class="footnote"><sup>[<a name="ftn.id2765617" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2765617" class="para">9</a>] </sup>Often disks inside a hardware RAID have the ARRE and AWRE bits cleared (disabled) so the RAID controller can do things manually or flag the disk for replacement.</p>
<p class="footnote"><sup>[<a name="ftn.id2765838" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2765838" class="para">10</a>] </sup>In this case the corruption was manufactured by using the WRITE LONG SCSI command. See <span class="command"><strong>sg_write_long</strong></span> in sg3_utils.</p>
<p class="footnote"><sup>[<a name="ftn.id2765955" href="http://smartmontools.sourceforge.net/badblockhowto.html#id2765955" class="para">11</a>] </sup>Most window managers have a handy calculator that will do hex to decimal conversions. More work may be needed at the file system level,</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=102</wfw:commentRss>
		</item>
		<item>
		<title>strace命令用法</title>
		<link>http://frsky.net/?p=101</link>
		<comments>http://frsky.net/?p=101#comments</comments>
		<pubDate>Fri, 26 Dec 2008 08:48:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=101</guid>
		<description><![CDATA[strace命令用法
调用:
strace [ -dffhiqrtttTvxx ] [ -acolumn ] [ -eexpr ] &#8230;
[ -ofile ] [ -ppid ] &#8230; [ -sstrsize ] [ -uusername ] [ command [ arg &#8230; ] ]
strace -c [ -eexpr ] &#8230; [ -Ooverhead ] [ -Ssortby ] [ command [ arg &#8230; ] ]
功能:
跟踪程式执行时的系统调用和所接收的信号.通常的用法是strace执行一直到commande结束.
并且将所调用的系统调用的名称、参数和返回值输出到标准输出或者输出到-o指定的文件.
strace是一个功能强大的调试,分析诊断工具.你将发现他是一个极好的帮手在你要调试一个无法看到源码或者源码无法在编译的程序.
你将轻松的学习到一个软件是如何通过系统调用来实现他的功能的.而且作为一个程序设计师,你可以了解到在用户态和内核态是如何通过系统调用和信号来实现程序的功能的.
strace的每一行输出包括系统调用名称,然后是参数和返回值.这个例子:
strace cat /dev/null
他的输出会有:
open(\\&#8221;/dev/null\\&#8221;,O_RDONLY) = 3
有错误产生时,一般会返回-1.所以会有错误标志和描述:
open(\\&#8221;/foor/bar\\&#8221;,)_RDONLY) = -1 ENOENT [...]]]></description>
			<content:encoded><![CDATA[<p>strace命令用法</p>
<p>调用:<br />
strace [ -dffhiqrtttTvxx ] [ -acolumn ] [ -eexpr ] &#8230;<br />
[ -ofile ] [ -ppid ] &#8230; [ -sstrsize ] [ -uusername ] [ command [ arg &#8230; ] ]</p>
<p>strace -c [ -eexpr ] &#8230; [ -Ooverhead ] [ -Ssortby ] [ command [ arg &#8230; ] ]<br />
功能:<br />
跟踪程式执行时的系统调用和所接收的信号.通常的用法是strace执行一直到commande结束.<br />
并且将所调用的系统调用的名称、参数和返回值输出到标准输出或者输出到-o指定的文件.<br />
strace是一个功能强大的调试,分析诊断工具.你将发现他是一个极好的帮手在你要调试一个无法看到源码或者源码无法在编译的程序.<br />
你将轻松的学习到一个软件是如何通过系统调用来实现他的功能的.而且作为一个程序设计师,你可以了解到在用户态和内核态是如何通过系统调用和信号来实现程序的功能的.<br />
strace的每一行输出包括系统调用名称,然后是参数和返回值.这个例子:<br />
strace cat /dev/null<br />
他的输出会有:<br />
open(<a href="file://%22/dev/null//%22,O_RDONLY">\\&#8221;/dev/null\\&#8221;,O_RDONLY</a>) = 3<br />
有错误产生时,一般会返回-1.所以会有错误标志和描述:<br />
open(<a href="file://%22/foor/bar//%22,)_RDONLY">\\&#8221;/foor/bar\\&#8221;,)_RDONLY</a>) = -1 ENOENT (no such file or directory)<br />
信号将输出喂信号标志和信号的描述.跟踪并中断这个命令<a href="file://%22sleep/">\\&#8221;sleep</a> 600\\&#8221;:<br />
sigsuspend({}<br />
&#8212; SIGINT (Interrupt) &#8212;<br />
+++ killed by SIGINT +++<br />
参数的输出有些不一致.如shell命令中的 <a href="file://%22%3e%3etmp//">\\&#8221;&gt;&gt;tmp\\</a>&#8220;,将输出:<br />
open(<a href="file://%22tmp//%22,O_WRONLY%7CO_APPEND%7CA_CREAT,0666">\\&#8221;tmp\\&#8221;,O_WRONLY|O_APPEND|A_CREAT,0666</a>) = 3<br />
对于结构指针,将进行适当的显示.如:\\&#8221;ls -l /dev/null\\&#8221;:<br />
lstat(<a href="file://%22/dev/null//%22,%7Bst_mode=S_IFCHR%7C0666%7D,st_rdev=makdev[1,3">\\&#8221;/dev/null\\&#8221;,{st_mode=S_IFCHR|0666},st_rdev=makdev[1,3</a>],&#8230;}) = 0<br />
请注意<a href="file://%22struct/">\\&#8221;struct</a> stat\\&#8221; 的声明和这里的输出.lstat的第一个参数是输入参数,而第二个参数是向外传值.<br />
当你尝试<a href="file://%22ls/">\\&#8221;ls</a> -l\\&#8221; 一个不存在的文件时,会有:<br />
lstat(/foot/ball\\&#8221;,0xb004) = -1 ENOENT (no such file or directory)<br />
char*将作为C的字符串类型输出.没有字符串输出时一般是char* 是一个转义字符,只输出字符串的长度.<br />
当字符串过长是会使用<a href="file://%22...//">\\&#8221;&#8230;\\</a>&#8220;省略.如在<a href="file://%22ls/">\\&#8221;ls</a> -l\\&#8221;会有一个gepwuid调用读取password文件:<br />
read(3,\\&#8221;root::0:0:System Administrator:/\\&#8221;&#8230;,1024) = 422<br />
当参数是结构数组时,将按照简单的指针和数组输出如:<br />
getgroups(4,[0,2,4,5]) = 4<br />
关于bit作为参数的情形,也是使用方括号,并且用空格将每一项参数隔开.如:<br />
sigprocmask(SIG_BLOCK,[CHLD TTOU],[]) = 0<br />
这里第二个参数代表两个信号SIGCHLD 和 SIGTTOU.如果bit型参数全部置位,则有如下的输出:<br />
sigprocmask(SIG_UNBLOCK,~[],NULL) = 0<br />
这里第二个参数全部置位.</p>
<p>参数说明:<br />
-c 统计每一系统调用的所执行的时间,次数和出错的次数等.<br />
-d 输出strace关于标准错误的调试信息.<br />
-f 跟踪由fork调用所产生的子进程.<br />
-ff 如果提供-o filename,则所有进程的跟踪结果输出到相应的filename.pid中,pid是各进程的进程号.<br />
-F 尝试跟踪vfork调用.在-f时,vfork不被跟踪.<br />
-h 输出简要的帮助信息.<br />
-i 输出系统调用的入口指针.<br />
-q 禁止输出关于脱离的消息.<br />
-r 打印出相对时间关于,,每一个系统调用.<br />
-t 在输出中的每一行前加上时间信息.<br />
-tt 在输出中的每一行前加上时间信息,微秒级.<br />
-ttt 微秒级输出,以秒了表示时间.<br />
-T 显示每一调用所耗的时间.<br />
-v 输出所有的系统调用.一些调用关于环境变量,状态,输入输出等调用由于使用频繁,默认不输出.<br />
-V 输出strace的版本信息.<br />
-x 以十六进制形式输出非标准字符串<br />
-xx 所有字符串以十六进制形式输出.<br />
-a column<br />
设置返回值的输出位置.默认为40.<br />
-e expr<br />
指定一个表达式,用来控制如何跟踪.格式如下:<br />
[qualifier=][!]value1[,value2]&#8230;<br />
qualifier只能是 trace,abbrev,verbose,raw,signal,read,write其中之一.value是用来限定的符号或数字.默认的qualifier是 trace.感叹号是否定符号.例如:<br />
-eopen等价于 -e trace=open,表示只跟踪open调用.而-etrace!=open表示跟踪除了open以外的其他调用.有两个特殊的符号 all 和 none.<br />
注意有些shell使用!来执行历史记录里的命令,所以要使用\\\\.<br />
-e trace=set<br />
只跟踪指定的系统调用.例如:-e trace=open,close,rean,write表示只跟踪这四个系统调用.默认的为set=all.<br />
-e trace=file<br />
只跟踪有关文件操作的系统调用.<br />
-e trace=process<br />
只跟踪有关进程控制的系统调用.<br />
-e trace=network<br />
跟踪与网络有关的所有系统调用.<br />
-e strace=signal<br />
跟踪所有与系统信号有关的系统调用<br />
-e trace=ipc<br />
跟踪所有与进程通讯有关的系统调用<br />
-e abbrev=set<br />
设定strace输出的系统调用的结果集.-v 等与 abbrev=none.默认为abbrev=all.<br />
-e raw=set<br />
将指定的系统调用的参数以十六进制显示.<br />
-e signal=set<br />
指定跟踪的系统信号.默认为all.如signal=!SIGIO(或者signal=!io),表示不跟踪SIGIO信号.<br />
-e read=set<br />
输出从指定文件中读出的数据.例如:<br />
-e read=3,5<br />
-e write=set<br />
输出写入到指定文件中的数据.<br />
-o filename<br />
将strace的输出写入文件filename<br />
-p pid<br />
跟踪指定的进程pid.<br />
-s strsize<br />
指定输出的字符串的最大长度.默认为32.文件名一直全部输出.<br />
-u username<br />
以username的UID和GID执行被跟踪的命令.<br />
用strace调试程序</p>
<p>     在理想世界里，每当一个程序不能正常执行一个功能时，它就会给出一个有用的错误提示，告诉你在足够的改正错误的线索。但遗憾的是，我们不是生活在理想世界里，起码不总是生活在理想世界里。有时候一个程序出现了问题，你无法找到原因。</p>
<p>这就是调试程序出现的原因。strace是一个必不可少的调试工具，strace用来监视系统调用。你不仅可以调试一个新开始的程序，也可以调试一个已经在运行的程序（把strace绑定到一个已有的PID上面）。</p>
<p>首先让我们看一个真实的例子：</p>
<p>[BOLD]启动KDE时出现问题[/BOLD]</p>
<p>前一段时间，我在启动KDE的时候出了问题，KDE的错误信息无法给我任何有帮助的线索。</p>
<p>代码：</p>
<p>_KDE_IceTransSocketCreateListener: failed to bind listener<br />
_KDE_IceTransSocketUNIXCreateListener: &#8230;SocketCreateListener() failed<br />
_KDE_IceTransMakeAllCOTSServerListeners: failed to create listener for local</p>
<p>Cannot establish any listening sockets DCOPServer self-test failed.</p>
<p>对我来说这个错误信息没有太多意义，只是一个对KDE来说至关重要的负责进程间通信的程序无法启动。我还可以知道这个错误和ICE协议（Inter Client Exchange）有关，除此之外，我不知道什么是KDE启动出错的原因。</p>
<p>我决定采用strace看一下在启动dcopserver时到底程序做了什么：</p>
<p>代码：</p>
<p>strace -f -F -o ~/dcop-strace.txt dcopserver</p>
<p>这里 -f -F选项告诉strace同时跟踪fork和vfork出来的进程，-o选项把所有strace输出写到~/dcop-strace.txt里面，dcopserver是要启动和调试的程序。</p>
<p>再次出现错误之后，我检查了错误输出文件dcop-strace.txt，文件里有很多系统调用的记录。在程序运行出错前的有关记录如下：</p>
<p>代码：</p>
<p>27207 mkdir(&#8221;/tmp/.ICE-unix&#8221;, 0777) = -1 EEXIST (File exists)<br />
27207 lstat64(&#8221;/tmp/.ICE-unix&#8221;, {st_mode=S_IFDIR|S_ISVTX|0755, st_size=4096, &#8230;}) = 0<br />
27207 unlink(&#8221;/tmp/.ICE-unix/dcop27207-1066844596&#8243;) = -1 ENOENT (No such file or directory)<br />
27207 bind(3, {sin_family=AF_UNIX, path=&#8221;/tmp/.ICE-unix/dcop27207-1066844596&#8243;}, 3 = -1 EACCES (Permission denied)<br />
27207 write(2, &#8220;_KDE_IceTrans&#8221;, 13) = 13<br />
27207 write(2, &#8220;SocketCreateListener: failed to &#8220;&#8230;, 46) = 46<br />
27207 close(3) = 0 27207 write(2, &#8220;_KDE_IceTrans&#8221;, 13) = 13<br />
27207 write(2, &#8220;SocketUNIXCreateListener: &#8230;Soc&#8221;&#8230;, 59) = 59<br />
27207 umask(0) = 0 27207 write(2, &#8220;_KDE_IceTrans&#8221;, 13) = 13<br />
27207 write(2, &#8220;MakeAllCOTSServerListeners: fail&#8221;&#8230;, 64) = 64<br />
27207 write(2, &#8220;Cannot establish any listening s&#8221;&#8230;, 39) = 39</p>
<p>其 中第一行显示程序试图创建/tmp/.ICE-unix目录，权限为0777，这个操作因为目录已经存在而失败了。第二个系统调用（lstat64）检查 了目录状态，并显示这个目录的权限是0755，这里出现了第一个程序运行错误的线索：程序试图创建属性为0777的目录，但是已经存在了一个属性为 0755的目录。第三个系统调用（unlink）试图删除一个文件，但是这个文件并不存在。这并不奇怪，因为这个操作只是试图删掉可能存在的老文件。</p>
<p>但 是，第四行确认了错误所在。他试图绑定到/tmp/.ICE-unix/dcop27207-1066844596，但是出现了拒绝访问错误。. ICE_unix目录的用户和组都是root，并且只有所有者具有写权限。一个非root用户无法在这个目录下面建立文件，如果把目录属性改成0777， 则前面的操作有可能可以执行，而这正是第一步错误出现时进行过的操作。</p>
<p>所以我运行了chmod 0777 /tmp/.ICE-unix之后KDE就可以正常启动了，问题解决了，用strace进行跟踪调试只需要花很短的几分钟时间跟踪程序运行，然后检查并分析输出文件。</p>
<p>说 明：运行chmod 0777只是一个测试，一般不要把一个目录设置成所有用户可读写，同时不设置粘滞位(sticky bit)。给目录设置粘滞位可以阻止一个用户随意删除可写目录下面其他人的文件。一般你会发现/tmp目录因为这个原因设置了粘滞位。KDE可以正常启动 之后，运行chmod +t /tmp/.ICE-unix给.ICE_unix设置粘滞位。</p>
<p>[BOLD]解决库依赖问题[/BOLD]</p>
<p>starce 的另一个用处是解决和动态库相关的问题。当对一个可执行文件运行ldd时，它会告诉你程序使用的动态库和找到动态库的位置。但是如果你正在使用一个比较老 的glibc版本（2.2或更早），你可能会有一个有bug的ldd程序，它可能会报告在一个目录下发现一个动态库，但是真正运行程序时动态连接程序 （/lib/ld-linux.so.2）却可能到另外一个目录去找动态连接库。这通常因为/etc/ld.so.conf和 /etc/ld.so.cache文件不一致，或者/etc/ld.so.cache被破坏。在glibc 2.3.2版本上这个错误不会出现，可能ld-linux的这个bug已经被解决了。</p>
<p>尽管这样，ldd并不能把所有程序 依赖的动态库列出来，系统调用dlopen可以在需要的时候自动调入需要的动态库，而这些库可能不会被ldd列出来。作为glibc的一部分的NSS （Name Server Switch）库就是一个典型的例子，NSS的一个作用就是告诉应用程序到哪里去寻找系统帐号数据库。应用程序不会直接连接到NSS库，glibc则会通 过dlopen自动调入NSS库。如果这样的库偶然丢失，你不会被告知存在库依赖问题，但这样的程序就无法通过用户名解析得到用户ID了。让我们看一个例 子：</p>
<p>whoami程序会给出你自己的用户名，这个程序在一些需要知道运行程序的真正用户的脚本程序里面非常有用，whoami的一个示例输出如下：<br />
代码：</p>
<p># whoami<br />
root</p>
<p>假设因为某种原因在升级glibc的过程中负责用户名和用户ID转换的库NSS丢失，我们可以通过把nss库改名来模拟这个环境：<br />
代码：</p>
<p># mv /lib/libnss_files.so.2 /lib/libnss_files.so.2.backup<br />
# whoami<br />
whoami: cannot find username for UID 0</p>
<p>这里你可以看到，运行whoami时出现了错误，ldd程序的输出不会提供有用的帮助：<br />
代码：</p>
<p># ldd /usr/bin/whoami<br />
libc.so.6 =&gt; /lib/libc.so.6 (0&#215;4001f000)<br />
/lib/ld-linux.so.2 =&gt; /lib/ld-linux.so.2 (0&#215;40000000)</p>
<p>你只会看到whoami依赖Libc.so.6和ld-linux.so.2，它没有给出运行whoami所必须的其他库。这里时用strace跟踪whoami时的输出：<br />
代码：</p>
<p>strace -o whoami-strace.txt whoami</p>
<p>open(&#8221;/lib/libnss_files.so.2&#8243;, O_RDONLY) = -1 ENOENT (No such file or directory)<br />
open(&#8221;/lib/i686/mmx/libnss_files.so.2&#8243;, O_RDONLY) = -1 ENOENT (No such file or directory)<br />
stat64(&#8221;/lib/i686/mmx&#8221;, 0xbffff190) = -1 ENOENT (No such file or directory)<br />
open(&#8221;/lib/i686/libnss_files.so.2&#8243;, O_RDONLY) = -1 ENOENT (No such file or directory)<br />
stat64(&#8221;/lib/i686&#8243;, 0xbffff190) = -1 ENOENT (No such file or directory)<br />
open(&#8221;/lib/mmx/libnss_files.so.2&#8243;, O_RDONLY) = -1 ENOENT (No such file or directory)<br />
stat64(&#8221;/lib/mmx&#8221;, 0xbffff190) = -1 ENOENT (No such file or directory)<br />
open(&#8221;/lib/libnss_files.so.2&#8243;, O_RDONLY) = -1 ENOENT (No such file or directory)<br />
stat64(&#8221;/lib&#8221;, {st_mode=S_IFDIR|0755, st_size=2352, &#8230;}) = 0<br />
open(&#8221;/usr/lib/i686/mmx/libnss_files.so.2&#8243;, O_RDONLY) = -1 ENOENT (No such file or directory)<br />
stat64(&#8221;/usr/lib/i686/mmx&#8221;, 0xbffff190) = -1 ENOENT (No such file or directory)<br />
open(&#8221;/usr/lib/i686/libnss_files.so.2&#8243;, O_RDONLY) = -1 ENOENT (No such file or directory)</p>
<p>你可以发现在不同目录下面查找libnss.so.2的尝试，但是都失败了。如果没有strace这样的工具，很难发现这个错误是由于缺少动态库造成的。现在只需要找到libnss.so.2并把它放回到正确的位置就可以了。</p>
<p>[BOLD]限制strace只跟踪特定的系统调用[/BOLD]</p>
<p>如果你已经知道你要找什么，你可以让strace只跟踪一些类型的系统调用。例如，你需要看看在configure脚本里面执行的程序，你需要监视的系统调用就是execve。让strace只记录execve的调用用这个命令：</p>
<p>代码：</p>
<p>strace -f -o configure-strace.txt -e execve ./configure</p>
<p>部分输出结果为：<br />
代码：</p>
<p>2720 execve(&#8221;/usr/bin/expr&#8221;, [&#8221;expr&#8221;, &#8220;a&#8221;, &#8220;:&#8221;, &#8220;(a)&#8221;], [/* 31 vars */]) = 0<br />
2725 execve(&#8221;/bin/basename&#8221;, [&#8221;basename&#8221;, &#8220;./configure&#8221;], [/* 31 vars */]) = 0<br />
2726 execve(&#8221;/bin/chmod&#8221;, [&#8221;chmod&#8221;, &#8220;+x&#8221;, &#8220;conftest.sh&#8221;], [/* 31 vars */]) = 0<br />
2729 execve(&#8221;/bin/rm&#8221;, [&#8221;rm&#8221;, &#8220;-f&#8221;, &#8220;conftest.sh&#8221;], [/* 31 vars */]) = 0<br />
2731 execve(&#8221;/usr/bin/expr&#8221;, [&#8221;expr&#8221;, &#8220;99&#8243;, &#8220;+&#8221;, &#8220;1&#8243;], [/* 31 vars */]) = 0<br />
2736 execve(&#8221;/bin/ln&#8221;, [&#8221;ln&#8221;, &#8220;-s&#8221;, &#8220;conf2693.file&#8221;, &#8220;conf2693&#8243;], [/* 31 vars */]) = 0</p>
<p>你 已经看到了，strace不仅可以被程序员使用，普通系统管理员和用户也可以使用strace来调试系统错误。必须承认，strace的输出不总是容易理 解，但是很多输出对大多数人来说是不重要的。你会慢慢学会从大量输出中找到你可能需要的信息，像权限错误，文件未找到之类的，那时strace就会成为一 个有力的工具了。</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=101</wfw:commentRss>
		</item>
		<item>
		<title>在 Web 浏览在 IIS 中许多应用程序池单独标识下运行时客户端收到可用 &#8221; 服务 &#8221; 错误信息</title>
		<link>http://frsky.net/?p=100</link>
		<comments>http://frsky.net/?p=100#comments</comments>
		<pubDate>Fri, 26 Dec 2008 02:40:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=100</guid>
		<description><![CDATA[运行 Microsoft Internet Information Services (IIS), 不同自定义标识下多个应用程序池时某些辅助进程不初始化正确。 出现此问题时, 可能会收到可用 &#8221; 服务 &#8221; 客户这些应用程序池宿主页面， 当他们尝试访问 Web 错误信息。 此外, 系统日志中可能记录以下警告消息：
事件类型： 警告
事件源： W3SVC
事件类别: 无
事件 ID 1009：
说明：
处理应用程序池 &#8216; poolname &#8216; 进程意外终止。 进程 ID 是 processid &#8216; &#8216;。 进程退出代码为 0 x 80 &#8216; &#8216;。
当您使用三个预定义标识不会发生此问题。 预定义标识是 NetworkService、 本地服务, 和本地系统。
注意 在同时 32 - 位版本的 IIS 和 64 - 位版本的 IIS 发生此问题。
通过从配置桌面堆分配内存一起使用， IIS [...]]]></description>
			<content:encoded><![CDATA[<p>运行 Microsoft Internet Information Services (IIS), 不同自定义标识下多个应用程序池时某些辅助进程不初始化正确。 出现此问题时, 可能会收到可用 &#8221; 服务 &#8221; 客户这些应用程序池宿主页面， 当他们尝试访问 Web 错误信息。 此外, 系统日志中可能记录以下警告消息：</p>
<p class="indent">事件类型： 警告<br />
事件源： W3SVC<br />
事件类别: 无<br />
事件 ID 1009：<br />
说明：<br />
处理应用程序池 &#8216; poolname &#8216; 进程意外终止。 进程 ID 是 processid &#8216; &#8216;。 进程退出代码为 0 x 80 &#8216; &#8216;。</p>
<p>当您使用三个预定义标识不会发生此问题。 预定义标识是 NetworkService、 本地服务, 和本地系统。</p>
<p><strong>注意 </strong>在同时 32 - 位版本的 IIS 和 64 - 位版本的 IIS 发生此问题。</p>
<p>通过从配置桌面堆分配内存一起使用， IIS 使用独立标识, 创建每个辅助进程系统创建一个新桌面对象。 出现此问题原因, 该堆已用尽时 IIS 无法创建多辅助进程是。 然后可用 &#8221; 服务 &#8221; 客户端接收这些应用程序池宿主站点， 其Web 当他们尝试访问 Web 浏览器中错误消息。</p>
<p><strong>警告 </strong>如果正确修改注册表通过注册表编辑器或通过其他方法可能发生 Serious 问题。 这些问题可能需要重新安装操作系统。 Microsoft 不能保证能够解决这些问题而。 修改注册表需要您自担风险。</p>
<p>要解决此问题, 添加 UseSharedWPDesktop 注册表项， 是运行 IIS 的计算机。 此注册表项允许所有要在一个共享桌面, 不管其辅助进程标识运行辅助进程。</p>
<p>要添加 UseSharedWPDesktop 注册表项：</p>
<ol>
<li>单击 开始 ， 单击 运行 , 类型 <span class="userInput">regedit</span> 然后单击 确定 。</li>
<li>找到以下注册表项：
<p class="indent">HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\W3SVC</p>
</li>
<li>右键单击 Parameters ， 指向 新建 , 然后单击 DWORD 值 。</li>
<li>类型 <span class="userInput">UseSharedWPDesktop</span>.</li>
<li>将对此新项值设置为 1。</li>
<li>退出注册表编辑器, 并重新启动 IIS。</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=100</wfw:commentRss>
		</item>
		<item>
		<title>路由器初始设置参数及命令配置</title>
		<link>http://frsky.net/?p=99</link>
		<comments>http://frsky.net/?p=99#comments</comments>
		<pubDate>Thu, 04 Dec 2008 08:39:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=99</guid>
		<description><![CDATA[路由器初始设置参数及命令配置
当路由器进行初始化时，路由器进行以下操作：
　　
　　1)自ROM执行上电自检，检测CPU,内存、接口电路的基本操作。
　　
　　2)自ROM进行引导，将操作系统装下载到主存。
　　
　　3)引导操作系统由配置寄存器的引导预确定由FLASH 或网络下载，则配置文件的
　　
　　boot system 命令确定其确切位置。
　　
　　4)操作系统下载到低地址内存，下载后由操作系统确定路由器的工作硬件和软件
　　
　　部分并在屏幕上显示其结果。
　　
　　5)NVRAM中存储的配置文件装载到主内存并通过执行，配置启动路由进程，提供接
　　
　　口地址、设置介质特性。如果NVRAM中设有有效的配置文件，则进入Setup 会话模
　　
　　式。
　　
　　6)然后进入系统配置会话，显示配置信息，如每个接口的配置信息。
　　二、Setup会话
　　
　　当NVRAM里没有有效的配置文件时，路由器会自动进入Setup会话模式。以后也可
　　
　　在命令行敲入Setup进行配置。
　　
　　Setup 命令是一个交互方式的命令，每一个提问都有一个缺省配置，如果用缺省
　　
　　配置则敲回车即可。如果系统已经配置过，则显示目前的配置值。如果是第一次
　　
　　配置，则显示出厂设置。当屏幕显示 &#8220;&#8212;&#8212; More &#8212;&#8212;&#8221;,键入空格键继续；
　　
　　若从Setup 中退出，只要键入Ctrl-C即可。
　　1、Setup主要参数：
　　
　　配置它的一般参数，包括：
　　
　　主机名 ：hostname
　　
　　特权口令 ：enable password
　　
　　虚终端口令 ：virtual terminal password
　　
　　SNMP网管 ：SNMP Network Management
　　
　　IP ：IP
　　
　　IGRP路由协议：IGRP Routing
　　
　　RIP路由协议 ：RIP Routing
　　
　　DECnet : DECnet . 等
　　其中 Console 的secret、 password的设置：
　　
　　enable secret
　　
　　enable password
　　
　　Virtual Terminor 的password的设置：
　　
　　Line vty
　　
　　Password
　　
　　Host name的设置：
　　
　　Hostname
　　2、Setup接口参数：
　　
　　设置接口参数，如以太网口、TokenRing口、同步口、异步口等。包括IP地址、子
　　
　　网屏蔽、TokengRing速率等。
　　3、Setup描述：
　　
　　在设置完以上参数后，该命令提示是否要用以上的配置，如果回答是&#8221;YES&#8221;则系统
　　
　　会存储以上的配置参数，系统就可以使用了。
　　4、 Setup相关命令：
　　
　　Show config
　　
　　write memory
　　
　　write erase
　　
　　reload
　　
　　setup
　　5、路由器丢失PASSWORD的恢复
　　
　　以下办法可以恢复：
　　
　　enable secret password (适合10。3（2）或更新的版本)
　　
　　enable password
　　
　　console password
　　
　　通过修改Configuration Register(出厂为0&#215;2102)，使路由器忽略PASSWORD，这
　　
　　样就可以进入路由器，就可以看到enable password和Console password，但ena
　　
　　ble secret password以被加密，只能替换。可以进入的configuration Registe
　　
　　r值为0&#215;142.
　　· 运行password恢复可能会使系统DOWN掉一个半小时；
　　
　　· 将Console terinal连在路由器的Console口上，确认终端设置为9600bps、8
　　
　　Data bit [...]]]></description>
			<content:encoded><![CDATA[<p>路由器初始设置参数及命令配置<br />
当路由器进行初始化时，路由器进行以下操作：<br />
　　<br />
　　1)自ROM执行上电自检，检测CPU,内存、接口电路的基本操作。<br />
　　<br />
　　2)自ROM进行引导，将操作系统装下载到主存。<br />
　　<br />
　　3)引导操作系统由配置寄存器的引导预确定由FLASH 或网络下载，则配置文件的<br />
　　<br />
　　boot system 命令确定其确切位置。<br />
　　<br />
　　4)操作系统下载到低地址内存，下载后由操作系统确定路由器的工作硬件和软件<br />
　　<br />
　　部分并在屏幕上显示其结果。<br />
　　<br />
　　5)NVRAM中存储的配置文件装载到主内存并通过执行，配置启动路由进程，提供接<br />
　　<br />
　　口地址、设置介质特性。如果NVRAM中设有有效的配置文件，则进入Setup 会话模<br />
　　<br />
　　式。<br />
　　<br />
　　6)然后进入系统配置会话，显示配置信息，如每个接口的配置信息。</p>
<p>　　二、Setup会话<br />
　　<br />
　　当NVRAM里没有有效的配置文件时，路由器会自动进入Setup会话模式。以后也可<br />
　　<br />
　　在命令行敲入Setup进行配置。<br />
　　<br />
　　Setup 命令是一个交互方式的命令，每一个提问都有一个缺省配置，如果用缺省<br />
　　<br />
　　配置则敲回车即可。如果系统已经配置过，则显示目前的配置值。如果是第一次<br />
　　<br />
　　配置，则显示出厂设置。当屏幕显示 &#8220;&#8212;&#8212; More &#8212;&#8212;&#8221;,键入空格键继续；<br />
　　<br />
　　若从Setup 中退出，只要键入Ctrl-C即可。</p>
<p>　　1、Setup主要参数：<br />
　　<br />
　　配置它的一般参数，包括：<br />
　　<br />
　　主机名 ：hostname<br />
　　<br />
　　特权口令 ：enable password<br />
　　<br />
　　虚终端口令 ：virtual terminal password<br />
　　<br />
　　SNMP网管 ：SNMP Network Management<br />
　　<br />
　　IP ：IP<br />
　　<br />
　　IGRP路由协议：IGRP Routing<br />
　　<br />
　　RIP路由协议 ：RIP Routing<br />
　　<br />
　　DECnet : DECnet . 等</p>
<p>　　其中 Console 的secret、 password的设置：<br />
　　<br />
　　enable secret<br />
　　<br />
　　enable password<br />
　　<br />
　　Virtual Terminor 的password的设置：<br />
　　<br />
　　Line vty<br />
　　<br />
　　Password<br />
　　<br />
　　Host name的设置：<br />
　　<br />
　　Hostname</p>
<p>　　2、Setup接口参数：<br />
　　<br />
　　设置接口参数，如以太网口、TokenRing口、同步口、异步口等。包括IP地址、子<br />
　　<br />
　　网屏蔽、TokengRing速率等。</p>
<p>　　3、Setup描述：<br />
　　<br />
　　在设置完以上参数后，该命令提示是否要用以上的配置，如果回答是&#8221;YES&#8221;则系统<br />
　　<br />
　　会存储以上的配置参数，系统就可以使用了。</p>
<p>　　4、 Setup相关命令：<br />
　　<br />
　　Show config<br />
　　<br />
　　write memory<br />
　　<br />
　　write erase<br />
　　<br />
　　reload<br />
　　<br />
　　setup</p>
<p>　　5、路由器丢失PASSWORD的恢复<br />
　　<br />
　　以下办法可以恢复：<br />
　　<br />
　　enable secret password (适合10。3（2）或更新的版本)<br />
　　<br />
　　enable password<br />
　　<br />
　　console password<br />
　　<br />
　　通过修改Configuration Register(出厂为0&#215;2102)，使路由器忽略PASSWORD，这<br />
　　<br />
　　样就可以进入路由器，就可以看到enable password和Console password，但ena<br />
　　<br />
　　ble secret password以被加密，只能替换。可以进入的configuration Registe<br />
　　<br />
　　r值为0&#215;142.</p>
<p>　　· 运行password恢复可能会使系统DOWN掉一个半小时；<br />
　　<br />
　　· 将Console terinal连在路由器的Console口上，确认终端设置为9600bps、8<br />
　　<br />
　　Data bit 、No parity、1 stop bit;<br />
　　<br />
　　· show version显示Configuration Register 0&#215;2102；<br />
　　<br />
　　· 关机再开，按&#8221;Ctrl+ Break&#8221;,进入ROM MONITOR状态，提示符为&#8221;&gt;&#8221;；<br />
　　<br />
　　· 键入&#8221;&gt; o/r 0&#215;142&#8243;，修改 Configuration Register到0&#215;142,可以忽略原先的<br />
　　<br />
　　password；<br />
　　<br />
　　· 键入&#8221;&gt; initialize&#8221;,初始化路由器，等一段时间后，路由器会出现以下提示<br />
　　<br />
　　：<br />
　　<br />
　　&#8221;system configuration Diaglog ……&#8221;<br />
　　<br />
　　Enter &#8220;NO&#8221;<br />
　　<br />
　　提示&#8221;Press RETURN to get started!&#8221; ,Press &#8220;Enter&#8221;</p>
<p>　　· 进入特权模式<br />
　　<br />
　　Router&gt;enable<br />
　　<br />
　　Router#show startup-config<br />
　　<br />
　　这样就可以得到password(enable&amp;console password)<br />
　　<br />
　　· 修改password<br />
　　<br />
　　&#8221;Router#config ter&#8221;<br />
　　<br />
　　&#8221;Router(config)# enable secret cisco&#8221;<br />
　　<br />
　　&#8221;Router(config)# enable password cisco1&#8243;<br />
　　<br />
　　&#8221;Router(config)# line con 0&#8243;<br />
　　<br />
　　&#8221;Router(config)# password cisco&#8221;<br />
　　<br />
　　&#8221;Router(config)# config-register 0&#215;2102&#8243;<br />
　　<br />
　　&#8221;ctrl + Z&#8221;<br />
　　<br />
　　&#8221;Router#copy running-config startup-config&#8221;<br />
　　<br />
　　&#8221;reload&#8221;<br />
　　<br />
　　· 以password cisco进入特权用户。<br />
　三、路由器配置<br />
　　<br />
　　1)路由器模式<br />
　　<br />
　　在Cisco 路由器中，命令解释器称为EXEC，EXEC解释用户键入的命令并执行相应<br />
　　<br />
　　的操作，在输入EXEC命令前必须先登录到路由器上。基于安全原因，EXEC设置了<br />
　　<br />
　　两个访问权限：用户级和特权级，用户级可执执行的命令是特权级命令的子集。<br />
　　<br />
　　在特权级，可以使用：configuration，interface，subinterface，line，rout<br />
　　<br />
　　er，router-map等命令。</p>
<p>　　2)配置模式<br />
　　<br />
　　使用Config命令可进入配置模式，进入该模式后，EXEC提示用户可用的配置方式<br />
　　<br />
　　如终端、NVRAM、网络三种，缺省是终端方式。</p>
<p>　　3)IP路由协议模式<br />
　　<br />
　　在配置模式下输入Router命令，可进入IP路由协议模式，可选的路由协议一般有<br />
　　<br />
　　：bgp、egp、igrp、eigrp、rip等动态路由和静态路由。</p>
<p>　　4)接口配置模式<br />
　　<br />
　　在每一个端口上可以设置很多特性，接口配置命令修改以太网、令牌环网、FDDI<br />
　　<br />
　　或同步、异步口等操作。</p>
<p>　　5)口令配置<br />
　　<br />
　　可以采用口令来限制对路由器的访问，口令可以设定到具体的线路上或是特权Ｅ<br />
　　<br />
　　ＸＥＣ模式。<br />
　　<br />
　　Line console 0 命令设置控制台终端口令<br />
　　<br />
　　Line vty 0 命令设置Telnet虚终端口令<br />
　　<br />
　　Enable-password 命令设置特权EXEC访问权限</p>
<p>　　6)路由器命名<br />
　　<br />
　　在配置模式下用hostname，如：<br />
　　<br />
　　hostname RouterA</p>
<p>　　四、用户帮助提示<br />
　　<br />
　　1、在用户提示符下键入？可以列出常用命令，通常有以下命令：<br />
　　<br />
　　connect 打开一个中端连接<br />
　　<br />
　　disconnect 关闭一个已有的telnet会话<br />
　　<br />
　　enable 进入特权级<br />
　　<br />
　　exit 退出EXEC<br />
　　<br />
　　help 交互求助系统描述<br />
　　<br />
　　lock 终端锁定<br />
　　<br />
　　login 以特定用户登录<br />
　　<br />
　　logout 退出EXEC<br />
　　<br />
　　ping 发送echo信息<br />
　　<br />
　　resume 恢复一个激活的telnet连接<br />
　　<br />
　　show 显示正在运行的系统信息<br />
　　<br />
　　systat 显示正在运行的系统信息<br />
　　<br />
　　telnet 打开一个telnet连接<br />
　　<br />
　　terminal 设置终端线路参数<br />
　　<br />
　　where 列出激活的telnet连接<br />
　　<br />
　　2、上下相关帮助<br />
　　<br />
　　上下相关帮助包括：<br />
　　<br />
　　符号转换 ：键入命令有错时提示；<br />
　　<br />
　　关键字完成 ：键入命令字的一部分即可；<br />
　　<br />
　　命令记忆 ：可用&#8221; &#8220;调出以前的命令；<br />
　　<br />
　　命令提示 ：当命令记不完全时，可用&#8221;？&#8221;替代</p>
<p><u></u></p>
<p><u><font color="#810081"></p>
<p class="posttitle"><a href="http://www.cnweblog.com/vcbird/archive/2007/11/05/260371.html" id="viewpost1_TitleUrl" class="singleposttitle"><font color="#333333">路由器中config-register各位的含义以及配合TFTP服务的应用</font></a></p>
<p><span style="color: #008000">config-register共16位，以4位16进制数表示 </span></p>
<p><span style="color: #008000">格式：0xABCD<br />
赋值范围从0&#215;0到0xFFFF </span></p>
<p><span style="color: #008000">0&#215;2102 ：标准默认值<br />
0&#215;2142 ：从FLASH中启动，但不使用NVRAM中的配置文件（用于口令恢复）<br />
0&#215;2101 ：从Boot RAM中启动，应用于更新系统文件<br />
0&#215;2141 ：从Boot RAM中启动，但不使用NVRAM中的配置文件<br />
其中C位的第三位为1时表示关闭Break键，反之表示打开Break键。<br />
0&#215;141：表示关闭Break键，不使用NVRAM中的配置文件，并且从系统默认的ROM中<br />
的系统中启动。<br />
0&#215;0040：表示允许路由器读取NVRAM中的配置文件。 </span></p>
<p><span style="color: #008000">表1：config-register中各位的含义</span></p>
<p><span style="color: #008000">位  十六进制值 含义<br />
00-03  0&#215;0000-0&#215;000F  启动位 <br />
05  0&#215;0020  使用扩展的console速率，19200bps以上<br />
06  0&#215;0040  使得系统软件忽略NVRAM中的内容<br />
07  0&#215;0080  OEM位开启<br />
08  0&#215;0100  Break键关闭 <br />
10  0&#215;0400  IP广播到所有域 <br />
11-12  0&#215;0800-0&#215;1000  Console口速率<br />
13  0&#215;2000  如果网络启动失败，默认从ROM中启动 <br />
14  0&#215;4000  不包含网络号的IP广播<br />
15  0&#215;8000  启动诊断信息同时忽略NVRAM内容</p>
<p><strong>===============================================<br />
以下是config-register和TFTP服务的联合应用：<br />
</strong></span><span style="color: #008000">  笔者有一台2501路由器的IOS是坏的(cisocB)，另外一台2501路由器IOS是好的(ciscoA)，好的<br />
IOS在我的PC上面己经没有了，但是通过在PC上面做一个TFTP，把好的传到PC上面，再传<br />
到坏的上面就太浪费时间了。后来想到一个办法，直接把好的路由器配置成TFTP服务器。<br />
我的连接方式是两台路由器是通过E0口连接的，我先是在好的路由器上面(cisocA )把E0口配<br />
置好IP是192.168.10.90(IP地址随便配置，只要两个E0口都能互相PING通就行)再到配置模式下<br />
面输入 tftp-server c2500-js-l.122-7a.bin(这是你好的IOS里面的IOS文件名，用show version 来查<br />
看你的IOS文件名</p>
<p>这台A己经配置好了以后，再到B这台来配置，首先让这台启动到BOOT模式，在全局配置模<br />
式下面输入config-register 0&#215;2101 再重启路由器，启动到BOOT模式以后，同样配置你的E口，<br />
到了BOOT模式以后，输入copy tftp flash ，提示你输入TFTP服务器，再输入文件名，就可以<br />
了，具体操作步骤如下:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
cisocA#conf t<br />
cisocA(config)#tftp-server c2500-js-l.122-7a.bin<br />
cisocA(config)#int e0<br />
cisocA(config-if)#ip add 192.168.10.90 255.255.255.0<br />
cisocA(config-if)#no shut<br />
ciscoB(config)#conf t<br />
ciscoB(config)#config-register 0&#215;2101<br />
ciscoB(config)#end<br />
ciscoB#reload<br />
System configuration has been modified. Save? [yes/no]: y<br />
ciscoB(boot)&gt;enable<br />
ciscoB(boot)#conf terminal<br />
ciscoB(boot)(config)#int e0<br />
ciscoB(boot)(config-if)#ip add 192.168.10.80 255.255.255.0<br />
ciscoB(boot)(config-if)#no shut<br />
ciscoB(boot)(config-if)#end<br />
ciscoB(boot)#erase flash<br />
System flash directory:<br />
File Length Name/status<br />
1 15533612 c2500-js-l.122-7a.bin<br />
[15533676 bytes used, 1243540 available, 16777216 total]<br />
Erase flash device? [confirm]<br />
Are you sure? [yes/no]: y<br />
Address or name of remote host [192.168.10.80]? 192.168.10.90<br />
Source file name? c2500-js-l.122-7a.bin<br />
Destination file name [c2500-js-l.122-7a.bin]?<br />
Erase flash device before writing? [confirm](回车)<br />
Copy &#8216;c2500-js-l.122-7a.bin&#8217; from server<br />
as &#8216;c2500-js-l.122-7a.bin&#8217; into Flash WITH erase? [yes/no]y<br />
输入Y以后，程序就自动COPY IOS，等成功以后，你再如下配置<br />
ciscoB(config)#config-register 0&#215;2102<br />
ciscoB(config)#reload<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p></span></font></u><a href="http://www.xker.com/page/e2007/0911/33979.html"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=99</wfw:commentRss>
		</item>
		<item>
		<title>基础入门：Cisco配置手记</title>
		<link>http://frsky.net/?p=98</link>
		<comments>http://frsky.net/?p=98#comments</comments>
		<pubDate>Thu, 04 Dec 2008 03:37:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=98</guid>
		<description><![CDATA[现有设备：CISCO路由器2620XM（4台）和2621XM（5台），3750三层交换机，PIX-515E防火墙，CISCO2950二层交换机（9台）
重点命令：有安全，控制，监控，监测和检测功能的命令集合和命令组合
一、两层交换机

1、基本配置
（1）设置VLAN1的IP地址，掩码：
配置：
sw itch#config terminal
(config)#interface vlan1    ！进入到要配置IP的接口
(config-if)#ip address 10.1.10.253(ip)  255.255.255.0(mask)  ！设置参数
验证：
(config-if)#exit
switch#show interface vlan1
保存设置：
switch#copy running-config startup-config
（2）划分VLAN
配置：
switch#vlan database(还有一种方法)   ！创建一个VLAN
switch#vlan 2
switch#exit
switch#config terminal
one port:
(config)#interface fastethernet0/0      ！进入到要被划分的端口
(config-if)#switchport access vlan 2    ！划分到一个VLAN
multiports:
(config)#interface range fastethernet0/0 -7  ！进入到要被集体划分的端口
(config-if)#switchport access vlan 2     ！划分到一个VLAN
验证：
switch#show vlan
保存：
switch#copy running-config startup-config
（3）设置trunk
配置：
switch#config terminal
(config)#interface gigabitethernet0/1  ！进入要配置成干道的接口
(config-if)#switchport mode trunk    ！设置成干道
验证：
switch#show interface trunk
保存：
switch#copy running-config startup-config
（4）连接路由器
如果交换机上有多个VLAN，则所连的路由器接口就必须有多个IP地址。要用子接口设置多IP地址。连接到路由器上的接口要被设置成trunk，并且要封装干道协议：ISL，或者802.1Q。
配置交换机：
switch#config terminal
(config)#interface gigabitethernet0/1
(config-if)#switchport mode trunk  !配置成干道，将自动封装802.1q协议
配置路由器：
router#config terminal
(config)#interface fastethernet0/0.2   ！进入子接口2
(config-subif)#encapsulation dot1q 2   [...]]]></description>
			<content:encoded><![CDATA[<p>现有设备：CISCO<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a>2620XM（4台）和2621XM（5台），3750三层交换机，PIX-515E防火墙，CISCO2950二层交换机（9台）<br />
重点命令：有安全，控制，监控，监测和检测功能的命令集合和命令组合</p>
<p><strong>一、两层交换机<br />
</strong><br />
<strong>1、基本配置<br />
（1）设置VLAN1的IP地址，掩码：</strong><br />
配置：<br />
sw<script src="/CMS/JS/newsad.js" language="javascript"></script> itch#config terminal<br />
(config)#interface vlan1    ！进入到要配置IP的接口<br />
(config-if)#ip address 10.1.10.253(ip)  255.255.255.0(mask)  ！设置参数<br />
验证：<br />
(config-if)#exit<br />
switch#show interface vlan1<br />
保存设置：<br />
switch#copy running-config startup-config</p>
<p><strong>（2）划分VLAN</strong><br />
配置：<br />
switch#vlan database(还有一种方法)   ！创建一个VLAN<br />
switch#vlan 2<br />
switch#exit<br />
switch#config terminal<br />
one port:<br />
(config)#interface fastethernet0/0      ！进入到要被划分的端口<br />
(config-if)#switchport access vlan 2    ！划分到一个VLAN<br />
multiports:<br />
(config)#interface range fastethernet0/0 -7  ！进入到要被集体划分的端口<br />
(config-if)#switchport access vlan 2     ！划分到一个VLAN<br />
验证：<br />
switch#show vlan<br />
保存：<br />
switch#copy running-config startup-config</p>
<p><strong>（3）设置trunk</strong><br />
配置：<br />
switch#config terminal<br />
(config)#interface gigabitethernet0/1  ！进入要配置成干道的接口<br />
(config-if)#switchport mode trunk    ！设置成干道<br />
验证：<br />
switch#show interface trunk<br />
保存：<br />
switch#copy running-config startup-config</p>
<p><strong>（4）连接<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a></strong><br />
如果交换机上有多个VLAN，则所连的<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a>接口就必须有多个IP地址。要用子接口设置多IP地址。连接到<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a>上的接口要被设置成trunk，并且要封装干道协议：ISL，或者802.1Q。<br />
配置交换机：<br />
switch#config terminal<br />
(config)#interface gigabitethernet0/1<br />
(config-if)#switchport mode trunk  !配置成干道，将自动封装802.1q协议<br />
配置<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a>：<br />
router#config terminal<br />
(config)#interface fastethernet0/0.2   ！进入子接口2<br />
(config-subif)#encapsulation dot1q 2   ！子接口对应VLAN2，并封装dot1q协议<br />
(config-subif)#ip address 10.1.20.1  255.255.255.0  !配置了10.1.20.0/24网段的网关<br />
确认：<br />
router#show interface fastethernet0/0<br />
不同VLAN下的主机可以相互ping通，则配置成功。<br />
保存配置</p>
<p><strong>（5）连接交换机</strong><br />
同种类型的网络设备相连要使用交叉线。交换机使用交叉线相连后，将会自动将两端设置成干道。</p>
<p><strong>2、VTP（VLAN Trunk Protocol）</strong><br />
（1） 作用：<br />
允许用户集中管理网络中交换机的配。VTP是一种消息协议，可以对整个网络内的VLAN的添加、删除和重命名操作进行管理，以此维护VLAN配置的一致性。<br />
（2） 工作方式<br />
确定一条交换机为VTP服务器。<br />
可以在服务器上更改VLAN的配置，并把该配置传播到网络中的所有VTP客户机。<br />
当交换机配置成VTP客户机之后，就不能物理地改变该交换机的VLAN配置。<br />
唯一可以更改VLAN配置的方法是当且仅当VTP客户端交换机接收到来自其VTP服务器的VTP更新信息时，才能更改。<br />
多台VTP服务器管理不同的VTP客户机，必须指定一个VTP域。服务器和客户机在各自的域内。</p>
<p><strong>二、<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a><br />
1、基本配置</strong><br />
（1）以太网口配置<br />
注：<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a>以太网口直接接主机用交叉线。<br />
（2）串口配置<br />
（3）配置静态路由<br />
（4）配置动态路由协议<br />
（5）配置访问控制列表（ACL）**<br />
（6）<a href="http://www.souzz.net/Cisco/"><u>路由器</u></a>互联</p>
<p><strong>2、问题</strong><br />
（1）无法配置静态路由，出现“Default gateway is not set ….. ICMP redirect cache is empty”<br />
原因：IP路由被禁用<br />
解决：(config)#ip routing</p>
<p>（2）与其他设备的接口状态上，”protocol  down”<br />
可能的原因：双绞线的接线类型不对<br />
解决：换成直通线或者交叉线。</p>
<p><strong>三、三层交换机</strong><br />
<strong>1、基本配置<br />
</strong><br />
（1）配置IP<br />
手工配置：<br />
(config)#interface vlan vlan-id<br />
(config-if)#ip address ip-address subnet-mask<br />
(config-if)#exit<br />
(config)#ip default-gateway ip-address<br />
确认配置：<br />
#show interface vlan vlan-id<br />
#show ip redirects  ！确认默认网关配置<br />
保存：＃copy running-config startup-config<br />
使用DHCP配置</p>
<p>（2）使不同VLAN互联<br />
 </p>
<p>（3）配置某个端口为trunk<br />
(config)#interface fastethernet1/0/23<br />
(config-if)#switchport encapsultion dot1q<br />
(config-if)#switchport mode trunk</p>
<p>（4）默认路由及路由协议的设定<br />
问题<br />
（1）多个子网连接到三层交换机，交换机上设定了每个子网对应的网关地址，交换机通过router连接到其他的网络或者区域。三层switch和router上相同网段的地址无法相互ping 通。如：3750上有192.168.8.254（VLAN1），192.168.16.254（VLAN2），192.168.24.254（VLAN3）；router上有192.168.8.1，192.168.16.1，192.168.24.1。<br />
    现象：192.168.8.254 可以ping通192.168.8.1，但是.16.和.24.网段的无法ping通。<br />
    原因：router接到switch上的接口没有设置成trunk。</p>
<p><strong>四、防火墙<br />
</strong>CISCO PIX系列属于状态检测防火墙。<br />
Note:ASA(Adaptive Security Algorithm) allows one way (inside to outside) connections without an explicit configuration in memory.</p>
<p><strong>1、特点</strong><br />
<strong>（1）自适应安全算法（ASA）</strong><br />
创建状态会话流表（state table）。各种连接信息都被记录进表中。<br />
ASA是一个有状态、面向连接的过程，它在状态表中维持会话信息，应用对状态表的安全策略来控制通过防火墙的所有流量。<br />
连接状态包括：源/目的IP，源/目的端口，TCP顺序信息，附加的TCP/UDP标记。应用一个随机产生的TCP顺序号。总称为“会话对象”。</p>
<p>内部不主动发出数据，要求响应，外部的数据就无法进入内部了吗。<br />
PIX中ASA和状态过滤的工作机制：<br />
a、 内部主机开始一个对外部资源的连接<br />
b、 PIX在状态表中写入一个会话（连接）对象<br />
c、 会话对象同安全策略相比较。如果连接不被允许，此会话对象被删除，并且连接被取消<br />
h、 如果安全策略认可这个连接，此连接继续向外部资源发送<br />
j、 外部资源响应这个请求<br />
k、 响应信息到达防火墙，与会话对象比较。匹配则响应信息被发送到内部主机，不匹配则连接就会被取消。</p>
<p><strong> （2）贯穿式代理</strong><br />
认证和授权一个防火墙上输入/输出的连接。<br />
它在应用层完成用户认证，依照安全策略检验授权。当安全策略授权时打开这个连接。这个连接后面的流量不再在应用层处理，而是进行状态检测。</p>
<p><strong>（3）冗余<br />
</strong><br />
<strong>2、基本配置<br />
</strong><br />
配置完基本参数后，发现从PIX上可以ping通内网和外网的地址。但是内外网的主机无法相互ping通。内网主机无法ping通PIX外口。但是，内网主机可以访问外网的服务器。（可能原因：PIX默认关闭ICMP响应？？）</p>
<p>基本配置命令：interface , nameif , ip address , nat , global , route<br />
<strong>（1）激活以太端口</strong><br />
firewell#config terminal<br />
(config)#interface ethernet0 auto<br />
(config)#interface ethernet1 auto    !外口必须用命令激活</p>
<p><strong>（2）命名端口和安全级别</strong><br />
(config)#nameif  ethernet1  inside  security0<br />
(config)#nameif  ethernet0  outside  security100</p>
<p><strong>（3）配置内外口</strong><br />
firewell#config terminal<br />
(config)#ip address inside 192.168.1.1 255.255.255.0<br />
(config)#ip address outside 222.20.16.1 255.255.255.0</p>
<p><strong>（4）配置NAT和PAT</strong><br />
(config)#nat (inside) 1 0 0   !所有的内口地址都<br />
(config)#nat (inside) 2 192.168.8.0 255.255.255.0   <br />
(config)#global (outside) 2 10.1.30.150-10.1.30.160 netmask 255.255.0.0<br />
测试配置：<br />
  ping<br />
  debug</p>
<p><strong>（5）DMZ的访问</strong></p>
<p><strong>（6）转换表的操作</strong><br />
show  xlate    显示转换表的信息<br />
clear  xlate     每次重建转换表要运行，以清除原有的转换槽，否则原信息将在超时（3小时）后才被丢弃<br />
show conn    查找连接故障，为选择的特定选项显示所有活动的TCP连接的数量和状态<br />
可以更改转换表的操作：<br />
nat ，global ，static ，route，alias，conduit</p>
<p><strong>（7）配置网络时间协议（NTP）</strong><br />
 NTP server与PIX的关系</p>
<p><strong>（8）访问配置<br />
</strong>经由PIX的入站访问</p>
<p><strong>step1：静态网络地址转换</strong><br />
  静态网络地址转换，不节省已经分配的IP地址 <br />
static [( prenat_interface,postnat_interface)] {mapped_address | interface} real_address [dns] [netmask mask] [norandomseq] [ max_cons [em_limit]]<br />
   设定一个内部地址到一个外部地址的映射<br />
   (config)#static (inside,outside) 211.70.96.10 10.1.100.10 netmask 255.255.255.255<br />
   或者一个内部网络到一个外部网络的映射<br />
   (config)#static (inside,outside) 211.70.96.0 10.1.100.0 netmask 255.255.255.0<br />
   静态端口地址转换，不支持H.323或者多媒体应用流量<br />
   static [(internal_if_name,external_if_name)] {tcp|udp} {global_ip | interface} global local_ip local_port [netmask mask] [ max_cons [emb_limit [norandomseq]]]</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=98</wfw:commentRss>
		</item>
		<item>
		<title>■思科ASA和PIX防火墙配置手册 第一章</title>
		<link>http://frsky.net/?p=97</link>
		<comments>http://frsky.net/?p=97#comments</comments>
		<pubDate>Tue, 02 Dec 2008 05:34:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=97</guid>
		<description><![CDATA[■思科ASA和PIX防火墙配置手册 第一章
一、配置基础
1.1用户接口
思科防火墙支持下列用户配置方式：
Console，Telnet，SSH（1.x或者2.0，2.0为7.x新特性，PDM的http方式（7.x以后称为ASDM）和VMS的Firewall Management Center。
支持进入Rom Monitor模式，权限分为用户模式和特权模式，支持Help，History和命令输出的搜索和过滤。
注：Catalyst6500的FWSM没有物理接口接入，通过下面CLI命令进入：
Switch# session slot slot processor 1 （FWSM所在slot号）
用户模式：
Firewall&#62; 为用户模式，输入enable进入特权模式Firewall#。特权模式下可以进入配置模式，在6.x所有的配置都在一个全局模式下进行，7.x
以后改成和IOS类似的全局配置模式和相应的子模式。通过exit，ctrl-z退回上级模式。
配置特性：
在原有命令前加no可以取消该命令。Show running-config 或者 write terminal显示当前配置，7.x后可以对show run 的命令输出进行搜索和
过滤。Show running-config all显示所有配置，包含缺省配置。Tab可以用于命令补全，ctrl-l可以用于重新显示输入的命令（适用于还没有
输入完命令被系统输出打乱的情况），help和history相同于IOS命令集。
Show命令支持 begin，include，exclude，grep 加正则表达式的方式对输出进行过滤和搜索。
Terminal width 命令用于修改终端屏幕显示宽度，缺省为80个字符，pager命令用于修改终端显示屏幕显示行数，缺省为24行，pager lines 0
命令什麽效果可以自己试试。
1.2防火墙许可介绍
防火墙具有下列几种许可形式，通过使用show version命令可以看设备所支持的特性：
Unrestricted (UR) 所有的限制仅限于设备自身的性能，也支持Failover
Restricted (R) 防火墙的内存和允许使用的最多端口数有限制，不支持Failover
Failover (FO) 不能单独使用的防火墙，只能用于Failover
Failover-Active/Active (FO-AA) 只能和UR类型的防火墙一起使用，支持active/active failover
注：FWSM内置UR许可。
activation-key 命令用于升级设备的许可，该许可和设备的serial number有关（show version输出可以看到），6.x为16字节，7.x为20字节
。
1.3初始配置
跟路由器一样可以使用setup进行对话式的基本配置。
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
■思科ASA和PIX防火墙配置手册 第二章
二、 配置连接性
2.1配置接口
接口基础：
防火墙的接口都必须配置接口名称，接口IP地址和掩码（7.x开始支持IPv6）和安全等级。接口可以是物理接口也可以是逻辑接口（vlan），从6.3开始支持SPAN、trunk，但只支持802.1Q封装，不支持DTP协商。
接口基本配置：
注：对于FWSM所有的接口都为逻辑接口，名字也是vlan后面加上vlanid。例如FWSM位于6500的第三槽，配置三个接口，分别属于vlan
100,200,300.
Switch(config)# firewall vlan-group 1 100,200,300
Switch(config)# firewall module 3 vlan-group 1
Switch(config)# exit
Switch# session slot 3 processor [...]]]></description>
			<content:encoded><![CDATA[<p>■思科ASA和PIX防火墙配置手册 第一章<br />
一、配置基础<br />
1.1用户接口<br />
思科防火墙支持下列用户配置方式：<br />
Console，Telnet，SSH（1.x或者2.0，2.0为7.x新特性，PDM的http方式（7.x以后称为ASDM）和VMS的Firewall Management Center。<br />
支持进入Rom Monitor模式，权限分为用户模式和特权模式，支持Help，History和命令输出的搜索和过滤。<br />
注：Catalyst6500的FWSM没有物理接口接入，通过下面CLI命令进入：<br />
Switch# session slot slot processor 1 （FWSM所在slot号）<br />
用户模式：<br />
Firewall&gt; 为用户模式，输入enable进入特权模式Firewall#。特权模式下可以进入配置模式，在6.x所有的配置都在一个全局模式下进行，7.x<br />
以后改成和IOS类似的全局配置模式和相应的子模式。通过exit，ctrl-z退回上级模式。<br />
配置特性：<br />
在原有命令前加no可以取消该命令。Show running-config 或者 write terminal显示当前配置，7.x后可以对show run 的命令输出进行搜索和<br />
过滤。Show running-config all显示所有配置，包含缺省配置。Tab可以用于命令补全，ctrl-l可以用于重新显示输入的命令（适用于还没有<br />
输入完命令被系统输出打乱的情况），help和history相同于IOS命令集。<br />
Show命令支持 begin，include，exclude，grep 加正则表达式的方式对输出进行过滤和搜索。<br />
Terminal width 命令用于修改终端屏幕显示宽度，缺省为80个字符，pager命令用于修改终端显示屏幕显示行数，缺省为24行，pager lines 0<br />
命令什麽效果可以自己试试。<br />
1.2防火墙许可介绍<br />
防火墙具有下列几种许可形式，通过使用show version命令可以看设备所支持的特性：<br />
Unrestricted (UR) 所有的限制仅限于设备自身的性能，也支持Failover<br />
Restricted (R) 防火墙的内存和允许使用的最多端口数有限制，不支持Failover<br />
Failover (FO) 不能单独使用的防火墙，只能用于Failover<br />
Failover-Active/Active (FO-AA) 只能和UR类型的防火墙一起使用，支持active/active failover<br />
注：FWSM内置UR许可。<br />
activation-key 命令用于升级设备的许可，该许可和设备的serial number有关（show version输出可以看到），6.x为16字节，7.x为20字节<br />
。<br />
1.3初始配置<br />
跟路由器一样可以使用setup进行对话式的基本配置。<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第二章<br />
二、 配置连接性<br />
2.1配置接口<br />
接口基础：<br />
防火墙的接口都必须配置接口名称，接口IP地址和掩码（7.x开始支持IPv6）和安全等级。接口可以是物理接口也可以是逻辑接口（vlan），从6.3开始支持SPAN、trunk，但只支持802.1Q封装，不支持DTP协商。<br />
接口基本配置：<br />
注：对于FWSM所有的接口都为逻辑接口，名字也是vlan后面加上vlanid。例如FWSM位于6500的第三槽，配置三个接口，分别属于vlan<br />
100,200,300.<br />
Switch(config)# firewall vlan-group 1 100,200,300<br />
Switch(config)# firewall module 3 vlan-group 1<br />
Switch(config)# exit<br />
Switch# session slot 3 processor 1<br />
经过此配置后形成三个端口vlan100,vlan200,vlan300<br />
PIX 6.x<br />
Firewall(config)# interface hardware-id [hardware-speed] [shutdown] （Hardware-id可以用show version命令看到）<br />
PIX 7.x<br />
Firewall(config)# interface hardware-id<br />
Firewall(config-if)# speed {auto | 10 | 100 | nonegotiate}<br />
Firewall(config-if)# duplex {auto | full | half}<br />
Firewall(config-if)# [no] shutdown<br />
命名接口<br />
FWSM 2.x<br />
Firewall(config)# nameif vlan-id if_name securitylevel<br />
PIX 6.x<br />
Firewall(config)# nameif {hardware-id | vlan-id} if_name securitylevel<br />
PIX 7.x<br />
Firewall(config)# interface hardware_id[.subinterface]<br />
Firewall(config-if)# nameif if_name<br />
Firewall(config-if)# security-level level<br />
注：Pix 7.x和FWSM 2.x开始支持不同接口有相同的security level，前提是全局配置模式下使用same-security-traffic permit<br />
inter-interface命令。<br />
配置IP地址<br />
静态地址：Firewall(config)# ip address if_name ip_address [netmask]<br />
动态地址：Firewall(config)# ip address outside dhcp [setroute] [retry retry_cnt]<br />
注：setroute参数可以同时获得来自DHCP服务器的缺省路由，再次输入此命令可以renew地址。<br />
PPPOE：Firewall(config)# vpdn username JohnDoe password JDsecret<br />
Firewall(config)# vpdn group ISP1 localname JohnDoe<br />
Firewall(config)# vpdn group ISP1 ppp authentication chap<br />
Firewall(config)# vpdn group ISP1 request dialout pppoe<br />
Firewall(config)# ip address outside pppoe setroute<br />
验证接口<br />
Firewall# show ip<br />
IPv6地址配置（7.x新特性）<br />
暂略<br />
ARP配置<br />
配置一个静态的ARP条目：Firewall(config)# arp if_name ip_address mac_address [alias]<br />
配置timeout时间：Firewall(config)# arp timeout seconds 缺省为4小时<br />
注：一般情况下使用clear arp会清除所有的ARP缓存，不能针对单个的条目，但是可以通过以下变通方法：配置一个静态的条目，映射有问题<br />
的ip为一个假的mac地址，然后no掉该命令就会重新建立一个arp条目。<br />
MTU和分段<br />
配置MTU：Firewall(config)# mtu if_name bytes 使用show mtu (6.3) 或者show running-config mtu (7.x)来验证<br />
分段（fragment）的几个命令：限制等待重组的分段数Firewall(config)# fragment size database-limit [if_name]<br />
限制每个包的分段数Firewall(config)# fragment chain chain-limit [if_name]<br />
限制一个数据包分段到达的时间Firewall(config)# fragment timeout seconds [if_name]<br />
配置接口的优先队列（7.x新特性）<br />
暂略<br />
2.2配置路由<br />
启用PRF防止地址欺骗 Firewall(config)# ip verify reverse-path interface if_name<br />
配置静态路由Firewall(config)# route if_name ip_address netmask gateway_ip [metric]<br />
配置RIP<br />
被动听RIP更新(v1，v2)Firewall(config)# rip if_name passive [version 1] （Firewall(config)# rip if_name passive version 2<br />
[authentication [text | md5 key (key_id)]]）<br />
宣告该接口为缺省路由Firewall(config)# rip if_name default version [1 | 2 [authentication [text | md5 key key_id]]<br />
配置OSPF<br />
定义OSPF进程 Firewall(config)# router ospf pid<br />
指定相应网络到OSPF区域 Firewall(config-router)# network ip_address netmask area area_id<br />
可选：定义Router ID Firewall(config-router)# router-id ip_address<br />
记录OSPF邻居状态更新 Firewall(config-router)# log-adj-changes [detail]<br />
启用OSPF更新认证 Firewall(config-router)# area area_id authentication [message-digest]<br />
宣告缺省路由 Firewall(config-router)# default-information originate [always] [metric value] [metric-type {1 | 2}] [route-map<br />
name]<br />
调节OSPF参数 Firewall(config-router)# timers {spf spf_delay spf_holdtime |lsa-group-pacing seconds}<br />
2.3 DHCP<br />
配置成为DHCP Server：<br />
配置地址池 Firewall(config)# dhcpd address ip1[-ip2] if_name  （最多256个客户端）<br />
配置DHCP参数 Firewall(config)# dhcpd dns dns1 [dns2] Firewall(config)# dhcpd wins wins1 [wins2] Firewall(config)# dhcpd<br />
domain domain_name Firewall(config)# dhcpd lease lease_length  Firewall(config)# dhcpd ping_timeout timeout<br />
启用DHCP服务 Firewall(config)# dhcpd enable if_name<br />
验证：show dhcdp, show dhcpd bindings, show dhcpd statistics<br />
配置DHCP中继：<br />
定义真实DHCP Server Firewall(config)# dhcprelay server dhcp_server_ip server_ifc(最多4个)<br />
中继参数Firewall(config)# dhcprelay timeout seconds Firewall(config)# dhcprelay setroute client_ifc<br />
启用中继 Firewall(config)# dhcprelay enable client_ifc<br />
验证 show dhcprelay statistics<br />
2.4组播的支持<br />
暂略<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第三章 <br />
一、防火墙的管理<br />
3.1 使用Security Context建立虚拟防火墙（7.x特性）<br />
特性介绍：从PIX7.0和FWSM 2.2(1)开始，可以把物理的一个防火墙配置出多个虚拟的防火墙，每个防火墙称为context，这样一个防火墙就支<br />
持两种工作模式：single-context和multiple-context，处于后者工作模式的防火墙被分为三个功能模块：system execution space(虽然没有<br />
context的功能，但是是所有的基础)，administrative context(被用来管理物理的防火墙) 和 user contexts(虚拟出来的防火墙，所有配置<br />
防火墙的命令都适用)<br />
配置：首先使用show activation-key来验证是否有multiple-context的许可，然后通过mode multiple和mode single命令在这两个模式之间进<br />
行切换，当然也可以用show mode来验证现在工作在什麽模式下。在不同context下进行切换使用Firewall# changeto {system | context<br />
name}，由于所有的context的定义都必须在system execution space下，所以要首先使用changeto system转入该模式，Firewall(config)#<br />
context name 接着要把物理接口映射到context中 只要这样才能在相应的context下显示出物理接口，从而配置其属性<br />
Firewall(config-ctx)# allocate-interface physical-interface [map-name] 最后定义context 的startup-config的存放位置<br />
Firewall(config-ctx)# config-url url  通过show context验证<br />
注：当防火墙工作在multiple-context模式下，admin context就自动生成。(show context来验证)<br />
由于所有的context都共享设备的资源，所以要限制各个context的资源分配<br />
首先定义class Firewall(config)# class name 然后Firewall(config-class)# limit-resource all number% Firewall(config-class)#<br />
limit-resource [rate] resource_name number[%] 最后在相应的context配置下Firewall(config-ctx)# member class<br />
通过以下命令验证 show class， show resource allocation, show resource usage等<br />
注：缺省telnet，ssh，IPsec 5 sessions，MAC address 65535条目<br />
3.2 管理Flash文件系统<br />
6.x文件系统<br />
只有六种文件可以保存到Flash，没有文件名只有代号，没有目录结构<br />
0 OS镜像 1 启动文件 2 VPN和密匙证书 3 PDM镜像 4 崩溃信息 5 0的文件大小<br />
show flashfs 显示flash文件<br />
7.x和FWSM文件系统<br />
7.x和FWSM更像IOS的文件系统，具有层级目录，要被格式化后才可以使用，7.x使用flash:/代表Flash文件系统，FWSM分别使用flash:/ (系统<br />
镜像)和disk:/(配置文件)<br />
由于该系统使用类Unix的指令，所以可以使用下列常用命令来对该文件系统操作：<br />
dir pwd cd more delete copy rename mkdir rmdir format erase fsck(检查文件系统完整性)<br />
6.x在Flash裡面只能保存一个系统镜像，7.x则废除了此种限制通过使用Firewall(config)# boot system flash:filename来选取不同的系统镜<br />
像，show bootvar进行验证<br />
OS升级 见附录<br />
3.3 管理配置文件<br />
7.0以后可以使用多个启动配置文件Firewall(config)# boot config url<br />
显示启动配置文件Firewall# show startup-config Firewall# show configuration (6.x为show configure)<br />
保存当前配置文件 write memory, copy running-config startup-config, write net [[server-ip-address]:[filename]] (7.x也支持copy<br />
至tftp)<br />
强制standby同步当前配置文件 write standby 删除启动配置文件 write erase<br />
合併启动配置文件为当前配置文件 configure memory 从Web导入配置文件configure http[s]://[user:password@]location[:port]/<br />
http-pathname  (7.x支持copy自以上源)<br />
合併配置文件自自动更新服务器<br />
Firewall(config)# auto-update device-id {hardware-serial | hostname |<br />
ipaddress [if_name] | mac-address [if_name] | string text}<br />
Firewall(config)# auto-update server http[s]://[username:password@]<br />
AUSserver-IP-address[:port]/autoupdate/AutoUpdateServlet<br />
[verify-certificate]<br />
3.4 管理管理会话<br />
Firewall(config)# console timeout minutes 配置console登录的超时(缺省0不超时)<br />
禁止来自outside端口的telnet，启用telnet Firewall(config)# telnet ip_address netmask if_name   Firewall(config)# telnet<br />
timeout minutes  配置telnet超时<br />
启用SSH配置<br />
首先生成RSA密匙对 Firewall(config)# domain-name name Firewall(config)# ca generate rsa key [modulus] (7.x 使用crypto key<br />
generate rsa general-keys [modulus modulus]) Firewall(config)# ca save all (7.x自动保存)<br />
使用show ca mypubkey rsa来验证(7.x show crypto key mypubkey rsa) ca zeroize rsa作废原有密匙对(7.x crypto key zeroize rsa<br />
default)<br />
最后允许ssh会话 Firewall(config)# ssh ip_address netmask if_name<br />
ssh version命令可以选择ssh的版本，ssh timeout定义超时时间<br />
PDM/ASDM配置<br />
由于PDM存放位置固定，所以不需要指定镜像的位置，ASDM使用Firewall(config)# asdm image device:/path 来指定镜像位置，如果没有可以<br />
使用copy命令来安装。然后配置访问许可Firewall# http ip_address subnet_mask if_name 启用HTTP进程Firewall# http server enable 使<br />
用<a href="https://ip-address/admin">https://ip-address/admin</a>来访问。<br />
Banner配置 Firewall(config)# banner {exec | login | motd} text  对banner不能修改，只能用no来删除，或者clear banner来清除所有<br />
的banner（7.0 clear configure banner）<br />
监控管理会话 who监控telnet会话 kill telnet-id来清除会话，show ssh sessions监控ssh会话，ssh disconnect session-id清除ssh会话，<br />
show pdm sessions监控pdm会话，pdm disconnect session-id清除pdm会话<br />
3.5 系统重启和崩溃<br />
通常使用reload命令重启系统，从7.0以后支持在特定的时间重启系统Firewall# reload at hh:mm [month day | day month] [max-hold-time<br />
{minutes | hhh:mm}] [noconfirm] [quick] [save-config] [reason text]或者经过一定的时间间隔后重启Firewall# reload in {minutes |<br />
hh:mm} [max-hold-time {minutes | hhh:mm}] [noconfirm] [quick] [save-config] [reason text]<br />
启用崩溃信息生成 Firewall(config)# crashinfo save enable (7.0 no crashinfo save disable) show crashinfo 来看崩溃信息 clear<br />
crashinfo删除信息（FWSM使用crashdump）<br />
3.6       SNMP支持<br />
系统SNMP信息 Firewall(config)# snmp-server location string (contact string)<br />
SNMP访问许可 Firewall(config)# snmp-server host if_name ip_addr [poll | trap]<br />
Firewall(config)# snmp-server community key<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第四章 <br />
四、用户管理<br />
4.1 一般用户管理<br />
注：缺省情况下认证用户仅需要password，这样的一般用户缺省用户名就是enalbe_1,在ssh情况下缺省用户名就是pix，然后用password来认证<br />
。<br />
非特权模式密码配置 Firewall(config)# {password | passwd} password [encrypted] (恢复缺省密码cisco 用clear {password | passwd})<br />
特权模式密码配置 Firewall(config)# enable password [pw] [level priv_level] [encrypted]<br />
4.2 本地数据库管理用户<br />
定义用户 Firewall(config)# username username [{nopassword | password password}<br />
[encrypted]] privilege level<br />
启用本地认证 Firewall(config)# aaa authentication {serial | telnet | ssh | http} console LOCAL<br />
注：缺省情况特权模式密码使用enable password定义，这样用户通过认证后使用enable来进入特权模式，而不管用户初始什麽等级的权限，所<br />
有用户使用相同的密码。这裡也可以使用本地enable认证(aaa authentication enable console LOCAL)，用户使用username password的密码<br />
来进入enable，用户enable密码独立从而增加安全性。<br />
本地授权：Firewall(config)# aaa authorization command LOCAL<br />
配置命令的特权等级：Firewall(config)# privilege {show | clear | configure} level level [mode {enable | configure}] command<br />
command<br />
使用show privilege来看当前命令的特权等级(7.x使用show run all privilege)<br />
4.3 使用AAA服务器来管理用户<br />
定义AAA服务器组和协议 Firewall(config)# aaa-server server_tag protocol {tacacs+ | radius} (7.x还增加了kerberos,ldap,nt,sdi协<br />
议的支持)<br />
加入服务器到组 Firewall(config)# aaa-server server_tag [(if_name)] host server_ip [key] [timeout seconds]<br />
可选命令<br />
定义服务器失败阀值 FWSM Firewall(config)# aaa-server server_tag max-attempts number<br />
PIX 6.x Firewall(config)# aaa-server server_tag max-failed-attempts number<br />
PIX 7.x Firewall(config-aaa-server-group)# max-failed-attempts number<br />
定义统计策略(7.x特性) Firewall(config-aaa-server-group)# accounting-mode {single | simultaneous}<br />
具体各协议参数配置暂略<br />
4.4 配置AAA管理用户<br />
启用鉴权 Firewall(config)# aaa authentication {serial | telnet | ssh | http} console<br />
server_tag [LOCAL]<br />
启用授权 Firewall(config)# aaa authorization command server_tag [LOCAL]<br />
启用统计 Firewall(config)# aaa accounting command [privilege level] server_tag<br />
注：AAA服务器配置略<br />
4.5 配置AAA支持用户Cut-Through代理<br />
4.6 密码恢复<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第五章<br />
五 防火墙的访问控制<br />
5.1 防火墙的透明模式<br />
特性介绍：从PIX 7.0和FWSM 2.2开始防火墙可以支持透明的防火墙模式，接口不需要配置地址信息，工作在二层。只支持两个接口inside和<br />
outside，当然可以配置一个管理接口，但是管理接口不能用于处理用户流量，在多context模式下不能复用物理端口。由于连接的是同一地址<br />
段的网络，所以不支持NAT，虽然没有IP地址但是同样可以配置ACL来检查流量。<br />
进入透明模式 Firewall(config)# firewall transparent (show firewall 来验证当前的工作模式，由于路由模式和透明模式工作方式不同，<br />
所以互相切换的时候会清除当前配置文件)<br />
配置接口 Firewall(config)# interface hardware-id<br />
Firewall(config-if)# speed {auto | 10 | 100 |nonegotiate}<br />
Firewall(config-if)# duplex {auto | full | half}<br />
Firewall(config-if)# [no] shutdown<br />
Firewall(config-if)# nameif if_name<br />
Firewall(config-if)# security-level level<br />
注：不用配置IP地址信息，但是其它的属性还是要配置的，接口的安全等级一般要不一样，same-security-traffic permit inter-interface<br />
命令可以免除此限制。<br />
配置管理地址 Firewall(config)# ip address ip_address subnet_mask<br />
Firewall(config)# route if_name foreign_network foreign_mask gateway [metric]<br />
MAC地址表的配置 Firewall# show mac-address-table 显示MAC地址表<br />
Firewall(config)# mac-address-table aging-time minutes 设置MAC地址表过期时间<br />
Firewall(config)# mac-address-table static if_name mac_address 设置静态MAC条目<br />
Firewall(config)# mac-learn if_name disable 禁止特定接口地址学习(show mac-learn验证)<br />
ARP检查 Firewall(config)# arp if_name ip_address mac_address 静态ARP条目<br />
Firewall(config)# arp-inspection if_name enable [flood | no-flood] 端口启用ARP检查<br />
为非IP协议配置转发策略 Firewall(config)# access-list acl_id ethertype {permit | deny} {any | bpdu | ipx | mpls-unicast |<br />
mpls-multicast | ethertype}<br />
Firewall(config)# access-group acl_id {in | out} interface if_name<br />
5.2 防火墙的路由模式和地址翻译<br />
特性介绍：从高安全等级到低安全等级的访问称为outbound访问，需要配置地址翻译和outbound访问控制，PIX缺省情况下不用配置ACL就允许<br />
此类访问，FWSM则需要配置ACL来允许此类型的访问。而从低安全等级到高安全等级的访问称为inboud访问，也需要配置地址翻译和inboud访问<br />
控制，此类型必须配置ACL.同一安全等级的访问也可以配置地址翻译。<br />
支持下列几种NAT类型</p>
<p>Translation Type<br />
Application<br />
Basic Command<br />
Direction in Which Connections Can Be Initiated<br />
Static NAT<br />
Real source addresses (and ports) are translated to mapped addresses (and ports)<br />
static<br />
Inbound or outbound<br />
Policy NAT<br />
Conditionally translates real source addresses (and ports) to mapped addresses<br />
static access-list<br />
Inbound or outbound<br />
Identity NAT<br />
No translation of real source addresses<br />
nat 0<br />
Outbound only<br />
NAT exemption<br />
No translation of real source addresses matched by the access list<br />
nat 0 access-list<br />
Inbound or outbound<br />
Dynamic NAT<br />
Translates real source addresses to a pool of mapped addresses<br />
nat id<br />
global id address-range<br />
Outbound only<br />
PAT<br />
Translates real source addresses to a single mapped address with dynamic port numbers<br />
nat id<br />
global id address<br />
Outbound only<br />
配置<br />
对于连接数的控制 PIX 6.x &#8230; [norandomseq] [max_conns [emb_limit]]<br />
PIX 7.x  &#8230; [norandomseq] [[tcp] max_conns [emb_limit]] [udp udp_max_conns]<br />
连接超时控制 Firewall(config)# timeout [conn hh:mm:ss] [udp hh:mm:ss]<br />
静态NAT<br />
基于地址的静态翻译 Firewall(config)# static (real_ifc,mapped_ifc) {mapped_ip | interface} {real_ip [netmask mask]} [dns]<br />
[norandomseq] [max_conns [emb_limit]]<br />
基于端口的静态翻译 Firewall(config)# static (real_ifc,mapped_ifc) {tcp | udp} {mapped_ip | interface} mapped_port {real_ip<br />
real_port [netmask mask]} [dns] [norandomseq] [max_conns [emb_limit]]<br />
策略NAT<br />
定义翻译策略 Firewall(config)# access-list acl_name permit ip real_ip real_mask foreign_ip foreign_mask<br />
静态的 Firewall(config)# static (real_ifc,mapped_ifc) mapped_ip access-list acl_name [dns] [norandomseq] [max_conns<br />
[emb_limit]]<br />
NAT的 Firewall(config)# global (mapped_ifc) nat_id {global_ip [-global_ip] [netmask global_mask]} | interface<br />
Firewall(config)# nat (real_ifc) nat_id access-list acl_name [dns] [outside][norandomseq] [max_conns [emb_limit]]<br />
Identify NAT Firewall(config)# nat (real_ifc) 0 real_ip real_mask [dns] [norandomseq] [max_conns [emb_limit]]<br />
注：nat 0和static 相同地址的区别在于：nat 0只能用于outbound访问，static两种访问都可以，对同一地址不建议同时配置此两类命令。<br />
NAT Exemption<br />
Firewall(config)# access-list acl_name permit ip local_ip local_mask foreign_ip foreign_mask<br />
Firewall(config)# nat (real_ifc) 0 access-list acl_name [dns] [outside] [max_conns [emb_limit] [norandomseq]]<br />
注：此类型NAT策略只能根据源和目的地址不能根据协议类型或者端口<br />
动态地址翻译<br />
定义NAT的映射地址 Firewall(config)# global (mapped_ifc) nat_id global_ip[-global_ip] [netmask global_mask]<br />
定义PAT的映射地址 Firewall(config)# global (mapped_ifc) nat_id {global_ip | interface}<br />
定义翻译策略 Firewall(config)# nat (real_ifc) nat_id real_ip [mask [dns] [outside] [[norandomseq] [max_conns [emb_limit]]]<br />
注：也可以使用ACL来做类似的策略NAT。<br />
5.3 使用ACL进行访问控制<br />
特性介绍：防火墙的ACL配置跟IOS不同，子网掩码部分为正常的子网掩码不需要使用反转的子网掩码。还支持Object group，包含IP地址组，<br />
ICMP类型组，IP协议或者端口组，并且支持组嵌套。access-list acl_name compiled配置Turbo ACL，7.x自动turbo。防火墙的ACL缺省是扩展<br />
模式的，7.x后也支持标准模式了儘管只用于路由协议的配置上，并且加上了extend的参数，虽然配置的时候可以不必强制用这个参数但是当你<br />
需要移除该条目的时候要记得把extend这个参数加上。<br />
配置<br />
定义Object Group<br />
网络对像组 Firewall(config)# object-group network group_id<br />
Firewall(config-network)# description text<br />
Firewall(config-network)# network-object ip_addr mask (或者 host ip_addr)<br />
Firewall(config-network)# group-object group_id<br />
ICMP对像组 Firewall(config)# object-group icmp-type group_id<br />
Firewall(config-icmp-type)# description text<br />
Firewall(config-icmp-type)# icmp-object icmp_type<br />
Firewall(config-icmp-type)# group-object group_id<br />
协议对像组 Firewall(config)# object-group protocol group_id<br />
Firewall(config-protocol)# description text<br />
Firewall(config-protocol)# protocol-object protocol<br />
Firewall(config-protocol)# group-object group_id<br />
服务对像组 Firewall(config)# object-group service group_id {tcp | udp | tcp-udp}<br />
Firewall(config-service)# description text<br />
Firewall(config-service)# port-object range begin_port end_port (或者eq port)<br />
Firewall(config-service)# group-object group_id<br />
定义时间范围 7.0特性<br />
Firewall(config)# time-range name<br />
Firewall(config-time-range)# periodic start-day hh:mm to end-day hh:mm<br />
Firewall(config-time-range)# periodic days-of-the-week hh:mm to hh:mm<br />
Firewall(config-time-range)# absolute [start hh:mm day month year] [end hh:mm day month year]<br />
配置ACL Firewall(config)# access-list acl_id [line line-num] [extended] {permit | deny}<br />
  {protocol | object-group protocol_obj_group}   {source_addr  source_mask | object-group  network_obj_group} [operator<br />
sport | object-group service_obj_group]<br />
  {destination_addr destination_mask |object-group network_obj_group}<br />
[operator dport | object-group service_obj_group] [log [[disable | default] | [level]]] [interval secs]] [time-range name]<br />
[inactive]<br />
show access-list 来验证， clear access-list acl_id counters 重置ACL计数器<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第六章<br />
六 配置Failover增加可用性</p>
<p>特性介绍：为了增强可用性，避免单点故障，提高性能等原因才引入了Failover的特性。Active-Standby是最初支持的一种特性，其中一台是</p>
<p>UR的许可，另一台为UR或者Failover-only的许可，FWSM缺省支持此中模式，在该模式下一个为Active工作状态，Standby只是监控Active的状</p>
<p>态而不工作，这样就在性能上虽然有两台设备但是并没有得到加强。在7.x以后由于引入了context的概念，这样Active-Active另一种Failover</p>
<p>的特性也出现了，在每个context下有自己的active和standby，配置每个设备在不同context下的角色从而使其都工作，也增加了性能，但是此</p>
<p>模式只被PIX515E，525,535和ASA平台支持。</p>
<p>6.1 配置Failover</p>
<p>确定主备用的设备：一种方式是通过不同的许可来决定，如果两者都是UR的许可，对于适用serial连接的根据线缆两端的主备用标识来决定，</p>
<p>如果适用lan的话使用下面的命令来决定，Firewall(config)# failover lan unit {primary | secondary}</p>
<p>配置lan使用的端口</p>
<p>FWSM 2.x Firewall(config)# failover interface ip if_name ip_address mask standby ip_address</p>
<p>PIX 6.x Firewall(config)# interface phy_if phy_speed</p>
<p>Firewall(config)# nameif phy_if if_name securitylevel</p>
<p>Firewall(config)# ip address if_name ip_address netmask</p>
<p>Firewall(config)# failover ip address if_name ip_address</p>
<p>PIX 7.x  Firewall(config)# interface phy_if</p>
<p>Firewall(config-if)# speed speed</p>
<p>Firewall(config-if)# duplex duplex</p>
<p>Firewall(config-if)# no shutdown</p>
<p>Firewall(config-if)# exit</p>
<p>Firewall(config)# failover interface ip if_name ip_address mask standby ip_address</p>
<p>定义用于Failover通讯的接口</p>
<p>FWSM 2.x Firewall(config)# failover lan interface if_name vlan vlan</p>
<p>PIX 6.x  Firewall(config)# failover lan interface if_name</p>
<p>PIX 7.x  Firewall(config)# failover lan interface if_name phy_if</p>
<p>也可以使用failover lan key key-string命令对通讯进行加密</p>
<p>failover lan enable 启用lan-based failover，FWSM缺省使用此模式，不需要此命令。</p>
<p>对于Active-Active模式需要在主设备的system execution space下配置Failover组，</p>
<p>Firewall(config)# failover group {1 | 2}</p>
<p>Firewall(config-fover-group)# {primary | secondary}</p>
<p>Firewall(config-fover-group)# preempt</p>
<p>对接口使用虚拟的MAC地址</p>
<p>PIX 6.x Firewall(config)# failover mac address if_name active_mac standby_mac</p>
<p>PIX 7.x (A-S) Firewall(config)# failover mac address phy_if active_mac standby_mac</p>
<p>PIX 7.x (A-A)  Firewall(config)# failover group {1 | 2}</p>
<p>Firewall(config-fover-group)# mac address phy_if  active_mac standby_mac</p>
<p>定义健康监控策略</p>
<p>PIX 6.x Firewall(config)# failover poll time</p>
<p>PIX 7.x Firewall(config)# failover polltime [unit] [msec] time [holdtime holdtime]</p>
<p>Firewall(config)# failover polltime interface time</p>
<p>Firewall(config)# failover interface-policy num[%]</p>
<p>Firewall(config)# monitor-interface if_name</p>
<p>保持HTTP的状态信息 Firewall(config)# failover replicate http</p>
<p>Firewall(config)# failover 启用Failover进程</p>
<p>6.2 管理Failover</p>
<p>show failover命令对状态进行监控，后面可以加state,lan, history,等参数。</p>
<p>(no)Failover active手动的对状态进行切换,重置一个失败的设备failover reset。对于不能同步的挂起设备使用failover reload-standby强</p>
<p>制重启。</p>
<p>6.3 升级Failover模式防火墙的OS镜像</p>
<p>见附录<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第七章 <br />
七 配置负载均衡</p>
<p>特性介绍：虽然使用Failover保证了高可用性，但是在流量分担上还有劣势，儘管7.x支持了A-A的模式，不过也仅仅只能是两台防火墙。真正</p>
<p>的负载均衡的实现有三种方式，第一为软件方式，使用6500平台上IOS SLB(Server Load Balancing)特性的一个子集FWLB来实现，第二为硬件</p>
<p>方式，在6500上配置CSM(Content Switching Module)来实现，最后一种为专属设备方式，思科的CSS(Content Services Switch)产品线的设备</p>
<p>来实现。要注意的是在配置负载均衡的时候要inside和outside同时配置，免得出现来回链路不同而被丢弃的情况。</p>
<p>7.1 配置软件实现 (只在6500 native ios模式下)</p>
<p>定义防火墙群的连接性 Router(config)# vlan vlan-id</p>
<p>Router(config)# interface vlan vlan-id</p>
<p>Router(config-if)# ip address ip-address subnet-mask</p>
<p>Router(config-if)# no shutdown</p>
<p>Router(config)# ip route inside-network subnet-mask fw-outside-address</p>
<p>定义针对每个防火墙失败的探测器 Router(config)# ip slb probe name ping</p>
<p>Router(config-slb-probe)# address ip-address</p>
<p>Router(config-slb-probe)# interval seconds</p>
<p>Router(config-slb-probe)# faildetect retry-count</p>
<p>定义防火墙群 Router(config)# ip slb firewallfarm firewallfarm-name</p>
<p>Router(config-slb-fw)# real ip-address</p>
<p>Router(config-slb-fw-real)# probe probe-name</p>
<p>Router(config-slb-fw-real)# inservice</p>
<p>Router(config-slb-fw-real)# weight weighting-value</p>
<p>定义特定的数据流到该防火墙群(只针对Outside)</p>
<p>Router(config-slb-fw)# access [source source-ip-address network-mask]</p>
<p>[destination destination-ip-address network-mask]</p>
<p>选择FWLB的方式 Router(config-slb-fw)# predictor hash address [port]</p>
<p>启用FWLB Router(config-slb-fw)# inservice</p>
<p>7.2 配置硬件实现</p>
<p>进入CSM负载均衡模式 Switch(config)# ip slb mode csm</p>
<p>选择CSM模块 Switch(config)# module csm slot-number</p>
<p>配置到离开防火墙群的连接性 Switch(config-module-csm)# vlan vlan-id client</p>
<p>Switch(config-slb-vlan-client)# ip address ip-address netmask</p>
<p>Switch(config-slb-vlan-client)# gateway ip-address</p>
<p>Switch(config-slb-vlan-client)# exit</p>
<p>配置到防火墙群的连接性 Switch(config-module-csm)# vlan vlan-id server</p>
<p>Switch(config-slb-vlan-server)# ip address ip-address netmask</p>
<p>Switch(config-slb-vlan-server)# alias ip-address netmask</p>
<p>Switch(config-slb-vlan-server)# route ip-address netmask gateway gw-ip-address</p>
<p>定义防火墙探测器 Switch(config-module-csm)# probe probe-name icmp</p>
<p>Switch(config-slb-probe-icmp)# interval seconds</p>
<p>Switch(config-slb-probe-icmp)# receive receive-timeout</p>
<p>Switch(config-slb-probe-icmp)# retries retry-count</p>
<p>Switch(config-slb-probe-icmp)# failed failed-interval</p>
<p>定义防火墙群 Switch(config-module-csm)# serverfarm serverfarm-name</p>
<p>Switch(config-slb-sfarm)# real ip-address</p>
<p>Switch(config-slb-real)# inservice</p>
<p>Switch(config-slb-sfarm)# predictor hash address {source | destination} 255.255.255.255</p>
<p>Switch(config-slb-sfarm)# no nat server</p>
<p>Switch(config-slb-sfarm)# probe probe-name</p>
<p>定义一个虚拟服务器来处理发往服务器群的流量</p>
<p>Switch(config-module-csm)# vserver virtual-server-name</p>
<p>Switch(config-slb-vserver)# serverfarm serverfarm-name</p>
<p>Switch(config-slb-vserver)# virtual ip-address [network-mask] any</p>
<p>Switch(config-slb-vserver)# vlan vlan-number</p>
<p>Switch(config-slb-vserver)# inservice</p>
<p>Switch(config-slb-vserver)# replicate csrp {sticky | connection}</p>
<p>定义一个通用服务器群处理离开防火墙群的流量</p>
<p>Switch(config-module-csm)# serverfarm serverfarm-name</p>
<p>Switch(config-slb-sfarm)# predictor forward</p>
<p>Switch(config-slb-sfarm)# no nat server</p>
<p>定义一个通用的虚拟服务器处理离开防火墙群的流量</p>
<p>Switch(config-module-csm)# vserver virtual-server-name</p>
<p>Switch(config-slb-vserver)# serverfarm serverfarm-name</p>
<p>Switch(config-slb-vserver)# virtual 0.0.0.0 0.0.0.0  any</p>
<p>Switch(config-slb-vserver)# vlan vlan-number</p>
<p>Switch(config-slb-vserver)# inservice</p>
<p>7.3 配置CSS实现</p>
<p>配置CSS的物理接口 (config) interface interface_name</p>
<p>(config-if) bridge vlan vlan-id (或者(config-if) trunk)</p>
<p>指定IP地址 (config) circuit circuit_name</p>
<p>(config-circuit) ip address ip_address subnet_mask</p>
<p>(config-circuit-ip) enable</p>
<p>配置缺省路由 (config) ip route 0.0.0.0 0.0.0.0 next-hop-address</p>
<p>定义防火墙群的防火墙 (config) ip firewall index local_firewall_address remote_firewall_address  remote_css_address</p>
<p>定义静态路由 (config) ip route ip_address subnet_mask firewall index distance</p>
<p>调整Keeplive时间 (config) ip firewall timeout seconds</p>
<p>验证命令 show ip firewall 防火墙状态，show ip routes firewall到防火墙的静态路由，show flows显示到防火墙的负载均衡连接。<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第八章 <br />
八、日志管理</p>
<p>8.1 时钟管理</p>
<p>定义时区 Firewall(config)# clock timezone zone-name hours [minutes]</p>
<p>定义夏令时 Firewall(config)# clock summer-time zone recurring [week weekday month</p>
<p>hh:mm week weekday month hh:mm] [offset]</p>
<p>Firewall(config)# clock summer-time zone date {day month | month day}</p>
<p>year hh:mm {day month | month day} year hh:mm [offset]</p>
<p>设置防火墙时钟 Firewall(config)# clock set hh:mm:ss {day month | month day} year</p>
<p>时钟验证 Firewall# show clock [detail]</p>
<p>指定NTP服务器 Firewall(config)# ntp server ip-address [key number] [source if-name]</p>
<p>[prefer]</p>
<p>配置NTP认证 Firewall(config)# ntp authentication-key key-number md5 value</p>
<p>Firewall(config)# ntp trusted-key key-number</p>
<p>Firewall(config)# ntp authenticate</p>
<p>NTP验证 show ntp, show ntp status, show ntp associations</p>
<p>8.2 日志配置</p>
<p>启用消息日志 Firewall(config)# logging on (7.x 用logging enable)</p>
<p>使用事件列表定义日志策略 (7.0特性)</p>
<p>Firewall(config)# logging list event_list level level [class event_class]</p>
<p>Firewall(config)# logging list event_list message start[-end]</p>
<p>根据不同日志级别定义目的位置 (7.0特性)</p>
<p>Firewall(config)# logging class event_class destination level [destination level] [destination level] &#8230;</p>
<p>发送日志到console Firewall(config)# logging console level</p>
<p>发送日志到telnet，ssh会话 Firewall(config)# logging monitor level</p>
<p>发送日志到buffer Firewall(config)# logging buffered level</p>
<p>发送日志到ftp (7.0特性) Firewall(config)# logging ftp-bufferwrap</p>
<p>Firewall(config)# logging ftp-server ftp_server path username password</p>
<p>发送日志到flash (7.0特性) Firewall(config)# logging flash-bufferwrap</p>
<p>Firewall(config)# logging flash-minimum-free kbytes_free</p>
<p>Firewall(config)# logging flash-maximum-allocation kbytes_max</p>
<p>发送日志到SNMP服务器 Firewall(config)# snmp-server host [if_name] ip_addr trap (7.x</p>
<p>Firewall(config)# snmp-server host if_name ip_addr TRap [community string] [version version] [udp-port port])</p>
<p>Firewall(config)# snmp-server enable traps {all | syslog}</p>
<p>Firewall(config)# logging history level</p>
<p>发送日志到Syslog服务器 Firewall(config)# logging trap level</p>
<p>Firewall(config)# logging device-id {hostname | ipaddress if_name | string text}</p>
<p>Firewall(config)# logging host if_name ip_address [protocol/port] [format emblem]</p>
<p>Firewall(config)# logging timestamp</p>
<p>Firewall(config)# logging queue queue_size (show logging queue验证)</p>
<p>Firewall(config)# logging facility facility</p>
<p>Firewall(config)# logging standby</p>
<p>发送日志到邮件 (7.x特性) Firewall(config)# logging mail {level | event-list}</p>
<p>Firewall(config)# smtp-server server_primary [server_secondary]</p>
<p>Firewall(config)# logging from-address from_email_address</p>
<p>Firewall(config)# logging recipient-address to_email_address [level level]</p>
<p>发送日志到ASDM Firewall(config)# logging asdm-buffer-size num_of_msgs</p>
<p>Firewall(config)# logging asdm {level | event-list}</p>
<p>验证 show logging</p>
<p>8.3 日志消息输出的微调</p>
<p>消息的修剪 Firewall(config)# no logging message message-number (show logging message 验证)</p>
<p>改变消息严重等级 Firewall(config)# logging message message-number [level level]</p>
<p>配置日志对ACL支持 Firewall(config)# access-list acl_name {permit | deny} &#8230; log [level] [interval seconds]</p>
<p>Firewall(config)# access-list deny-flow-max n</p>
<p>Firewall(config)# access-list alert-interval seconds</p>
<p>8.4 日志分析</p>
<p>对日志分析的软件</p>
<p>CS-MARS  (<a href="http://www.cisco.com/">http://www.cisco.com</a>)</p>
<p>Network  Intelligence Engine (<a href="http://www.network-intelligence.com/">http://www.network-intelligence.com</a>)</p>
<p>Network Security Analyzer和FirewallAnalyzer Enterprise (<a href="http://www.eiqnetworks.com/">http://www.eiqnetworks.com</a>)</p>
<p>Sawmill Log Analyzer (<a href="http://www.sawmill.net/">http://www.sawmill.net</a>)</p>
<p>CiscoWorks (<a href="http://www.cisco.com/">http://www.cisco.com</a>)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
■思科ASA和PIX防火墙配置手册 第九章<br />
九、防火墙工作状态验证</p>
<p>9.1 防火墙健康检查</p>
<p>CPU负荷 Firewall# show cpu usage (show cpu usage context all 正常应该在80%以下)</p>
<p>Show processes显示防火墙当前活动进程，一般关注Process和Runtime。</p>
<p>内存利用 Firewall# show memory</p>
<p>Xlate 表大小 Firewall# show xlate count</p>
<p>Conn 表大小 Firewall# show conn count</p>
<p>防火墙流量 使用PDM，Syslog, show traffic来计算或者Perfmon计数器 Firewall# show perfmon  Firewall(config)# perfmon interval</p>
<p>seconds ,perfmon {verbose | quiet}</p>
<p>Inspection引擎和Service Policy  Firewall# show service-policy</p>
<p>Failover Firewall# show failover</p>
<p>端口状态 Firewall# show interface, 包队列状态 Firewall# show priority-queue statistics [if_name]</p>
<p>9.2 流经防火墙数据的监控</p>
<p>特性介绍 对于流经防火墙数据的监控有两种方式capture session和debug packet，两者区别在于前者可以后处理，多个进程，CPU和内存利用</p>
<p>率低，后者是实时显示，同时只能一个进程，且对资源利用率高，后者在7.x后已经不被支持。</p>
<p>配置Capture</p>
<p>配置兴趣流量的ACL Firewall(config)# access-list acl_id [line line-num] [extended] permit protocol {source_addr  source_mask</p>
<p>[operator sport] [destination_addr destination_mask [operator dport]]</p>
<p>配置Capture Firewall# capture capture_name [access-list acl_name] [ethernet-type type]</p>
<p>[interface if-name] [buffer bytes] [circular-buffer] [packet-length bytes]</p>
<p>(7.x支持type {raw-data | isakmp | asp-drop drop-reason}参数)</p>
<p>show capture显示当前的Capture会话，Firewall# show capture capture_name [access-list acl_name] [detail] [dump] 显示所抓包的信</p>
<p>息。Firewall# copy capture:capture-name tftp://server/path [pcap] 拷贝信息至TFTP，如果启用http后可以用</p>
<p><a href="https://firewall_address/capture/capture_name[/pcap">https://firewall_address/capture/capture_name[/pcap</a>]通过Web来显示或者下载。</p>
<p>clear capture capture_name清空capture缓存但是保持会话，no capture capture_name interface if_name停止capture，从特定接口去除保</p>
<p>持会话和缓存，no capture capture_name彻底删除会话和缓存。</p>
<p>配置Debug模式 Firewall# debug packet if_name [src source_ip [netmask mask]] [dst dest_ip  [netmask mask]] [[proto icmp] |</p>
<p>[proto {tcp | udp} [sport src_port] [dport</p>
<p>dest_port]] [rx | tx | both]</p>
<p>9.3 验证防火墙的连接性</p>
<p>Ping测试 Firewall# ping [if_name] host [data pattern] [repeat count] [size bytes] [timeout seconds] [validate]</p>
<p>ARP缓存检查 show arp</p>
<p>路由表检查 show route</p>
<p>Traceroute测试 traceroute命令前提配置 Firewall(config)# access-list acl_name permit icmp any any eq echo</p>
<p>Firewall(config)# access-list acl_name permit icmp any any eq echo-reply</p>
<p>Firewall(config)# access-list acl_name permit icmp any any eq unreachable</p>
<p>Firewall(config)# access-list acl_name permit icmp any any eq time-exceeded</p>
<p>Firewall(config)# access-list acl_name permit udp any range 32768 65535 any range</p>
<p>33434 33523</p>
<p>Firewall(config)# access-list acl_name permit udp any dns_address eq domain (可选)</p>
<p>ACL检查  show access-group, show access-list</p>
<p>NAT验证  Firewall# show xlate [detail] [global | local ip1[-ip2] [netmask mask]] lport |</p>
<p>gport port[-port]] [interface if1[,if2][,ifn]] [state static [,dump]</p>
<p>[,portmap] [,norandomseq] [,identity]] [debug] [count]</p>
<p>Firewall# show xlate [{global | local} ip1[-ip2] [netmask mask]] [{lport | gport}</p>
<p>port[-port]] [interface if1[,if2][,ifn]] [state {static | portmap | identity |</p>
<p>norandomseq}] [debug] [detail]</p>
<p>Firewall# show conn [state state_type] [{foreign | local} ip1[-ip2] netmask mask]</p>
<p>[long] [{lport | fport} port1[-port2]] [protocol {tcp | udp}]</p>
<p>监控特定主机 Firewall# show local-host [ip_address] [all] [detail]</p>
<p>Firewall# clear xlate global global_ip [netmask mask] [gport global_port]</p>
<p>Firewall# clear xlate local local_ip [netmask mask] [lport local_port]</p>
<p>Firewall# clear xlate interface if_name_1[,if_name_2]</p>
<p>Firewall# clear xlate</p>
<p>超时参数Firewall(config)# timeout xlate hh[:mm[:ss]]</p>
<p>Firewall(config)# timeout conn hh[:mm[:ss]]</p>
<p>Firewall(config)# half-closed hh[:mm[:ss]]</p>
<p>Firewall(config)# udp hh[:mm[:ss]]</p>
<p>Shun检查 show shun， show shun statistics</p>
<p>用户认证检查 show uauth  show url-server stats</p>
<p>配置更新检查 启用AAA记录用户命令记录</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=97</wfw:commentRss>
		</item>
		<item>
		<title>Cisco3550三层交换机配置与管理</title>
		<link>http://frsky.net/?p=96</link>
		<comments>http://frsky.net/?p=96#comments</comments>
		<pubDate>Tue, 02 Dec 2008 05:23:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=96</guid>
		<description><![CDATA[Cisco3550三层交换机配置与管理
本文仅供网络管理参考
一、       3550日常管理命令&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 1
二、       密码恢复&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 1
三、       VLAN配置&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 4
四、       SPAN监听配置&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230; 12
五、       DHCP服务配置&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 13
1.    在3550上配置DHCP服务&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;. 13
2.    C3550配置作为DHCP中继代理&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;. 15
六、       流量控制&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230; 17
七、       策略路由&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230; 19
一、      3550日常管理命令
l         clear arp-cache清除ARP缓存
l         arp 192.168.100.22 000a.eb22.c1b5 arpa 绑定MAC和IP
l         sh ip accounting output-packets显示统计信息(当然需要配置统计功能如：ip accounting-transits [...]]]></description>
			<content:encoded><![CDATA[<p>Cisco3550三层交换机配置与管理</p>
<p><font color="#ff0000">本文仅供网络管理参考</font></p>
<p>一、       3550日常管理命令&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 1<br />
二、       密码恢复&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 1<br />
三、       VLAN配置&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 4<br />
四、       SPAN监听配置&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230; 12<br />
五、       DHCP服务配置&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.. 13<br />
1.    在3550上配置DHCP服务&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;. 13<br />
2.    C3550配置作为DHCP中继代理&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;. 15<br />
六、       流量控制&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230; 17<br />
七、       策略路由&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230; 19</p>
<p>一、      3550日常管理命令<br />
l         clear arp-cache清除ARP缓存<br />
l         arp 192.168.100.22 000a.eb22.c1b5 arpa 绑定MAC和IP<br />
l         sh ip accounting output-packets显示统计信息(当然需要配置统计功能如：ip accounting-transits 3200)<br />
l         通过IP追查交换机端口：CiscoWorks 2000 LMS网管软件的User tracking可以追查一个IP地址对应的端口。sh mac-address-table address 00e0.9102.afd0 显示这个MAC地址在哪个接口出来的；sh mac-address-table interface Fa0/20显示20端口上的MAC地址，如果只有一个，则可能连接一个电脑，如果有很多个条目，则可以连接一个交换机。sh cdp entry  *显示邻居信息；<br />
二、      密码恢复<br />
下面步骤也适用于 Cisco 层 2 系列的交换机比如 Catalyst 2900/3500XL,2940,2950/2955和层 3 系列的比如 Catalyst 3550 的密码恢复.<br />
通过终端或带有仿真终端程序(比如 Hyper Terminal)的 PC,连接到交换机的 console 对于Catalyst 2900/3500XL 拔下交换机的电源线,然后按住交换机的  Mode 按钮,再重新插上交换机的电源线.直到端口 Port 1x 的 LED 熄灭之后释放 Mode 按钮.Catalyst 2940/2950L 拔下交换机的电源线,然后按住交换机的  Mode  按钮,再重新插上交换机的电源线.直到 STAT 的 LED 熄灭之后释放 Mode 按<br />
钮. Catalyst 2955 对于 2955 交换机,它没有外部的 Mode 按钮,因此就不能使用之前的那种方法来进行密码恢 复.在交换机启动时,对于 Windows 系列的 PC,按下 Ctrl+Break 键;对于 UNIX 系列的工 作站,按下 Ctrl+C.如下:<br />
C2955  Boot  Loader  (C2955HBOOTM)  Version  12.1(0.0.514),  CISCO DEVELOPMENT TEST<br />
VERSION<br />
Compiled Fri 13Dec02 17:38 by madison<br />
WSC2955T12 starting&#8230;<br />
Base ethernet MAC Address: 00:0b:be:b6:ee:00<br />
Xmodem file system is available.<br />
Initializing Flash&#8230;<br />
flashfs[0]: 19 files, 2 directories<br />
flashfs[0]: 0 orphaned files, 0 orphaned directories flashfs[0]: Total bytes: 7741440<br />
flashfs[0]: Bytes used: 4510720 flashfs[0]: Bytes available: 3230720 flashfs[0]: flashfs<br />
fsck took 7 seconds.<br />
&#8230;done initializing flash.<br />
Boot Sector Filesystem (bs:) installed, fsid: 3<br />
Parameter Block Filesystem (pb:) installed, fsid: 4<br />
/&#8212;接下来交换机会在 15 秒内自动启动,等出现该信息之后,按下 Ctrl+Break 键或 Ctrl+C<br />
键&#8212;-/<br />
The system has been interrupted prior to initializing the flash file system to finish<br />
loading the operating system software:<br />
flash_init load_helper bootswitch:<br />
接下来输入 flash_init 命令: switch: flash_init Initializing Flash&#8230;<br />
flashfs[0]: 143 files, 4 directories<br />
flashfs[0]: 0 orphaned files, 0 orphaned directories flashfs[0]: Total bytes: 3612672<br />
flashfs[0]: Bytes used: 2729472 flashfs[0]: Bytes available: 883200 flashfs[0]: flashfs fsck<br />
took 86 seconds<br />
&#8230;.done Initializing Flash.</p>
<p>Boot Sector Filesystem (bs:) installed, fsid: 3<br />
Parameter Block Filesystem (pb:) installed, fsid: 4<br />
switch:<br />
接着输入 load_helper 命令: switch: load_helper switch:<br />
再输入 dir flash:命令显示交换机的文件系统:<br />
switch: dir flash: Directory of flash:/<br />
2 rwx  1803357    c3500xlc3h2smz.1205.WC7.bin<br />
4 rwx  1131    config.text<br />
5 rwx  109      info<br />
6 rwx  389      env_vars</p>
<p>7   drwx  640     html<br />
18 rwx  109    info.ver<br />
403968 bytes available (3208704 bytes used)<br />
switch:<br />
把配置文件重命名:<br />
switch: rename flash:config.text flash:config.old switch:</p>
<p>输入 boot 命令启动交换机:<br />
switch: boot<br />
Loading<br />
&#8220;flash:c3500xlc3h2smz.1205.WC7.bin&#8221;&#8230;####################<br />
###########<br />
######################<br />
File &#8220;flash:c3500xlc3h2smz.1205.WC7.bin&#8221; uncompressed and installed, entry po</p>
<p>int: 0&#215;3000</p>
<p>executing&#8230;<br />
(略)</p>
<p>不进入 setup 模式:<br />
System Configuration Dialog<br />
At any point you may enter a question mark &#8216;?&#8217; for help. Use ctrlc to abort configuration<br />
dialog at any prompt. Default settings are in square brackets &#8216;[]&#8217;.<br />
Continue with configuration dialog? [yes/no]: n<br />
进入特权模式,恢复原始的配置文件:<br />
Switch#rename flash:config.old flash:config.text<br />
Destination filename [config.text] Switch#<br />
把配置文件保存在内存里:<br />
Switch#copy flash:config.text system:runningconfig<br />
Destination filename [runningconfig]?<br />
1131 bytes copied in 0.760 secs<br />
Switch# 进入全局配置模式,取消密码设置: Switch(config)#no enable secret 保存配置:<br />
Switch#write memory<br />
Building configuration&#8230;<br />
[OK] Switch#<br />
三、      VLAN配置<br />
我们现在是一个具备三层交换功能的核心交换机接几台分支交换机(不具备三层交换能力)。我们核心交换机名称为:cmlroot;分支交换机分别为<br />
:hrswitch、misswitch、salesswitch，分别通过port 1的光线模块与核心交换机相连;并且vlan名称分别为hrlan、mislan、saleslan……</p>
<p>步骤如下：</p>
<p>　　1、设置vtp domain(核心、分支交换机上都设置)</p>
<p>　　2、配置中继(核心、分支交换机上都设置)</p>
<p>　　3、创建vlan(在server上设置)</p>
<p>　　4、将交换机端口划入vlan</p>
<p>　　5、配置三层交换</p>
<p>　　6、设置vtp domain。 vtp domain 称为管理域。</p>
<p>　　1、交换vtp更新信息的所有交换机必须配置为相同的管理域。如果所有的交换机都以中继线相连，那么只要在核心交换机上设置一个管理<br />
域，网络上所有的交换机都加入该域，这样管理域里所有的交换机就能够了解彼此的vlan列表。</p>
<p>　　cmlroot#vlan database 进入vlan配置模式</p>
<p>　　cmlroot(vlan)#vtp domain cmlroot 设置vtp管理域名称 cmlroot</p>
<p>　　cmlroot(vlan)#vtp server 设置交换机为服务器模式</p>
<p>　　hrswitch#vlan database 进入vlan配置模式</p>
<p>　　hrswitch(vlan)#vtp domain cmlroot 设置vtp管理域名称cmlroot</p>
<p>　　hrswitch(vlan)#vtp client 设置交换机为客户端模式</p>
<p>　　misswitch#vlan database 进入vlan配置模式</p>
<p>　　misswitch(vlan)#vtp domain cmlroot 设置vtp管理域名称cmlroot</p>
<p>　　misswitch(vlan)#vtp client 设置交换机为客户端模式</p>
<p>　　salesswitch#vlan database 进入vlan配置模式</p>
<p>　　salesswitch(vlan)#vtp domain cmlroot 设置vtp管理域名称cmlroot</p>
<p>　　salesswitch(vlan)#vtp client 设置交换机为客户端模式</p>
<p>　　注意:<br />
这里设置核心交换机为server模式是指允许在该交换机上创建、修改、删除vlan及其他一些对整个vtp域的配置参数，同步本vtp域中其他交换<br />
机传递来的最新的vlan信息;client模式是指本交换机不能创建、删除、修改vlan配置，也不能在nvram中存储vlan配置，但可同步由本vtp域中<br />
其他交换机传递来的vlan信息。</p>
<p>　　2、配置中继为了保证管理域能够覆盖所有的分支交换机，必须配置中继。</p>
<p>　　Cisco交换机能够支持任何介质作为中继线，为了实现中继可使用其特有的isl标签。isl(inter-switch link)是一个在交换机之间、交换<br />
机与路由器之间及交换机与服务器之间传递多个vlan信息及vlan数据流的协议，通过在交换机直接相连的端口配置isl封装，即可跨越交换机进<br />
行整个网络的vlan分配和进行配置。</p>
<p>　　在核心交换机端配置如下:</p>
<p>　　cmlroot(config)#interface gigabitethernet 2/1</p>
<p>　　cmlroot(config-if)#switchport</p>
<p>　　cmlroot(config-if)#switchport trunk encapsulation isl 配置中继协议</p>
<p>　　cmlroot(config-if)#switchport mode trunk</p>
<p>　　cmlroot(config)#interface gigabitethernet 2/2</p>
<p>　　cmlroot(config-if)#switchport</p>
<p>　　cmlroot(config-if)#switchport trunk encapsulation isl 配置中继协议</p>
<p>cmlroot(config-if)#switchport mode trunk</p>
<p>　　cmlroot(config)#interface gigabitethernet 2/3</p>
<p>　　cmlroot(config-if)#switchport</p>
<p>　　cmlroot(config-if)#switchport trunk encapsulation isl 配置中继协议</p>
<p>　　cmlroot(config-if)#switchport mode trunk</p>
<p>　　在分支交换机端配置如下:</p>
<p>　　hrswitch(config)#interface gigabitethernet 0/1</p>
<p>　　hrswitch(config-if)#switchport mode trunk</p>
<p>　　misswitch(config)#interface gigabitethernet 0/1</p>
<p>　　misswitch(config-if)#switchport mode trunk</p>
<p>　　salesswitch(config)#interface gigabitethernet 0/1</p>
<p>　　salesswitch(config-if)#switchport mode trunk</p>
<p>　　……</p>
<p>　　此时，管理域算是设置完毕了。</p>
<p>　　3、创建vlan</p>
<p>　　cmlroot(vlan)#vlan 10 name hrlan 创建了一个编号为10 名字为hrlan的 vlan</p>
<p>　　cmlroot(vlan)#vlan 11 name mislan 创建了一个编号为11 名字为mislan的 vlan</p>
<p>　　cmlroot(vlan)#vlan 12 name saleslan 创建了一个编号为12 名字为saleslan的 vlan</p>
<p>　　……</p>
<p>　　注意，这里的vlan是在核心交换机上建立的，其实，只要是在管理域中的任何一台vtp 属性为server的交换机上建立vlan，它就会通过vtp<br />
通告整个管理域中的所有的交换机。但如果要将具体的交换机端口划入某个vlan，就必须在该端口所属的交换机上进行设置。</p>
<p>　　4、将交换机端口划入vlan</p>
<p>　　例如，要将hrswitch、misswitch、salesswitch……分支交换机的端口1划入hrlan vlan，端口2划入mislan vlan，端口3划入saleslan<br />
vlan……</p>
<p>　　hrswitch(config)#interface fastethernet 0/1 配置端口1</p>
<p>　　hrswitch(config-if)#switchport access vlan 10 归属hrlan vlan</p>
<p>　　hrswitch(config)#interface fastethernet 0/2 配置端口2</p>
<p>　　hrswitch(config-if)#switchport access vlan 11 归属mislan vlan</p>
<p>　　hrswitch(config)#interface fastethernet 0/3 配置端口3</p>
<p>　　hrswitch(config-if)#switchport access vlan 12 归属saleslan vlan</p>
<p>　　misswitch(config)#interface fastethernet 0/1 配置端口1</p>
<p>　　misswitch(config-if)#switchport access vlan 10 归属hrlan vlan</p>
<p>　　misswitch(config)#interface fastethernet 0/2 配置端口2</p>
<p>　　misswitch(config-if)#switchport access vlan 11 归属mislan vlan</p>
<p>　　misswitch(config)#interface fastethernet 0/3 配置端口3</p>
<p>　　misswitch(config-if)#switchport access vlan 12 归属saleslan vlan</p>
<p>　　salesswitch(config)#interface fastethernet 0/1 配置端口1</p>
<p>　　salesswitch(config-if)#switchport access vlan 10 归属hrlan vlan</p>
<p>　　salesswitch(config)#interface fastethernet 0/2 配置端口2</p>
<p>　　salesswitch(config-if)#switchport access vlan 11 归属mislan vlan</p>
<p>　　salesswitch(config)#interface fastethernet 0/3 配置端口3</p>
<p>　　salesswitch(config-if)#switchport access vlan 12 归属saleslan vlan</p>
<p>　　……</p>
<p>　　5、配置三层交换</p>
<p>　　到这里，vlan已经基本划分完毕。但是，vlan间如何实现三层(网络层)交换呢?这时就要给各vlan分配网络(ip)地址了。给vlan分配ip地址<br />
分两种情况，其一，给vlan所有的节点分配静态ip地址;其二，给vlan所有的节点分配动态ip地址(可参考DHCP配置部分)。</p>
<p>给vlan hrlan分配的接口ip地址为192.168.101.1/24，网络地址为:192.168.101.0，</p>
<p>　　vlan mislan 分配的接口ip地址为192.168.102.1/24，网络地址为:192.168.102.0，</p>
<p>　　vlan saleslan分配接口ip地址为192.168.34.1/24， 网络地址为192.168.34.0</p>
<p>　　给vlan所有的节点分配静态ip地址。</p>
<p>　　首先在核心交换机上分别设置各vlan的接口ip地址。核心交换机将vlan做为一种接口对待，就象路由器上的一样，如下所示:</p>
<p>　　cmlroot(config)#interface vlan 10</p>
<p>　　cmlroot(config-if)#ip address 192.168.101.254 255.255.255.0 vlan10接口ip</p>
<p>　　cmlroot(config)#interface vlan 11</p>
<p>　　cmlroot(config-if)#ip address 192.168.102.253 255.255.255.0 vlan11接口ip</p>
<p>　　cmlroot(config)#interface vlan 12</p>
<p>　　cmlroot(config-if)#ip address 192.168.34.254 255.255.255.0 vlan12接口ip</p>
<p>　　……</p>
<p>　　再在各接入vlan的计算机上设置与所属vlan的网络地址一致的ip地址，并且把默认网关设置为该vlan的接口地址。这样，所有的vlan也可以互访了。</p>
<p>　目前我们的配置如下：</p>
<p>interface Vlan1<br />
ip address 192.168.100.254 255.255.255.0<br />
interface Vlan2<br />
ip address 192.168.5.253 255.255.255.0 sec<br />
ip address 192.168.5.254 255.255.255.0<br />
interface Vlan3<br />
ip address 192.168.101.254 255.255.255.0<br />
interface Vlan5<br />
ip address 192.168.34.254 255.255.255.0<br />
interface Vlan6<br />
ip address 192.168.102.253 255.255.255.</p>
<p>四、      SPAN监听配置<br />
1．在全局配置模式下：<br />
dh(config)# monitor session 1 source interface fastethernet0/24 rx|tx|all<br />
或dh(config)# monitor session 1 source interface vlan 1 -3 rx<br />
配置要监听的端口或vlan,其中对于端口可以监听进、出或双向的数据包，而监听vlan 则只能监听进入的数据包<br />
2.在全局配置模式下：<br />
Sw(config)# monitor session 1 destination interface fastethernet0/23<br />
配置监听终端要接入交换机的端口(destination port)<br />
说明：一个monitor session 即为一个监听行为，source interface可以属与不同的vlan，在同一个monitor session中可以同时监听多个port<br />
注：目前我们的3550的Fa0/24为连接防火墙的接口，Fa0/23为连接IDS主机的接口<br />
五、      DHCP服务配置<br />
1.        在3550上配置DHCP服务<br />
各VLAN保留2-10的IP地址不分配置,例如:192.168.100.0的网段,保留192.168.100.2至192.168.100.10的IP地址段不分配. VLAN 3和VLAN 4 不允许互相访问,但都可以访问服务器所在的VLAN 2,<br />
默认访问控制列表的规则是拒绝所有包.<br />
/*VLAN 2可用地址池和相应参数的配置,有几个VLAN要设几个地址池*/<br />
Switch(Config)Ip Dhcp Pool IP01<br />
/*设置可分配的子网*/<br />
Switch(Config-pool)Network 192.168.100.0 255.255.255.0<br />
/*设置DNS服务器*/<br />
Switch(Config-pool)Dns-server 192.168.100.16<br />
/*设置该子网的网关*/<br />
Switch(Config-pool)Default-router 192.168.100.254<br />
/*配置VLAN 3所用的地址池和相应参数*/<br />
Switch(Config)Ip Dhcp Pool IP02<br />
Switch(Config-pool)Network 192.168.101.0 255.255.255.0<br />
Switch(Config-pool)Dns-server 192.168.100.16<br />
Switch(Config-pool)Default-router 192.168.101.254<br />
/*配置VLAN 4所用的地址池和相应参数*/<br />
Switch(Config)Ip Dhcp Pool IP03<br />
Switch(Config-pool)Network 192.168.102.0 255.255.255.0<br />
Switch(Config-pool)Dns-server 192.168.100.16<br />
Switch(Config-pool)Default-router 192.168.102.253<br />
第六步:设置DHCP保留不分配的地址<br />
Switch(Config)Ip Dhcp Excluded-address 192.168.100.2 192.168.100.10<br />
Switch(Config)Ip Dhcp Excluded-address 192.168.101.2 192.168.101.10<br />
Switch(Config)Ip Dhcp Excluded-address 192.168.102.2 192.168.102.10<br />
第七步:启用路由<br />
/*路由启用后,各VLAN间主机可互相访问*/<br />
Switch(Config)Ip Routing<br />
第八步:配置访问控制列表<br />
Switch(Config)access-list 103 permit ip 192.168.100.0 0.0.0.255 192.168.101.0 0.0.0.255<br />
Switch(Config)access-list 103 permit ip 192.168.101.0 0.0.0.255 192.168.100.0 0.0.0.255<br />
Switch(Config)access-list 103 permit udp any any eq bootpc<br />
Switch(Config)access-list 103 permit udp any any eq tftp<br />
Switch(Config)access-list 103 permit udp any eq bootpc any<br />
Switch(Config)access-list 103 permit udp any eq tftp any<br />
Switch(Config)access-list 104 permit ip 192.168.100.0 0.0.0.255 192.168.102.0 0.0.0.255<br />
Switch(Config)access-list 104 permit ip 192.168.102.0 0.0.0.255 192.168.100.0 0.0.0.255<br />
Switch(Config)access-list 104 permit udp any eq tftp any<br />
Switch(Config)access-list 104 permit udp any eq bootpc any<br />
Switch(Config)access-list 104 permit udp any eq bootpc any<br />
Switch(Config)access-list 104 permit udp any eq tftp any<br />
第九步:应用访问控制列表<br />
/*将访问控制列表应用到VLAN 3和VLAN 4,VLAN 2不需要*/<br />
Switch(Config)Int Vlan 3<br />
Switch(Config-vlan)ip access-group 103 out<br />
Switch(Config-vlan)Int Vlan 4<br />
Switch(Config-vlan)ip access-group 104 out<br />
第十步：结束并保存配置<br />
Switch(Config-vlan)End<br />
Switch#Copy Run Start<br />
2.        C3550配置作为DHCP中继代理</p>
<p>3550配置dhcp，如果在每个vlan上仅配置一句“IP HELPER-ADDRESS DHCP服务器地址”后，客户机不能从DHCP服务器获取IP地址。 还需要启用DHCP中断功能：service dhcp 然后Ip Dhcp Relay Information Option即可</p>
<p>网络环境：一台3550EMI交换机，划分四个vlan,vlan1 为服务器所在网络，命名为server,IP地址段为192.168.100.0,子网掩码:255.255.255.0,网关:192.168.100.254,域服务器为windows 20003 server,同时兼作DHCP服务器，DNS服务器，IP地址为192.168.100.14,vlan2 IP地址段为192.168.101.0,子网掩码:255.255.255.0,网关:192.168.101.254命名为work01,vlan3 IP地址段为192.168.102.0,子网掩码:255.255.255.0,网关:192.168.102.253. vlan4 IP地址段为192.168.5.0,子网掩码:255.255.255.0,网关:192.168.5.253.<br />
3550上端口1-8划到VLAN 2，端口9-16划分到VLAN 3,端口17-24划分到VLAN 4.</p>
<p>配置命令及步骤如下：</p>
<p>第一步：创建VLAN：<br />
Switch&gt;Vlan Database<br />
Switch(Vlan)&gt;Vlan 1 Name server<br />
Switch(Vlan)&gt;Vlan 2 Name work01<br />
Switch(vlan)&gt;Vlan 3 Name work02<br />
Switch(vlan)&gt;Vlan 4 Name work03</p>
<p>第二步：启用DHCP中继代理：<br />
/*关键一步，若缺少以下两条命令，在VLAN中使用“IP HELPER-ADDRESS DHCP服务器地址”指定DHCP服务器，客户机仍然不能获得IP地址*/<br />
Switch&gt;Enable<br />
Switch＃c onfig t<br />
Switch(Config)Service Dhcp<br />
Switch(Config)Ip Dhcp Relay Information Option</p>
<p>第三步：设置VLAN IP地址：<br />
Switch(Config)&gt;Int Vlan 1<br />
Switch(Config-vlan)Ip Address 192.168.100.254 255.255.255.0<br />
Switch(Config-vlan)No Shut<br />
Switch(Config-vlan)Exit<br />
其它相同<br />
/*注意：由于此时没有将端口分配置到VLAN2，3，4，所以各VLAN会DOWN掉，待将端口分配到各VLAN后，VLAN会起来*/</p>
<p>第四步：设置端口全局参数<br />
Switch(Config)Interface Range Fa 0/1 - 24<br />
Switch(Config-if-range)Switchport Mode Access<br />
Switch(Config-if-range)Spanning-tree Portfast</p>
<p>第五步：将端口添加到VLAN2，3，4中<br />
/*将端口1-8添加到VLAN 2*/<br />
Switch(Config)Interface Range Fa 0/1 - 8<br />
Switch(Config-if-range)Switchport Access Vlan 2</p>
<p>/*将端口9-16添加到VLAN 3*/<br />
Switch(Config)Interface Range Fa 0/9 - 16<br />
Switch(Config-if-range)Switchport Access Vlan 3</p>
<p>/*将端口17-24添加到VLAN 4*/<br />
Switch(Config)Interface Range Fa 0/17 - 24<br />
Switch(Config-if-range)Switchport Access Vlan 4<br />
Switch(Config-if-range)Exit</p>
<p>/*经过这一步后，各VLAN会起来*/</p>
<p>第六步：在VLAN3和4中设定DHCP服务器地址<br />
/*VLAN 1中不须指定DHCP服务器地址*/<br />
Switch(Config)Int Vlan 3<br />
Switch(Config-vlan)Ip Helper-address 192.168.100.10<br />
Switch(Config)Int Vlan 4<br />
Switch(Config-vlan)Ip Helper-address 192.168.100.10</p>
<p>第七步:启用路由<br />
/*路由启用后,各VLAN间主机可互相访问,若需进一步控制访问权限,则需应用到访问控制列表*/<br />
Switch(Config)Ip Routing</p>
<p>第八步：结束并保存配置<br />
Switch(Config-vlan)End<br />
Switch#Copy Run Start</p>
<p>六、      流量控制<br />
class-map match-all VOIP<br />
  match access-group 115<br />
class-map match-any APP<br />
  match access-group 116<br />
class-map match-any SHARE<br />
  match access-group 117<br />
!<br />
!<br />
policy-map qos<br />
  class VOIP<br />
    set ip precedence 5<br />
  class APP<br />
    set ip precedence 3<br />
  class SHARE<br />
    police 2048000 1600000 exceed-action drop<br />
  class class-default<br />
    set ip precedence 0<br />
并在接口上应用：<br />
interface FastEthernet0/48<br />
description To Cisco Router 2610xm<br />
no switchport<br />
ip address 10.0.0.1 255.255.255.252<br />
ip route-cache policy<br />
duplex full<br />
speed 10<br />
service-policy input qos<br />
访问控制列表如下：<br />
access-list 115 permit ip host 192.168.4.250 host 192.168.100.178<br />
access-list 116 permit ip any host 192.168.100.9<br />
access-list 116 permit ip any host 192.168.100.103<br />
access-list 116 permit ip any host 192.168.100.104<br />
access-list 116 permit ip any host 192.168.100.30<br />
access-list 117 permit tcp any any eq 445<br />
access-list 117 permit tcp any any eq 139</p>
<p>七、      策略路由<br />
对于192.168.101.0/24的网络，走ADSL上网<br />
access-list 1 permit 192.168.101.0 0.0.0.255<br />
route-map ADSL permit 10<br />
match ip address 1<br />
set ip default next-hop 192.168.100.249(ADSL路由器)</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=96</wfw:commentRss>
		</item>
		<item>
		<title>Cisco路由器流量控制实例</title>
		<link>http://frsky.net/?p=95</link>
		<comments>http://frsky.net/?p=95#comments</comments>
		<pubDate>Tue, 02 Dec 2008 05:13:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=95</guid>
		<description><![CDATA[Cisco路由器流量控制实例
       网上关于Qos资料太多了，但很多不实用，讲了一大堆理论，下面是我们一子公司的路由器上的配置，供大家参考。其实，只要理解了NBAR、CBWFQ、WRED等意义，流量控制就可以随心配置。
说明：
       一家子公司使用2M专线上网，内部网段为192.168.23.0/24（普通员工）和192.168.24.0/24（总经办所在的VLAN），其中路由器IP地址为：192.168.23.1，内部cisco3560交换机IP为：192.168.23.254。现需要作流量控制，使总经办的流量比较优先，并优先传送一些声音与视频及网管流量。其它的服务如：smtp、pop3及ftp等为低优先级，并禁止bt下载等。
配置如下：
Current configuration : 3590 bytes
!
!
version 12.3
service timestamps debug datetime
service timestamps log datetime
service password-encryption
!
hostname xxxxxx
!
enable secret 5 $44adf#dfdfj090$on
!
clock timezone China 8
ip subnet-zero
no ip source-route
ip cef
!
!
ip name-server 192.168.23.2
ip name-server x.x.x.x
!
no ip bootp server
!
ip nbar pdlm flash:bittorrent.pdlm
class-map match-any premium_class
description For premium
match protocol http
match protocol icmp
match protocol netshow
match protocol pcanywhere
match protocol realaudio
match protocol secure-http
match access-group [...]]]></description>
			<content:encoded><![CDATA[<p>Cisco路由器流量控制实例</p>
<p>       网上关于Qos资料太多了，但很多不实用，讲了一大堆理论，下面是我们一子公司的路由器上的配置，供大家参考。其实，只要理解了NBAR、CBWFQ、WRED等意义，流量控制就可以随心配置。</p>
<p>说明：<br />
       一家子公司使用2M专线上网，内部网段为192.168.23.0/24（普通员工）和192.168.24.0/24（总经办所在的VLAN），其中路由器IP地址为：192.168.23.1，内部cisco3560交换机IP为：192.168.23.254。现需要作流量控制，使总经办的流量比较优先，并优先传送一些声音与视频及网管流量。其它的服务如：smtp、pop3及ftp等为低优先级，并禁止bt下载等。</p>
<p>配置如下：<br />
Current configuration : 3590 bytes<br />
!<br />
!<br />
version 12.3<br />
service timestamps debug datetime<br />
service timestamps log datetime<br />
service password-encryption<br />
!<br />
hostname xxxxxx<br />
!<br />
enable secret 5 $44adf#dfdfj090$on<br />
!<br />
clock timezone China 8<br />
ip subnet-zero<br />
no ip source-route<br />
ip cef<br />
!<br />
!<br />
ip name-server 192.168.23.2<br />
ip name-server x.x.x.x<br />
!<br />
no ip bootp server<br />
!<br />
ip nbar pdlm flash:bittorrent.pdlm</p>
<p>class-map match-any premium_class<br />
description For premium<br />
match protocol http<br />
match protocol icmp<br />
match protocol netshow<br />
match protocol pcanywhere<br />
match protocol realaudio<br />
match protocol secure-http<br />
match access-group 111<br />
注：以上有省略，嘿嘿!</p>
<p>class-map match-any normal_calss<br />
description For normal<br />
match protocol ftp<br />
match protocol imap<br />
match protocol pop3<br />
match protocol smtp<br />
match access-group 110</p>
<p>class-map match-any bt_download<br />
description For drop<br />
match protocol bittorrent<br />
!<br />
!<br />
policy-map qos_policy_map</p>
<p>class premium_class<br />
bandwidth percent 50<br />
random-detect<br />
random-detect exponential-weighting-constant 4<br />
police cir 2000000 bc 10000 be 10000<br />
conform-action transmit<br />
exceed-action transmit</p>
<p>class normal_calss<br />
bandwidth percent 25<br />
random-detect<br />
random-detect exponential-weighting-constant 4<br />
police cir 2000000 bc 2000 be 2000<br />
conform-action transmit<br />
exceed-action drop</p>
<p>class bt_download<br />
   drop</p>
<p>!<br />
!<br />
!<br />
!<br />
interface FastEthernet0/0<br />
ip address 192.168.23.1 255.255.255.0<br />
ip verify unicast reverse-path<br />
ip nat inside<br />
ip route-cache same-interface<br />
ip route-cache policy<br />
duplex auto<br />
speed auto<br />
no cdp enable<br />
!<br />
interface Serial0/0<br />
bandwidth 2048<br />
ip address 210.88.44.x 255.255.255.252<br />
ip verify unicast reverse-path<br />
no ip proxy-arp<br />
ip nat outside<br />
rate-limit input 2000000 20000 20000 conform-action transmit exceed-action drop<br />
ip route-cache policy<br />
service-policy output qos_policy_map<br />
no cdp enable<br />
!<br />
ip nat inside source list 10 interface Serial0/0 overload<br />
ip classless<br />
ip route 0.0.0.0 0.0.0.0 210.88.44.y</p>
<p>ip route 192.168.24.0 255.255.255.0 192.168.23.254<br />
no ip http server</p>
<p>!<br />
!<br />
access-list 10 remark NAT<br />
access-list 10 permit 192.168.23.0 0.0.0.255<br />
access-list 10 permit 192.168.24.0 0.0.0.255</p>
<p>access-list 110 remark normal<br />
access-list 110 permit ip 192.168.23.0 0.0.0.255 any</p>
<p>access-list 111 remark premium<br />
access-list 111 permit ip 192.168.24.0 0.0.0.255 any</p>
<p>no cdp run</p>
<p>!<br />
banner motd ^cml system router !!!^C<br />
!<br />
line con 0<br />
exec-timeout 0 0<br />
line aux 0<br />
line vty 0 4<br />
password 7 121A0C0411045D5D7C<br />
login<br />
!<br />
!<br />
!<br />
end</p>
<p>注：互联网带宽为2M，故WRED中的指数加权因子为4，最小阀值为5，最大阀值为17，标记几率分母为1。</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=95</wfw:commentRss>
		</item>
		<item>
		<title>CCIE面试题之答案</title>
		<link>http://frsky.net/?p=94</link>
		<comments>http://frsky.net/?p=94#comments</comments>
		<pubDate>Tue, 02 Dec 2008 05:10:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=94</guid>
		<description><![CDATA[CCIE面试题之答案
前言：
       这里是几个月前在网上转载很多的CCIE面试题，题虽然不难，但如果没有在电信或cisco代理商工作过，仅仅凭书面的知识还是回答不全的。下面是网上的参考答案加上我的一点点补充，以后有时间再补充，先贴出来供大家参考，也让从事相关技术的人自我测试一下。
1.       现在的6509及7609，SUP720交换带宽去到720G，是不是可以说7609/6509 可以取代一部分GSR的地位？
答：从某一部分功能来说是可以的。6509以前主要定位于公司企业局域网核心交换机，而GSR定位于广域网高速核心路由设备。7609的SUP720可以提供720G的高速交换能力，MSFC3和PFC3提供高速路由处理能力和大量FEATURE，再加上现在7600系列上的新的SIP+SPA高速线速板卡，完全可以胜任核心路由设备的工作，最适合作汇聚和业务提供路由器。而随着技术的发展，CRS-1的出现，GSR逐渐从核心往骨干汇聚发展，作为各种高低速线路的汇聚，在这方面7609和GSR都可以。但7609和GSR在体系结构上还是有根本不同，7609是从交换机发展而来，GSR在内部是将数据分解为标准的信元交换，在队列和调度方面也有不同，所以说作为纯核心路由器来说还是GSR更好，因为它经过多年的考验。从价格来说7609还是比较贵的，而GSR某些时候还要便宜。
2.       isis level1 的路由表包括哪此路由？有多个level-1-2出口时，其它路由它从哪里学到，如何选路？
答：ISIS level1和level2 维护LSD和SPF，LEVEL1的路由表是由LEVEL1 LSD通过SPF计算所得，只包括本地AREA的详细路由和与之连接的LEVEL-1-2通过ATT位发来的缺省路由。当有多个LEVEL12是，每个LEVEL12通过对发出的LSP包中的ATT位置1，表示其有到其它AREA的路由，而当LEVEL1路由器收到此LSP是选择最近的LEVEL12路由器转发流量。
3.       MPLS L3 VPN，如果我想让两个不同的VPN作单向互访，怎做？
答：如果是两个VPN的互通，可以将两个VPN的路由信息输出到相同的一个RT，并都导入，可实现互通。如果要单向访问，可建立一个公共VPN，导出两个VPN的RT，两个VPN都可以对公共VPN实现访问。
4.       跨域的MPLS L3 VPN可以谈谈思路吗？
答：RFC2547bis和最新的rfc4364都对其有定义，主要有三种。Option A B C：
Option A： back to back vrf 互连。两个AS间通过VRF 间的背对背的连接，路由可以选择静态或动态路由，这种方法简单实用，适于不同运营商间的连接。
Option B ：MeBGP vpnv4连接两个AS间通过ASBR间建立MeBGP vpnv4，VPN路由通过MBGP承载，具有较好的可扩展性。
Option C： RR间多跳MeBGP两个AS间建立MEBGP，但不是在ASBR上，是在两个AS各自的RR间，这样有较好的可扩展性，灵活性。但较复杂。要解决下一跳问题有标签问题。
5.       MPLS L3 VPN的一个用户，他有上internet的需求，如何实现？有几种实现方法？特点各是什么？
答：有三种。
1、通过VPN访问internet. 传统做法是：设置一个集中的防火墙通过NAT实现INTERNET访问，简单易实现，只是不能对INTERNET流量和VPN流量进行区分，安全存在问题。或者在PE路由器上配置PACK LEAKING 实现。
2、独立的INTERNET访问向每个VPN SITE 提供独立的INTERNET连接线路，由CE路由器实现NAT到INTERNET。要求PE路由器向CE提供独立的线路或虚电路，PE路由器要有访问INTERNE的能力。优点是能将VPN流量和INTERNET流量分开。
3、 通过单独的VPN实现INTERNET连接，建立一个单独的VPN，将INTERNET缺省路由和部分路由注入，在需要INTERNET访问SIET相连的PE路由器上实现VPN互通，从而访问INTERNET。比较复杂，但可支持各种INTERNET访问要求。建议采用这种
6.       [...]]]></description>
			<content:encoded><![CDATA[<p>CCIE面试题之答案</p>
<p>前言：<br />
       这里是几个月前在网上转载很多的CCIE面试题，题虽然不难，但如果没有在电信或cisco代理商工作过，仅仅凭书面的知识还是回答不全的。下面是网上的参考答案加上我的一点点补充，以后有时间再补充，先贴出来供大家参考，也让从事相关技术的人自我测试一下。</p>
<p>1.       现在的6509及7609，SUP720交换带宽去到720G，是不是可以说7609/6509 可以取代一部分GSR的地位？<br />
答：从某一部分功能来说是可以的。6509以前主要定位于公司企业局域网核心交换机，而GSR定位于广域网高速核心路由设备。7609的SUP720可以提供720G的高速交换能力，MSFC3和PFC3提供高速路由处理能力和大量FEATURE，再加上现在7600系列上的新的SIP+SPA高速线速板卡，完全可以胜任核心路由设备的工作，最适合作汇聚和业务提供路由器。而随着技术的发展，CRS-1的出现，GSR逐渐从核心往骨干汇聚发展，作为各种高低速线路的汇聚，在这方面7609和GSR都可以。但7609和GSR在体系结构上还是有根本不同，7609是从交换机发展而来，GSR在内部是将数据分解为标准的信元交换，在队列和调度方面也有不同，所以说作为纯核心路由器来说还是GSR更好，因为它经过多年的考验。从价格来说7609还是比较贵的，而GSR某些时候还要便宜。<br />
2.       isis level1 的路由表包括哪此路由？有多个level-1-2出口时，其它路由它从哪里学到，如何选路？<br />
答：ISIS level1和level2 维护LSD和SPF，LEVEL1的路由表是由LEVEL1 LSD通过SPF计算所得，只包括本地AREA的详细路由和与之连接的LEVEL-1-2通过ATT位发来的缺省路由。当有多个LEVEL12是，每个LEVEL12通过对发出的LSP包中的ATT位置1，表示其有到其它AREA的路由，而当LEVEL1路由器收到此LSP是选择最近的LEVEL12路由器转发流量。<br />
3.       MPLS L3 VPN，如果我想让两个不同的VPN作单向互访，怎做？<br />
答：如果是两个VPN的互通，可以将两个VPN的路由信息输出到相同的一个RT，并都导入，可实现互通。如果要单向访问，可建立一个公共VPN，导出两个VPN的RT，两个VPN都可以对公共VPN实现访问。<br />
4.       跨域的MPLS L3 VPN可以谈谈思路吗？<br />
答：RFC2547bis和最新的rfc4364都对其有定义，主要有三种。Option A B C：<br />
Option A： back to back vrf 互连。两个AS间通过VRF 间的背对背的连接，路由可以选择静态或动态路由，这种方法简单实用，适于不同运营商间的连接。<br />
Option B ：MeBGP vpnv4连接两个AS间通过ASBR间建立MeBGP vpnv4，VPN路由通过MBGP承载，具有较好的可扩展性。<br />
Option C： RR间多跳MeBGP两个AS间建立MEBGP，但不是在ASBR上，是在两个AS各自的RR间，这样有较好的可扩展性，灵活性。但较复杂。要解决下一跳问题有标签问题。<br />
5.       MPLS L3 VPN的一个用户，他有上internet的需求，如何实现？有几种实现方法？特点各是什么？<br />
答：有三种。<br />
1、通过VPN访问internet. 传统做法是：设置一个集中的防火墙通过NAT实现INTERNET访问，简单易实现，只是不能对INTERNET流量和VPN流量进行区分，安全存在问题。或者在PE路由器上配置PACK LEAKING 实现。<br />
2、独立的INTERNET访问向每个VPN SITE 提供独立的INTERNET连接线路，由CE路由器实现NAT到INTERNET。要求PE路由器向CE提供独立的线路或虚电路，PE路由器要有访问INTERNE的能力。优点是能将VPN流量和INTERNET流量分开。<br />
3、 通过单独的VPN实现INTERNET连接，建立一个单独的VPN，将INTERNET缺省路由和部分路由注入，在需要INTERNET访问SIET相连的PE路由器上实现VPN互通，从而访问INTERNET。比较复杂，但可支持各种INTERNET访问要求。建议采用这种<br />
6.       L3 VPN与L2 VPN各自的特点是怎样？你觉得哪一种模式运营起来比较有前景？<br />
答：L3 VPN 的PE路由器需要维护客户VPN的路由信息，要实现各VPN的路由选择和维护，而L2 VPN只在客户间建立透明的二层通道，不维护三层的信息，相对没有L3 VPN复杂。L3 VPN已经在现实环境中应用多年，比较成熟，适合多SITE的复杂的用户，MPLS L2 VPN用于替代传统的二层FR、ATM等技术，适合点到点的互连或少量SITE的连接。L2 VPN由于维护较方便，性价比高，最近几年应发展迅速，而传统的L3 VPN也不会在短时间淘汰。<br />
7.       ISIS与OSPF的区别谈一谈吧，各个方面。<br />
答：它们有很多共同之处，都是链路状态路由协议，都使用SPF算法，VSLM 快速会聚。从使用的目的来说没有什么区别。从协议实现来说OSPF其于TCP/ ip协议簇，运行在IP层上，端口号89；ISIS基于ISO CLNS，设计初是为了实现ISO CLNP路由，在后来加上了对IP路由的支持。从具体细节来说：<br />
1：区域设计不同，OSPF采用一个骨干AREA0与非骨干区域，非骨干区域必须与AREAO连接。ISIS由L1 L2 L12路由器组成的层次结构，它使用的LSP要少很多，在同一个区域的扩展性要比OSPF好。<br />
2 OSPF有很多种LSA，比较复杂并占用资源，而ISIS的LSP要少很多，所以在CPU占用和处理路由更新方面，ISIS要好一些。<br />
3 isis 的定时器允许比OSPF更细的调节，可以提高收敛速度。华为、Cisco网络技术论坛<br />
4 OSPF数据格式不容易增加新的东西，要加，就需要新的LSA，而ISIS可以很容易的通过增加TLV进行扩展，包括对IPV6等的支持。<br />
5 从选择来说，ISIS更适合运营商级的网络，而OSPF非常适合企业级网络。<br />
8.       一个骨干网或城域网选ISIS及OSPF基于什么理由？<br />
答：从可用性来说，两种IGP协议都可以，但对于具体情况，经过分析，可能得出选哪种协议更优一些：<br />
l         从稳定和可靠性来看：骨干网要求路由协议的高稳定性和可靠性，以及快速收敛。OSPF协议是基于IP层的，所以其只能支持IP网络，且网络上一些基于IP的攻击会影响到OSPF的正常运行。ISIS是直接运行在链路层上的，其可以承载多种网络类型，且在预防网络攻击方面也有一些天然的优势。<br />
l         从支持的网络规模来看：OSPF、ISIS都有网络分层的概念，也都有区域的概念，OSPF有骨干区域0和分支区域，ISIS有相应的Level2、Level1的概念。OSPF有普通区域、Stub区域、Total Stub区域、NSSA区域等区域类型，而IS-IS 从功能上看它就是一个OSPF 的简化版本，只实现了骨干区（LEVEL2） 和STUB 区(LEVEL1)，由于其LEVEL1访问其他区域网络是采用到最近的L1/L2 路由器方式，容易产生路由次优化问题, 这样某些组网时就需要借助其他的方法来实现某些功能，如：在构建MPLS VPN的过程中就需要采用路由渗透，造成实现和维护复杂。由于ISIS计算路由的时候采用PRC计算，ip前缀作为最短 生成树的叶子节点，而OSPF是围绕链路建立的，在相同大小的区域，ISIS比OSPF更加稳定且消耗资源少，相比OSPF支持的网络规模更大。<br />
l         从灵活性来看：OSPF协议比较灵活，协议是基于接口的，支持的网络类型全面，且技术成熟，在城域网中，使用IGP用来传播用户路由，组网设备杂，关注的是协议的灵活性兼容性，以及能否满足大量用户复杂路由控制的需求，这些是OSPF 的强 项，建议使用OSPF。对于新维护方面OSPF协议在城域网中得到了广泛的应用，尤其是早期的网络维护人员对OSPF协议相当熟悉；<br />
l         从扩展性来看：ISIS结构严谨，运行稳定，IS-IS路由器只能属于一个区域，并且不提供对NBMA、P2MP接口的直接支持。ISIS可扩展性更好：ISIS能支持多种网络层协议（ OSPF仅支持IP协议）；ISIS区域能平滑地平移、分割、合并，流量不中断；ISIS是基于TLV的，协议本身扩展容易。最近几年，在各大运营商的骨干网络中大量使用了ISIS协议，在选取协议时，需要考虑原有网络中运行的是何种协议，如目前某些运营商在骨干层次采用ISIS，而在城域网内部采用OSPF协议，为了保护网络的延续性，在选取协议类型时需要予以考虑。新建的网络，如果所有设备都支持ISIS，可以考虑ISIS。<br />
9.       BGP选路原则常用是哪些？在骨干网与城域网间如何搭配一块使用？<br />
答：BGP有很多属性，用于路由选择的有9个左右，常用的有LCAL PREFERENCE,AS-PATH,MED,METRIC,COMMUNITY这几个。在骨干网与城域网连接中，骨干网向城域网发送缺省路由或部分明细路由，城域网将本地路由信息发到骨干网上。接收路由主要通过设置lcoal preference控制上行流量分担，如果骨干网发过来的明细路由带有MED，也可以通过MED值控制。发布出去的路由通过MED AS PATH控制回程流量的分担。发布路由可以设置COMMUNITY表示路由起源。在有多条出口链路时通过BGP实现流量分担。<br />
10.   如果BGP加上max path，会在哪个BGP选路属性之前应用这个选项？<br />
答：在最后一个BGP router id之前。<br />
11.   为什么骨干网pop及城域网出口要作next-hop-self？<br />
答：骨干网与城域网之间通过EBGP连接，而城域网收到的骨干网路由在发给内部IBGP邻居时不会改变路由的下一跳，下一跳的地址为骨干网设备地址，而IBGP内部路由器也没有其路由信息，所有 路由下一跳不可达，只有在城域网RR将路由发给IBGP邻居时要加next-hop-self，改变路由的下一跳，路由才可达。<br />
12.   两个AS之间，有四台路由器口字型互联，其中一台路由器上从EBGP学到一个网络，又从IBGP学到同一个网络，选路哪个？是哪个属性影响？如果我在IBGP过来那个加上MED小于从EBGP过来的，又选哪个？为什么？<br />
答：选EBGP那一条，如果加了MED，则选MED低的那个。<br />
13.    local-pre与weight的区别是什么？<br />
答：Weight 是CISCO专有的，LOCAL-PRE是公认必遵的BGP属性。Weight 只在本地ROUTER上有用，不可传递；而LOCAL-PRE用于一个AS内部，可在整个AS内传递。它们都是数值大的路由选中，而CISCO路由器中WEIGHT决策在LOCAL-PRE前。<br />
14.   BGP能不能实现负载均衡？如果可以，有哪些方法？<br />
答：可以。对于EBGP可以通过设置EBGP-MULTIHOP，通过相等的IGP METRIC实现。对于IBGP可以通过配置muximum-paths，使其在等值的IGP METRIC链路上实现。<br />
15.   多个AS之间，可不可以比较MED？如可以，需要前提条件吗？如有，前提条件是什么？<br />
答：默认是不比较来自不同AS的路由的MED值，但可设置bgp always-compare-med使其对来自不同AS的路由的MED值进行比较。<br />
16.   MED能不能和AS内的IGP度量值结合起来？如可以，如何做？<br />
答：设置Med的route-map 配置set metric internal<br />
17.   割接限定回退的时间还有十分钟，割接还未成功，局方已经催你回退了，但你觉得这些问题你再努力5分钟可能会解决，你的选择是什么？<br />
答：立即回退<br />
18.   骨干网的QoS，如何部署？你认为什么骨干网什么情况下是有拥塞发生了？<br />
答：对于电信级骨干网，轻载是骨干网上实现QOS的最好方法，保持流量低于带宽的50%，在需要时增加带宽，并且通过控制接入的流量在稳定的范围内。也可以对流量进行简单的分类，通过DIFF-SERV实现不同流量的QOS，对于复杂的QOS需求，可以使用TE实现。对于企业级骨干网，WAN链路为较低速率，此时可通过DIFF-SERV实现QOS，但如果流量已达到90%以前，QOS的实施对整个网络质量不能很好的改善。一般而言，在网络设备能全线速和BUFFER足够的情况一下，骨干网一般用POS接口，骨干网流量达到50%以上就应规划增加带宽，达到60%就比较紧张，70%网络质量可能开始下降，80%就有拥塞发生了。可以通过延迟和延迟抖动测试出来。<br />
19.   对于工程及维护来说，你觉得L3网络和L2网络哪个比较好？<br />
答：对于工程实施来说，L2网络简单。对于网络管理来说，L3要可控一些。<br />
20.    L3网络与L2网络对环路的处理各是什么样的机制？<br />
答：L3网络通过运行的路由协议的算法保证形成一个无环的拓扑。L2是通过STP 实现<br />
21.   一般情况下，L2交换机的生成树有多少数量？<br />
答：2950 支持64个PVST+ instances 16个 MST  3550 是 128WH pvst+instances  65个MST<br />
22.   3550的生成树模式是什么？生成树数量是怎样的？<br />
答：支持128个PVST+,65个MST，都支持PVST 和MSTP。<br />
23.   跟据你的经验，GE的端口，当流量达到多少时，你可以认为是有拥塞发生了？2.5G POS口，当流量达到多少时，你可以认为有拥塞？<br />
答：对于GE端口，如果流量达到900M时可视为发生拥塞，而对于POS口，如果硬件板卡都是线速，并且BUFFER足够，当流量达到达2G左右时可视为发生拥塞.。</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=94</wfw:commentRss>
		</item>
		<item>
		<title>pf, pfsync and CARP on FreeBSD 6.2</title>
		<link>http://frsky.net/?p=93</link>
		<comments>http://frsky.net/?p=93#comments</comments>
		<pubDate>Fri, 17 Oct 2008 05:19:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[SOftware]]></category>

		<guid isPermaLink="false">http://frsky.net/?p=93</guid>
		<description><![CDATA[Redundant Failover firewall with pf, pfsync and CARP on FreeBSD 6.2
Posted by Chris Barnes on Friday, June 15, 2007
This is a step by step tutorial that should take most of a day. I&#8217;m posting this here mostly as a reminder so that I can come back and read it when I need to build another [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold">Redundant Failover firewall with pf, pfsync and CARP on FreeBSD 6.2</span></p>
<p class="author">Posted by <cite>Chris Barnes</cite> <abbr title="2007-06-15T11:01:00-04:00" class="published"><span title="Fri, 15 Jun 2007 15:01:00 GMT" class="typo_date">on Friday, June 15, 2007</span></abbr></p>
<p>This is a step by step tutorial that should take most of a day. I&#8217;m posting this here mostly as a reminder so that I can come back and read it when I need to build another firewall but hopefully it will be helpful to someone else also. If you find this tutorial useful or if you find anything wrong with it, send me an email <a href="mailto:hammockintahiti@gmail.com">hammockintahiti@gmail.com</a>.</p>
<h4>Install FreeBSD</h4>
<p>Download the disc 1 and disc 2 from <a href="ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/6.2">ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/6.2</a></p>
<p>Burn the iso images to cds and boot the target machine with disc 1.</p>
<p>Start a Standard installation.</p>
<p>Highlight any partitions and hit &#8220;d&#8221; to delete them, then hit &#8220;a&#8221; to use the entire disk, then hit &#8220;q&#8221; to continue.</p>
<p>Choose Standard for no boot manager.</p>
<p>Create partitions. You can adjust the sizes of the partitions based on the size of your drive. The /usr/local and /usr/home partitions can go as low as 128MB since this won&#8217;t be a common-user system and there won&#8217;t be a lot of user-specific files or binaries&#8230;but the /usr partition should never go below 2,000MB since that&#8217;s where all of your kernel source code and ports tree is located. Here&#8217;s a partition scheme if you have a 6GB drive:</p>
<blockquote><p>486MB swap partition (or at least 2x your RAM)<br />
512MB file system mounted as /<br />
512MB file system mounted as /tmp<br />
1267MB file system mounted as /var<br />
3115MB file system mounted as /usr<br />
128MB file system mounted as /usr/local<br />
128MB file system mounted as /usr/home</p></blockquote>
<p>Press q to continue.</p>
<p>Highlight Kern-Developer and press space bar.</p>
<p>When asked about installing the ports collection choose yes.</p>
<p>Highlight exit and press enter.</p>
<p>Choose CD/DVD as the install media.</p>
<p>Last Chance, are you sure? Yes</p>
<p>When you see Congradulations, hit ok.</p>
<h4>FreeBSD Post-Install configuration</h4>
<p>Would you like to configure any ethernet or SLIP/PPP network devices? Yes</p>
<p>Highlight your device that is connected to the internet and press enter.</p>
<p>Do you want to try IPv6? No</p>
<p>Do you want to try DHCP? Yes</p>
<p>Verify network info and update if necessary.</p>
<p>Do you want this machine to function as a gateway? Yes</p>
<p>Do you want to configure inetd and the network services that it provides? No</p>
<p>Would you like to enable SSH login? Yes</p>
<p>Do you want to have anonymous FTP access to this machine? No</p>
<p>Do you want to configure this machine as an NFS Server: No</p>
<p>Do you want to configure this machine as an NFS Client: No</p>
<p>Would you like to customize your system console settings? No</p>
<p>Would you like to set this machine&#8217;s time zone now? Yes</p>
<p>Is your machine&#8217;s CMOS clock is set to UTC? No</p>
<p>Select the appropriate time zone - by region, country, and then the applicable time zone.</p>
<p>Would you like to enable Linux Binary compatibility? No</p>
<p>Does your system have a PS/2, serial, or bus mouse? Yes (unless, of course, it doesn&#8217;t&#8230;)</p>
<p>Would you like to browse the ports collection? Yes</p>
<h4>Install cvsup and bash</h4>
<p>cvsup will be used to keep your system up to date.</p>
<p>Highlight net and press enter.</p>
<p>Highlight cvsup-without-gui and press space bar.</p>
<p>Tab to ok and press enter.<br />
bash is a shell that we will use instead of the default sh</p>
<p>Highlight shells and press enter.</p>
<p>Highlight bash-2 and press space bar.</p>
<p>Tab to ok and press enter.<br />
Tab to Install and press enter.</p>
<p>Review your selections and press enter to install.</p>
<p>Would you like to add any user accounts? Yes (we need at least one so we can dis-allow root ssh access and require you to login as an unprivilaged user and su to root)</p>
<p>Highlight User and press enter.</p>
<p>Type the username, password, full name, and make the member group 0. (this is important so that your new user will be in the &#8216;wheel&#8217; group and they will be able to su to root. Also make the login shell /usr/local/bin/bash (I will create a user with the username admin so if you do the same you can follow the rest of this tutorial verbatim, otherwise just change admin to your username every time I use it later.</p>
<p>Set the root password.</p>
<p>Would you like to visit the general configuration menu for a chance to set any last options? Yes</p>
<p>Go to network then ntupdate and choose a server near you.</p>
<p>Highlight exit and press enter. (do this twice to get to the main menu)</p>
<p>Tab over to Exit Install and hit enter.</p>
<p>(System Reboots)</p>
<h4>Make &#8220;bash&#8221; the default shell for &#8216;root&#8217; and perform an initial set up of root&#8217;s bash environment.</h4>
<p>Log in as your non-privaleged user account. You should see a &#8216;bash-2.05b$&#8217; prompt&#8230;indicating that bash was successfully installed. After you log in, then type &#8217;su&#8217; to switch user to root. Enter the root password.</p>
<p>Type vipw and press enter.</p>
<p>Change the default shell from /bin/csh (at the end of the first line) to /usr/local/bin/bash.</p>
<p>If you like, you can change root&#8217;s unoffical name from &#8216;Charlie &amp;&#8217; to &#8216;Super-User&#8217; or whatever you like. When you get mail from root, it will be marked as being from the name that you enter here.</p>
<p>Verify that your changes are successful. Press <alt></alt>-F2 to get another terminal, then log in as root. Verify that you&#8217;re presented with the &#8216;bash-2.05b#&#8217; prompt. If you are, then log out and go back to the 1st virtual terminal to continue working. If you don&#8217;t see the bash prompt, then you need to go back to the previous step and figure out what you did wrong.<br />
Create a file named .bashrc in /root that contains the following.</p>
<blockquote>
<pre>umask 077
PS1="[u@h W]\$ "
alias ls='ls -alFG'</pre>
</blockquote>
<p>Also create a file named .bash_profile in /root that contains the following.</p>
<blockquote>
<pre>PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:$HOME/bin; export PATH
umask 077
PS1="[u@h W]\$ "
alias ls='ls -alFG'</pre>
</blockquote>
<p>Change the permissions on both files.</p>
<blockquote>
<pre>chmod 600 .bashrc
chmod 600 .bash_profile</pre>
</blockquote>
<p>Test your settings again at the 2nd virtual terminal. Log in as root, verify you&#8217;re using the bash shell, your cursor line looks different (it has your userid and current working directory), and that you have colorized directory listings. Close that session, return to the 1st virtual terminal, log out, and log back in and su to root.</p>
<p>Copy the files to your non privilaged user change the ownership of the new copies.</p>
<blockquote>
<pre>cp /root/.bashrc /usr/home/admin/.bashrc
cp /root/.bash_profile /usr/home/admin/.bash_profile
chown admin /usr/home/admin/.bashrc
chown admin /usr/home/admin/.bash_profile</pre>
</blockquote>
<h4>Redirect root&#8217;s email to your email account.</h4>
<blockquote>
<pre>vi /etc/aliases</pre>
</blockquote>
<p>Uncomment # root: <a href="mailto:me@my.domain">me@my.domain</a> and change <a href="mailto:me@mydomain">me@mydomain</a> to your email address.</p>
<p>Save and exit.</p>
<p>Update the email alias database.</p>
<blockquote>
<pre>newaliases</pre>
</blockquote>
<h4>Configure cvsup and update your source tree &amp; ports collection.</h4>
<p>After you configure cvsup and update your source and ports collection, you will want to re-run cvsup every once in a while to ensure your sources are up to date, then recompile your kernel &amp; system binaries to ensure you are using the latest versions with security patches applied.</p>
<blockquote>
<pre>cp /usr/share/examples/cvsup/stable-supfile /etc
chmod 600 /etc/stable-supfile
vi /etc/stable-supfile</pre>
</blockquote>
<p>Type &#8220;:set num&#8221; in vi to see line numbers</p>
<p>Change line 68 to point to a CVS server near you. Here you&#8217;ll find a list of CVSup servers <a href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvsup.html#CVSUP-MIRRORS">http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvsup.html#CVSUP-MIRRORS</a>. I ususlly go with cvsup2 or 3 because the main site reaches the maximum number of simultaneous users often.</p>
<p>Add these lines at the bottom of the file:</p>
<blockquote>
<pre>ports-net tag=CHANGE_THIS.FreeBSD.org
ports-shells tag=CHANGE_THIS.FreeBSD.org</pre>
</blockquote>
<p>Syncronize your source tree with the CVS server&#8230;should take 30-60 minutes</p>
<blockquote>
<pre>cvsup /etc/stable-supfile</pre>
</blockquote>
<p>Configure a custom kernel with support for ph, phsync, pflog, and carp</p>
<blockquote>
<pre>cd /usr/src/sys/i386/conf
cp GENERIC FIREWALL
vi FIREWALL</pre>
</blockquote>
<p>In line 2 of the file (part of the main comment block) change the word, GENERIC, to your hostname, FIREWALL.</p>
<p>On line 19 of the file (still part of the main comment block), change the word, GENERIC, to your hostname, FIREWALL</p>
<p>On lines 22-24, comment out the &#8220;cpu&#8221; lines so that only the one for your specific chip is left.</p>
<p>On line 25, change the value of the ident parameter so that it&#8217;s your hostname, FIREWALL</p>
<p>Add the following lines to the bottom of the file.</p>
<blockquote>
<pre># pf support
device pf
device pfsync
device pflog
device carp</pre>
</blockquote>
<p>Recompile your kernel to the updated stable version. (make buildworld will take about an hour and make buildkernel will take about 20 minutes)</p>
<blockquote>
<pre>[root@firewall /]# cd /usr/src
[root@firewall src]# echo "KERNCONF=FIREWALL" &gt;&gt; /etc/make.conf
[root@firewall src]# make buildworld
[root@firewall src]# make buildkernel
[root@firewall src]# make installkernel</pre>
</blockquote>
<h4>Configure the SSH daemon and your user&#8217;s DSA key files.</h4>
<p>Modify the SSH daemon configuration file, /etc/ssh/sshd_config, so that it reads as follows. The modified lines are in red. I&#8217;m using port 8081 for ssh access instead of the usual port 21. In the past I have had issues with hackers trying to use brute force tactics on my standard ports if they were open.</p>
<blockquote>
<pre><font color="#ff0000">Port 8081</font>
<font color="#ff0000">Protocol 2</font>
#AddressFamily any
<font color="#ff0000">ListenAddress 192.168.1.1 </font># Put your internal interface&#8217;s address here
#ListenAddress :: 

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
<font color="#ff0000">LogLevel VERBOSE</font>

# Authentication:

#LoginGraceTime 2m
<font color="#ff0000">PermitRootLogin no</font>
<font color="#ff0000">StrictModes yes</font>
#MaxAuthTries 6

<font color="#ff0000">RSAAuthentication yes</font>
<font color="#ff0000">PubkeyAuthentication yes</font>
<font color="#ff0000">AuthorizedKeysFile .ssh/authorized_keys</font>

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
<font color="#ff0000">RhostsRSAAuthentication no</font>
# similar for protocol version 2
<font color="#ff0000">HostbasedAuthentication no</font>
# Change to yes if you don&#8217;t trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
<font color="#ff0000">IgnoreUserKnownHosts yes</font>
# Don&#8217;t read the user&#8217;s ~/.rhosts and ~/.shosts files
<font color="#ff0000">IgnoreRhosts yes</font>

# Change to yes to enable built-in password authentication.
<font color="#ff0000">PasswordAuthentication no</font>
<font color="#ff0000">PermitEmptyPasswords no</font>

# Change to no to disable PAM authentication
<font color="#ff0000">ChallengeResponseAuthentication no</font>

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to &#8216;no&#8217; to disable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of &#8220;PermitRootLogin without-password&#8221;.
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to &#8216;no&#8217;.
<font color="#ff0000">UsePAM no</font>

<font color="#ff0000">AllowTcpForwarding no</font>
<font color="#ff0000">GatewayPorts no</font>
<font color="#ff0000">X11Forwarding no</font>
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
<font color="#ff0000">PrintLastLog yes</font>
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no

# no default banner path
#Banner /some/path

# override default of no subsystems
Subsystem sftp /usr/libexec/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# ForceCommand cvs server
<font color="#ff0000">AllowUsers admin </font># Substitute your non-privilaged user for admin</pre>
</blockquote>
<p>Generate an SSH key (version 2) for your user, by performing the following steps:</p>
<blockquote>
<pre>[root@firewall /root]# su - admin          *** substitute your non-privileged userid for 'admin'
[admin@firewall admin]$ ssh-keygen -d   *** then accept the default DSA key name &amp; enter a passphrase (twice)</pre>
</blockquote>
<p>Add the public copy of your user&#8217;s version 2 key to their own authorized_keys file by typing the following steps:</p>
<blockquote>
<pre>[admin@firewall admin]$ cd .ssh
[admin@firewall .ssh]$ cat id_dsa.pub &gt; authorized_keys</pre>
</blockquote>
<p>Copy your user&#8217;s private &amp; public keys to other systems that you&#8217;ll be using to SSH to your new firewall from. By default, the private &amp; public key go into a user&#8217;s &#8216;.ssh&#8217; directory on those systems. Without the private key on those remote systems, your firewall will not accept connections from them. If you&#8217;re new to FreeBSD and need to know how to access the floppy drive, follow the following steps.</p>
<blockquote>
<pre>[root@firewall root]# mkdir /mnt/floppy                     # This will make an empty mount point to mount the floppy to
[root@firewall root]# mount -t msdosfs /dev/fd0 /mnt/floppy # Insert a DOS-formatted floppy before you do this
[root@firewall root]# cd /mnt/floppy
[root@firewall floppy]# cp /home/admin/.ssh/id_dsa* .       # Copies all of your user's ssh key info to the floppy
[root@firewall floppy]# ls                                  # List the contents of the floppy to verify the files are there
[root@firewall floppy]# cd ..
[root@firewall mnt]# umount /mnt/floppy                     # Unmount the floppy</pre>
</blockquote>
<p>Now that you&#8217;ve copied your user&#8217;s private &amp; public keys to another system, remove them from your user&#8217;s .ssh directory on the firewall. This is only a precaution so that it can&#8217;t be stolen by a hacker and compromised.</p>
<p>Open up your /etc/hosts.allow file, delete all of the lines, and ensure that it reads as follows. Note that 192.168.1.0 is the address space of your internal network in this example. If you&#8217;re using a different internal address space (e.g. 10.10.10.0), then make the appropriate modifications.</p>
<blockquote>
<pre># hosts.allow access control file for "tcp wrapped" applications.
ALL : localhost 127.0.0.1 : allow
sshd : 192.168.1.0/255.255.255.0 : allow
ALL : ALL : deny
# If you want to allow a specific computer on the Internet to SSH into your
# system, replace the 'sshd' line above with one like this...but subsitute
# the X.X.X.X and subnet mask to suit your needs (e.g. one computer, entire subnet
# etc.). Also, make sure you allow inbound SSH from that same host/subnet
# in your /etc/ipf.rules file.
# sshd : 192.168.1.0/255.255.255.0 X.X.X.X/255.255.255.255 : allow</pre>
</blockquote>
<h4>Install and configure AIDE (Advanced Intrusion Detection Environment)</h4>
<blockquote>
<pre>[root@firewall /root]# cd /usr/ports/security/aide
[root@firewall aide]# make install clean
[root@firewall aide]# cp /usr/local/etc/aide.conf.sample /var/db/aide/aide.conf
[root@firewall aide]# cd /var/db/aide
[root@firewall aide]# aide --init
[root@firewall aide]# mv databases/aide.db.new databases/aide.db</pre>
</blockquote>
<p>Create a cron job to check the integrity of your system every Sunday at 4AM:</p>
<blockquote>
<pre>[root@firewall /root]# cd /etc
[root@firewall /etc]# vi crontab</pre>
</blockquote>
<p>Add the following line to the file:</p>
<blockquote>
<pre>0   4   *   *   7    root   /usr/local/bin/aide --check</pre>
</blockquote>
<h4>Restrict crontab access/usage</h4>
<p>Create the file /var/cron/allow and add the following lines to it. Be sure to substitute &#8216;newuser&#8217; for whatever your non-privileged user account is.</p>
<blockquote>
<pre>root
newuser</pre>
</blockquote>
<p>Edit /etc/crontab and comment out the &#8216;at&#8217; job that runs every 5 minutes.</p>
<blockquote>
<pre>*/5 * * * * root /usr/libexec/atrun</pre>
</blockquote>
<p>Chmod your /etc/crontab file so that it is only readable by root.</p>
<blockquote>
<pre>[root@firewall /etc]# chmod 600 /etc/crontab</pre>
</blockquote>
<h4>Edit your /etc/rc.conf to look like this</h4>
<p>This is my rc.conf file. Your network interfaces will be named differently if you have different cards (e.g. xl0 and xl1 are 3com network cards in my machine and rl0 is an integrated NE2000 network card)</p>
<blockquote>
<pre>icmp_drop_redirects="YES"
ntpdate_enable="YES"
ntpdate_flags="north-america.pool.ntp.org"
sshd_enable="YES"
usbd_enable="YES"
syslogd_flags="-ss"
sshd_flags="-4"
pf_enable="YES"
pf_rules="/etc/pf.conf"
pf_flags=""
pflog_enable="YES"
pflog_logfile="/var/log/pflog"
pflog_flags=""
kern_securelevel_enable="YES"
kern_securelevel="2"
dhcpd_enable="YES"
gateway_enable="YES"
defaultrouter="208.180.xxx.xxx"
hostname="dell_firewall"
network_interfaces="xl0 xl1 rl0 lo0 pfsync0"
cloned_interfaces="carp0 carp1 carp2"

# Loopback Interface
ifconfig_lo0="inet 127.0.0.1"

# External Public Interface (for the secondary firewall use a different public ip.)
ifconfig_xl0="208.180.xxx.xxx"

# External Public Carp Interface
ifconfig_carp0="208.180.xxx.xxx vhid 1 pass foo"
ifconfig_carp0_alias0="208.180.xxx.xxx vhid 1 pass foo"
ifconfig_carp0_alias1="208.180.xxx.xxx vhid 1 pass foo"

# Internal Interface (for the secondary firewall change the ip address to 192.168.1.251)
ifconfig_xl1="192.168.1.250"

# Internal Carp Interface
ifconfig_carp1="192.168.1.1 vhid 2 pass foo"

# Heartbeat Interface (for the secondary firewall, change the ip address to 10.10.10.251)
ifconfig_rl0="10.10.10.250"

#Heartbeat Carp Interface
ifconfig_carp2="10.10.10.1 vhid 3 pass foo"

# PFSync Interface
ifconfig_pfsync0="up syncif rl0"</pre>
</blockquote>
<h4>Add the following lines to the bottom of /etc/sysctl.conf</h4>
<p>Type ifconfig with no parameters to view your network configuration. Each real interface should have a line that says status: active when the ethernet cable is plugged in. If any of them do not, then preempt will not work. Note that the changes we made to rc.conf do not show up because we have not rebooted yet.</p>
<blockquote>
<pre>net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1

# if one interface fails then all will fail over
net.inet.carp.preempt=1

net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=65536</pre>
</blockquote>
<h4>Configure the main firewall /etc/pf.conf</h4>
<blockquote>
<pre>################################################################################
# Macro and lists
################################################################################
lop_if  ="lo0"
pfs_if  ="dc0"
ext_if  ="xl0"
int_if  ="xl1"
ext_carp ="carp0"

dns_srv  = "{ 208.180.xxx.xxx, 208.180.xxx.xxx }"
int_fw   = "{ 208.180.xxx.xxx 192.168.1.1 }"
chat_srv = "{ 192.168.1.119 }"

# Allowed incoming ICMP types
icmp_types = "{ echorep, echoreq, timex, paramprob, unreach code needfrag }"

# Private networks (RFC 1918)
priv_nets = "{ 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 }"

mail_ports         = "{ 25, 110 }"
web_ports          = "{ www, https }"
ftp_ports          = "{ 8084 9000 9001 }"
firewall_ssh_ports = "{ 8081 }"
web_ssh_ports      = "{ 8082 }"
chat_ports         = "{ 8080 }"
dns_ports          = "{ 53 }"

################################################################################
# Options, scrub and NAT
################################################################################
set block-policy drop
set skip on $lop_if

scrub in

# NAT outgoing connections
nat on $ext_if from $int_if:network to any -&gt; $ext_if

################################################################################
# Redirection
################################################################################
rdr on $ext_if proto tcp from any to $ext_carp port $chat_ports -&gt; $chat_srv
rdr on $ext_if proto tcp from any to $ext_carp port $ftp_ports -&gt; 192.168.1.80
rdr on $ext_if proto tcp from any to $ext_carp port $mail_ports -&gt; 192.168.1.80
rdr on $ext_if proto tcp from any to $ext_carp port $web_ssh_ports -&gt; 192.168.1.80
rdr on $ext_if proto tcp from any to 208.180.xxx.xxx port $web_ports -&gt; 192.168.1.80
rdr on $ext_if proto tcp from any to 208.180.xxx.xxx port $web_ports -&gt; 192.168.1.81
rdr on $ext_if proto tcp from any to 208.180.xxx.xxx port $web_ports -&gt; 192.168.1.82

################################################################################
# Filtering Rules
################################################################################
block log all
antispoof quick for $int_if

pass in quick on $ext_if inet proto tcp from 208.180.xxx.xxx to $int_fw port $firewall_ssh_ports keep state

pass in quick on $int_if inet proto udp from any to any port 123 keep state
pass out quick on $ext_if inet proto udp from any to any port 123 keep state

pass quick on $pfs_if proto pfsync
pass quick proto carp

block in quick on $ext_if from $priv_nets to any
block out quick on $ext_if from any to $priv_nets

pass in quick on $ext_if inet proto tcp from any to $int_if:network port $mail_ports 
     synproxy state
pass out quick on $int_if inet proto tcp from any to $int_if:network port $mail_ports 
     keep state
pass in quick on $int_if inet proto tcp from $int_if:network port $mail_ports to any 
     keep state
pass out quick on $ext_if inet proto tcp from $int_if:network port $mail_ports to any 
     modulate state

pass in  quick on $ext_if inet proto tcp from any to $int_if:network port $web_ports 
     synproxy state
pass out quick on $int_if inet proto tcp from any to $int_if:network port $web_ports 
     keep state

pass in quick on $ext_if inet proto tcp from any to $chat_srv port $chat_ports 
     synproxy state
pass out quick on $int_if inet proto tcp from any to $chat_srv port $chat_ports 
     keep state

pass in  quick inet proto icmp all icmp-type $icmp_types
pass out quick inet proto icmp all

pass in quick on $int_if inet proto { tcp, udp } from $int_if:network to $dns_srv port domain keep state

pass out quick on $ext_if inet proto { tcp, udp } from { $ext_if $int_if:network} to $dns_srv port domain keep state

pass in  quick on $int_if inet proto tcp from $int_if:network to any port $web_ports
pass out quick on $ext_if inet proto tcp from { $ext_if $int_if:network } to any port $web_ports 
     modulate state</pre>
</blockquote>
<h4>Configure the system to mount partitions restrictive</h4>
<p>Modify the /etc/fstab file with vi so that we can change how each partition is mounted&#8230;to ensure that hackers can do at little as possible if they (by chance alone) hack the box. Essentially, we&#8217;re restricting some of the partitions so that they are &#8216;nosuid&#8217;, &#8216;noexec&#8217;, and &#8216;ro&#8217;. The original /etc/fstab should look something like this. Yours might look a little different&#8230;the first column (device names) might be a little different, but that&#8217;s OK. The stuff we&#8217;ll be modifying is in the 4th column.</p>
<blockquote>
<pre># Device    Mountpoint  FStype  Options   Dump  Pass#
/dev/ad0s1b none        swap    sw        0     0
/dev/ad0s1a /           ufs     rw        1     1
/dev/ad0s1d /tmp        ufs     rw        2     2
/dev/ad0s1f /usr        ufs     rw        2     2
/dev/ad0s1h /usr/home   ufs     rw        2     2
/dev/ad0s1g /usr/local  ufs     rw        2     2
/dev/ad0s1e /var        ufs     rw        2     2
/dev/acd0   /cdrom      cd9660  ro,noauto 0     0</pre>
</blockquote>
<p>First, copy the original /etc/fstab file to /etc/fstab.original<br />
Then, make another copy of the /etc/fstab file and call it /etc/fstab.restrictive<br />
Then, modify the /etc/fstab.restrictive file so that it reads as follows:</p>
<blockquote>
<pre># Device    Mountpoint  FStype  Options                 Dump  Pass#
/dev/ad0s1b none        swap    sw                      0     0
/dev/ad0s1a /           ufs     rw,nosuid               1     1
/dev/ad0s1d /tmp        ufs     rw,noexec,nosuid,nodev  2     2
/dev/ad0s1f /usr        ufs     ro                      2     2
/dev/ad0s1h /usr/home   ufs     rw,noexec,nosuid        2     2
/dev/ad0s1g /usr/local  ufs     ro,nosuid               2     2
/dev/ad0s1e /var        ufs     rw,noexec,nosuid        2     2
/dev/acd0   /cdrom      cd9660  ro,noauto               0     0</pre>
</blockquote>
<p>Next, copy your new /etc/fstab.restrictive file and over-write the original /etc/fstab&#8230;so that your &#8220;real&#8221; fstab file has the restrictive settings, and you have the two other config files available (the original and restrictive one).</p>
<blockquote>
<pre>[root@firewall etc]# cp /etc/fstab.restrictive /etc/fstab</pre>
</blockquote>
<p>This will make adding new software, etc. much more difficult since /usr and /usr/local are mounted read-only. This means that programs which try to install their user-land programs in /usr/local/bin will fail during their install programs. And cvsup&#8230;which will try to update the kernel&#8217;s source code in /usr/src and the ports in /usr/ports&#8230;well, they&#8217;re now read-only because they fall under /usr. So, mounting your partitions in a very restrictive way will limit what the hacker can do on your system, but it makes software installs and kernel upgrades more difficult (or impossible&#8230;if the partitions are still mounted in a restrictive way).</p>
<p>Given that, if you want to add new software or upgrade the kernel &amp; ports tree source code, you&#8217;ll need to</p>
<ol>
<li>Change the partition&#8217;s mounting in /etc/fstab back to their original values by copying your /etc/fstab.original file to /etc/fstab.</li>
<li>Bump the kernel security level back down to &#8220;1&#8243; by setting the kern_securelevel paramater in your /etc/rc.conf file, and then</li>
<li>Reboot the machine (this will not cause downtime because the secondary firewall will take over while this machine is rebooting)</li>
<li>Update your sources with cvsup, then make buildworld, make buildkernel, and make installworld</li>
</ol>
<p>Then when you&#8217;re done upgrading, recompiling, and installing, do the steps in reverse:</p>
<ol>
<li>Change the partition&#8217;s mounting in /etc/fstab to their restrictive values by copying your /etc/fstab.restrictive file to /etc/fstab.</li>
<li>Bump the kernel security level back up to &#8220;2&#8243; by setting the kern_securelevel paramater in your /etc/rc.conf file, and then</li>
<li>Reboot the machine</li>
</ol>
<p>This is the price you pay for a VERY, VERY secure machine. Reboot the machine so we can finish the job&#8230;</p>
<blockquote>
<pre>[root@firewall /etc]# shutdown -r now</pre>
</blockquote>
<p>If the system doesn&#8217;t reboot, it means that you probably made an error in the kernel configuration file&#8230;possibly setting the wrong type of CPU. DON&#8217;T PANIC. We can still boot the machine so that you can fix the error. To boot into the original version of the kernel, following the steps, below:</p>
<ol>
<li>Reboot the machine (power off, then on)</li>
<li>When you reboot the machine and get to the bootloader screen, select option 6, &#8220;Escape to loader prompt&#8221;. This will give you an &#8220;OK&#8221; prompt at the bottom of the screen. Boot from your &#8220;old&#8221; kernel.<br />
<blockquote>
<pre>OK unload
OK boot /boot/kernel.old/kernel</pre>
</blockquote>
</li>
<li>After the old kernel boots, you&#8217;ll want to copy the &#8220;old&#8221; kernel to a safe place before you recompile a new kernel. This is an important thing to do since &#8220;kernel.old&#8221; is overwritten when you install a new kernel. To do this, type the following commands:<br />
<blockquote>
<pre>[root@firewall /]# cp -R /boot/kernel.old /boot/kernel.good</pre>
</blockquote>
<p>If subsequent kernel compiles still don&#8217;t work, you can always manually boot off your good kernel from the &#8220;OK&#8221; prompt until you resolve the problem&#8230;just substitute &#8220;kernel.good&#8221; for &#8220;kernel.old&#8221; in the commands listed above.</li>
<li>Now that you&#8217;ve saved a copy of your &#8220;good&#8221; kernel, modify your kernel configuration file and fix whatever was causing the problems, recompile &amp; install, and then reboot and continue with the next step.</li>
</ol>
<p>After the system comes back up, you&#8217;ll want to re-generate the AIDE database and replace the old one. Since you updated the kernal and all of the system binaries, the AIDE database signatures of those files is out of date. If you don&#8217;t update the AIDE database, AIDE will find thousands of &#8220;changes&#8221; to the system binaries when it runs for the first time at 4AM in the morning. To update the database so that it has signatures for the newest kernel &amp; system binaries, etc, just type the following commands:</p>
<blockquote>
<pre>[root@firewall /]# cd /var/db/aide
[root@firewall aide]# aide --init
[root@firewall aide]# mv databases/aide.db.new databases/aide.db</pre>
</blockquote>
<p>After you do this you should have a completely working firewall.</p>
]]></content:encoded>
			<wfw:commentRss>http://frsky.net/?feed=rss2&amp;p=93</wfw:commentRss>
		</item>
	</channel>
</rss>
<!--WEBBOT bot="Script" startspan PREVIEW="Site Meter" -->
<script type="text/javascript" src="http://sm8.sitemeter.com/js/counter.js?site=sm8frsky">
</script>
<noscript>
<a href="http://sm8.sitemeter.com/stats.asp?site=sm8frsky" target="_top">
<img src="http://sm8.sitemeter.com/meter.asp?site=sm8frsky" alt="Site Meter" border="0"/></a>
</noscript>
