<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.11" -->
<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>網絡技術日誌</title>
	<link>http://www.hkcode.com</link>
	<description>關於 PHP, Linux, Open Source 及個人生活記載的網誌。</description>
	<pubDate>Fri, 05 Mar 2010 03:50:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.11</generator>
	<language>en</language>
			<item>
		<title>Ubuntu - Firefox 的 Flash 亂碼問題</title>
		<link>http://www.hkcode.com/linux-bsd-notes/568</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/568#comments</comments>
		<pubDate>Fri, 05 Mar 2010 03:50:10 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/568</guid>
		<description><![CDATA[在 Google 找了一下，應該是 /etc/fonts/conf.d/49-sansserif.conf 出問題，只要將檔案移除或移到其他地方就可以：
sudo mv /etc/fonts/conf.d/49-sansserif.conf /etc/fonts/conf.d/49-sansserif.conf.bak
輸入以上指令後，只要重新啟動 Firefox，就可以看到問題解決了。

]]></description>
			<content:encoded><![CDATA[<p>在 Google 找了一下，應該是 /etc/fonts/conf.d/49-sansserif.conf 出問題，只要將檔案移除或移到其他地方就可以：</p>
<p>sudo mv /etc/fonts/conf.d/49-sansserif.conf /etc/fonts/conf.d/49-sansserif.conf.bak</p>
<p>輸入以上指令後，只要重新啟動 Firefox，就可以看到問題解決了。
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/568/feed/</wfw:commentRss>
		</item>
		<item>
		<title>vi 方向鍵及 backspace 的問題</title>
		<link>http://www.hkcode.com/linux-bsd-notes/567</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/567#comments</comments>
		<pubDate>Fri, 05 Mar 2010 01:32:41 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/567</guid>
		<description><![CDATA[在 Ubuntu 上面有時編輯一些設定檔時會直接用 vi 來做，但預設安裝 Ubuntu 後用 vi 開啟檔案，會發覺方向鍵及 backspace 鍵不能使用，解法方法是在家目錄建立 .vimrc 檔案，然後加入以下內容：
    set nocompatible
    set backspace=2
儲存檔案後離開，下次使用 vi 開啟檔案就可以使用方向鍵及 backspace 了。

]]></description>
			<content:encoded><![CDATA[<p>在 Ubuntu 上面有時編輯一些設定檔時會直接用 vi 來做，但預設安裝 Ubuntu 後用 vi 開啟檔案，會發覺方向鍵及 backspace 鍵不能使用，解法方法是在家目錄建立 .vimrc 檔案，然後加入以下內容：</p>
<p>    set nocompatible<br />
    set backspace=2</p>
<p>儲存檔案後離開，下次使用 vi 開啟檔案就可以使用方向鍵及 backspace 了。
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/567/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Linux: 操作包含特殊字元的檔案</title>
		<link>http://www.hkcode.com/linux-bsd-notes/566</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/566#comments</comments>
		<pubDate>Mon, 22 Feb 2010 07:55:57 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/566</guid>
		<description><![CDATA[在 Unix 或 Linux 下很多特殊字元也是指令的一部份，例如空格 (&#8221; &#8220;)、問號 (&#8221;?&#8221;) 及橫線 (&#8221;-&#8221;) 等。所以如果檔案名稱包含了一些特殊字元，在操作上便會出現錯誤，例如:

# touch -foo.txt
touch: invalid option &#8212; &#8216;o&#8217;
Try `touch &#8211;help&#8217; for more information.
# touch &#8211;foo.txt
touch: unrecognized option &#8216;&#8211;foo.txt&#8217;
Try `touch &#8211;help&#8217; for more information.
上面輸入了兩行指令，分別用 touch 建立檔案 &#8220;-foo.txt&#8221; 及 &#8220;&#8211;foo.txt&#8221;，但同樣發生錯誤。要解決這個問題，只要在指令後面加上兩個橫線 &#8220;&#8211;&#8221; 即可，例如:

# touch &#8212; &#8211;foo.txt
# touch &#8212; -foo.txt
而這個方法同樣可以在其他檔案操作指令使用，例如 cp, mv, rm, rmdir。
以下是 cp 及 mv 的用法:
cp - - [...]]]></description>
			<content:encoded><![CDATA[<p>在 Unix 或 Linux 下很多特殊字元也是指令的一部份，例如空格 (&#8221; &#8220;)、問號 (&#8221;?&#8221;) 及橫線 (&#8221;-&#8221;) 等。所以如果檔案名稱包含了一些特殊字元，在操作上便會出現錯誤，例如:</p>
<div class="shell">
# touch -foo.txt<br />
touch: invalid option &#8212; &#8216;o&#8217;<br />
Try `touch &#8211;help&#8217; for more information.<br />
# touch &#8211;foo.txt<br />
touch: unrecognized option &#8216;&#8211;foo.txt&#8217;<br />
Try `touch &#8211;help&#8217; for more information.</div>
<p>上面輸入了兩行指令，分別用 touch 建立檔案 &#8220;-foo.txt&#8221; 及 &#8220;&#8211;foo.txt&#8221;，但同樣發生錯誤。要解決這個問題，只要在指令後面加上兩個橫線 &#8220;&#8211;&#8221; 即可，例如:</p>
<div class="shell">
# touch &#8212; &#8211;foo.txt<br />
# touch &#8212; -foo.txt</div>
<p>而這個方法同樣可以在其他檔案操作指令使用，例如 cp, mv, rm, rmdir。</p>
<p>以下是 cp 及 mv 的用法:</p>
<p>cp - - &#8216;-foo.txt&#8217; /path/to/dest<br />
mv - - &#8216;-foo.txt&#8217; /path/to/dest
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/566/feed/</wfw:commentRss>
		</item>
		<item>
		<title>使用 PHP GZIP 使網頁提速</title>
		<link>http://www.hkcode.com/programming/565</link>
		<comments>http://www.hkcode.com/programming/565#comments</comments>
		<pubDate>Mon, 22 Feb 2010 07:36:58 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>程式設計分享</category>

		<guid isPermaLink="false">http://www.hkcode.com/programming/565</guid>
		<description><![CDATA[GZIP 是一種壓縮技術，是在伺服器上將頁面壓縮，傳到用戶的瀏覽器再解壓。在 PHP 實要 GZIP 壓縮可以這樣做:
PLAIN TEXT
PHP:




&#60;?php


if &#40;substr_count&#40;$_SERVER&#91;'HTTP_ACCEPT_ENCODING'&#93;, 'gzip'&#41;&#41;&#123;


&#160; &#160; ob_start&#40;"ob_gzhandler"&#41;;


&#125;else&#123;


&#160; &#160; ob_start&#40;&#41;;


&#125;


?&#62; 







]]></description>
			<content:encoded><![CDATA[<p>GZIP 是一種壓縮技術，是在伺服器上將頁面壓縮，傳到用戶的瀏覽器再解壓。在 PHP 實要 GZIP 壓縮可以這樣做:</p>
<div class="igBar"><span id="lphp-2"><a href="#" onclick="javascript:showPlainTxt('php-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/substr_count"><span style="color:#000066;">substr_count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'HTTP_ACCEPT_ENCODING'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#FF0000;">'gzip'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/ob_start"><span style="color:#000066;">ob_start</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"ob_gzhandler"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#616100;">else</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/ob_start"><span style="color:#000066;">ob_start</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/programming/565/feed/</wfw:commentRss>
		</item>
		<item>
		<title>執行 sudo 時電郵通知</title>
		<link>http://www.hkcode.com/linux-bsd-notes/564</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/564#comments</comments>
		<pubDate>Fri, 19 Feb 2010 04:08:09 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/564</guid>
		<description><![CDATA[sudo 提供了簡單的方法追蹤執行紀錄，其中一項就是當透過 sudo 執行 指令時發送電郵到指定電郵地址，方法如下:
1. 開啟 sudo 的設定檔:
visudo
2. 加入下面兩行:
mailto "admin@localhost"
mail_always on
mailto 後面是設定發送電郵通知的地址。
mail_always 預設是 off，開啟後會在每次執行 sudo 後發出電郵通知。

]]></description>
			<content:encoded><![CDATA[<p>sudo 提供了簡單的方法追蹤執行紀錄，其中一項就是當透過 sudo 執行 指令時發送電郵到指定電郵地址，方法如下:</p>
<p>1. 開啟 sudo 的設定檔:<br />
visudo</p>
<p>2. 加入下面兩行:</p>
<p>mailto "admin@localhost"<br />
mail_always on</p>
<p>mailto 後面是設定發送電郵通知的地址。<br />
mail_always 預設是 off，開啟後會在每次執行 sudo 後發出電郵通知。
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/564/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Iptables 限制每個 ip 連線數</title>
		<link>http://www.hkcode.com/linux-bsd-notes/563</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/563#comments</comments>
		<pubDate>Thu, 18 Feb 2010 13:08:54 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/563</guid>
		<description><![CDATA[如果在 Linux 下要限制每個 ip 的連線數，可以透過 iptables 實現。詳細指令語法如下：
/sbin/iptables  -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 3 -j REJECT
限制每個 ip 只可以有 3 個 ssh 連線 (預設 ssh 使用 port 22)。
/sbin/iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 -j REJECT --reject-with tcp-reset
只接受每個 ip 20 個 http 連線 (httpd.conf 裡面的 MaxClients [...]]]></description>
			<content:encoded><![CDATA[<p>如果在 Linux 下要限制每個 ip 的連線數，可以透過 iptables 實現。詳細指令語法如下：</p>
<p>/sbin/iptables  -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 3 -j REJECT<br />
限制每個 ip 只可以有 3 個 ssh 連線 (預設 ssh 使用 port 22)。</p>
<p>/sbin/iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 -j REJECT --reject-with tcp-reset<br />
只接受每個 ip 20 個 http 連線 (httpd.conf 裡面的 MaxClients 預設是 60)。<br />
要留意的是，這個設定可能會把 proxy servers 阻隔，因為每個 proxy servers 可能會建立大量的連線。</p>
<p>Skip proxy server IP 1.2.3.4 from this kind of limitations:</p>
<p>/sbin/iptables -A INPUT -p tcp --syn --dport 80 -d ! 1.2.3.4 -m connlimit --connlimit-above 20 -j REJECT --reject-with tcp-reset<br />
這句的作用跟上面語法一樣，只是把已知的 proxy server (1.2.3.4) 給開通，避免阻隔 proxy servers 的連線。</p>
<p>In this example, limit the parallel http requests to 20 per class C sized network (24 bit netmask)</p>
<p>/sbin/iptables  -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 --connlimit-mask 24 -j REJECT --reject-with tcp-reset<br />
這個是限制同一個 class C 網絡同時建立 20 個連線。</p>
<p>如果想把在指定時間內建立過多連線的 ip 阻隔，這便要編輯 iptables 的 shell script。<br />
以下例子會阻隔在 100 秒內建立多於 10 個 http 連線的 ip</p>
<p>#!/bin/bash<br />
IPT=/sbin/iptables<br />
# Max connection in seconds<br />
SECONDS=100<br />
# Max connections per IP<br />
BLOCKCOUNT=10<br />
# ....<br />
# ..<br />
# default action can be DROP or REJECT<br />
DACTION="DROP"<br />
$IPT -A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --set<br />
$IPT -A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --update --seconds ${SECONDS} --hitcount ${BLOCKCOUNT} -j ${DACTION}<br />
# ....<br />
# ..</p>
<p>要儲存 iptables 的修改可以查看 iptables-save 的 man page，在 redhat 下是用以下指令:<br />
service iptables save
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/563/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ProFTPd 登入援慢問題</title>
		<link>http://www.hkcode.com/linux-bsd-notes/562</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/562#comments</comments>
		<pubDate>Wed, 10 Feb 2010 07:03:10 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/562</guid>
		<description><![CDATA[在安裝 ProFTPd 後，會發覺登入時非常援慢，但只要登入成功後，速度就會變得很暢順。
造成這個問題的原因是 ProFTPd 預設在登入時會做「反查」的動作，解決方法是將 ProFTPd 設定為不做「反查」。方法如下：
1. 開啟 proftpd.conf，一般上檔案位置會是 /etc/proftpd.conf 或 /usr/local/etc/proftpd.conf
2. 加入以下兩行:
UseReverseDNS off
IdentLookups off
3. 重新啟動 ProFTPd。

]]></description>
			<content:encoded><![CDATA[<p>在安裝 ProFTPd 後，會發覺登入時非常援慢，但只要登入成功後，速度就會變得很暢順。</p>
<p>造成這個問題的原因是 ProFTPd 預設在登入時會做「反查」的動作，解決方法是將 ProFTPd 設定為不做「反查」。方法如下：</p>
<p>1. 開啟 proftpd.conf，一般上檔案位置會是 /etc/proftpd.conf 或 /usr/local/etc/proftpd.conf</p>
<p>2. 加入以下兩行:</p>
<p>UseReverseDNS off<br />
IdentLookups off</p>
<p>3. 重新啟動 ProFTPd。
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/562/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Linux 系統管理電子書</title>
		<link>http://www.hkcode.com/linux-bsd-notes/561</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/561#comments</comments>
		<pubDate>Tue, 09 Feb 2010 09:42:38 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/561</guid>
		<description><![CDATA[The Free Technology Academy (FTA) 釋出一本免費電子書 "The GNU/Linux operating system"，內容主要圍繞系統管理，例如如何安裝及設定多種不同的伺服器及優化系統等。
官方網站介紹：

    The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.
    In the module called "The GNU/Linux [...]]]></description>
			<content:encoded><![CDATA[<p>The Free Technology Academy (FTA) 釋出一本免費電子書 "<a href="http://ftacademy.org/files/materials/fta-m2-admin_gnulinux-v1.pdf" title="The GNU/Linux operating system">The GNU/Linux operating system</a>"，內容主要圍繞系統管理，例如如何安裝及設定多種不同的伺服器及優化系統等。</p>
<p>官方網站介紹：</p>
<blockquote><p>
    The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.</p>
<p>    In the module called "The GNU/Linux operating system", the main contents are related with system administration. This book is the main documentation for the module.
</p></blockquote>
<p>書本資料:</p>
<p>    * Authors: Remo Suppi Boldrito, Josep Jorba Esteve<br />
    * Coordinator: Josep Jorba Esteve<br />
    * Licenses: GNU Free Documentation License, Creative Commons Attribute ShareAlike License<br />
    * Information: 545 Pages; 18.8 Mb<br />
    * <a href="http://ftacademy.org/files/materials/fta-m2-admin_gnulinux-v1.pdf" title="The GNU/Linux operating system">Download PDF version</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/561/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP 免費線上電子書 - Practical PHP Programming</title>
		<link>http://www.hkcode.com/programming/560</link>
		<comments>http://www.hkcode.com/programming/560#comments</comments>
		<pubDate>Tue, 09 Feb 2010 08:53:00 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>程式設計分享</category>

		<guid isPermaLink="false">http://www.hkcode.com/programming/560</guid>
		<description><![CDATA[Practical PHP Programming 是 PHP 免費線上電子書，比較適合對 PHP 有基礎認識的朋友，以下為電子書目錄：
1. Preface
2. Introducing PHP
3. Simple variables and operators
4. Functions
5. Arrays
6. Objects
7. HTML Forms
8. Files
9. Databases
10. Cookies and Sessions
11. Multimedia
12. XML &#038; XSLT
13. Output Buffering
14. Java and COM
15. Networks
16. Miscellaneous topics
17. Security concerns
18. Performance
19. Writing PHP
20. Writing extensions
21. Alternative PHP uses
22. Practical PHP
23. Bringing it to a close
24. Answers [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tuxradar.com/practicalphp" title="Practical PHP Programming" target="_blank">Practical PHP Programming</a> 是 PHP 免費線上電子書，比較適合對 PHP 有基礎認識的朋友，以下為電子書目錄：</p>
<p>1. Preface<br />
2. Introducing PHP<br />
3. Simple variables and operators<br />
4. Functions<br />
5. Arrays<br />
6. Objects<br />
7. HTML Forms<br />
8. Files<br />
9. Databases<br />
10. Cookies and Sessions<br />
11. Multimedia<br />
12. XML &#038; XSLT<br />
13. Output Buffering<br />
14. Java and COM<br />
15. Networks<br />
16. Miscellaneous topics<br />
17. Security concerns<br />
18. Performance<br />
19. Writing PHP<br />
20. Writing extensions<br />
21. Alternative PHP uses<br />
22. Practical PHP<br />
23. Bringing it to a close<br />
24. Answers to Exercises<br />
25. The future of PHP<br />
26. Glossary</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/programming/560/feed/</wfw:commentRss>
		</item>
		<item>
		<title>netstat 檢查不尋常連線</title>
		<link>http://www.hkcode.com/linux-bsd-notes/559</link>
		<comments>http://www.hkcode.com/linux-bsd-notes/559#comments</comments>
		<pubDate>Tue, 09 Feb 2010 03:12:50 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>Linux / BSD 筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/linux-bsd-notes/559</guid>
		<description><![CDATA[netstat 是一個十分好用的網絡管理工具，而其中一個用途是查看不尋常連線，例如當一個 IP 發送大量連線到伺服器，那麼伺服器很大機會是否遭受 DoS 或 DDoS 攻擊。
以下是一些實用的 netstat 語法，可以檢查主機的連線數量：
netstat -na
顯示主機上所有已建立的連線。
netstat -an &#124; grep :80 &#124; sort
顯示所有 port 80 的連線，並把結果排序。
netstat -n -p&#124;grep SYN_REC &#124; wc -l
列出主機上有多少個 SYNC_REC，一般上這個數字應該相當低。
netstat -n -p &#124; grep SYN_REC &#124; sort -u
同樣是列出 SYNC_REC，但不只列出數字，而是將每個 SYNC_REC 的連線列出。
netstat -n -p &#124; grep SYN_REC &#124; awk '{print $5}' &#124; awk -F: '{print $1}'
列出發送 SYNC_REC 的所有 ip [...]]]></description>
			<content:encoded><![CDATA[<p>netstat 是一個十分好用的網絡管理工具，而其中一個用途是查看不尋常連線，例如當一個 IP 發送大量連線到伺服器，那麼伺服器很大機會是否遭受 DoS 或 DDoS 攻擊。</p>
<p>以下是一些實用的 netstat 語法，可以檢查主機的連線數量：</p>
<p><strong>netstat -na</strong><br />
顯示主機上所有已建立的連線。</p>
<p><strong>netstat -an | grep :80 | sort</strong><br />
顯示所有 port 80 的連線，並把結果排序。</p>
<p><strong>netstat -n -p|grep SYN_REC | wc -l</strong><br />
列出主機上有多少個 SYNC_REC，一般上這個數字應該相當低。</p>
<p><strong>netstat -n -p | grep SYN_REC | sort -u</strong><br />
同樣是列出 SYNC_REC，但不只列出數字，而是將每個 SYNC_REC 的連線列出。</p>
<p><strong>netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'</strong><br />
列出發送 SYNC_REC 的所有 ip 地址。</p>
<p><strong>netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n</strong><br />
計算每一個 ip 在主機上建立的連線數量。</p>
<p>netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n<br />
列出從 TCP 或 UDP 連線到主機的 ip 的數量。</p>
<p><strong>netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr</strong><br />
列出每個 ip 建立的 ESTABLISHED 連線數量。</p>
<p><strong>netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1</strong><br />
列出每個 ip 建立的 port 80 連線數量。
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/linux-bsd-notes/559/feed/</wfw:commentRss>
		</item>
		<item>
		<title>婚禮</title>
		<link>http://www.hkcode.com/my-life/558</link>
		<comments>http://www.hkcode.com/my-life/558#comments</comments>
		<pubDate>Sun, 31 Jan 2010 04:32:54 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>生活隨筆</category>

		<guid isPermaLink="false">http://www.hkcode.com/my-life/558</guid>
		<description><![CDATA[2010 年 1 月 23 日是我結婚的大日子，多得一班朋友及家人的幫忙，他們為我們處理大大小小的問題，尤其在酒樓座位安排上面，整天我們兩夫妻也不用操心細節，只要專心影相。
沒有你們的幫忙，結婚當日不會這麼順利，在此再向他們衷心說聲多謝！

]]></description>
			<content:encoded><![CDATA[<p>2010 年 1 月 23 日是我結婚的大日子，多得一班朋友及家人的幫忙，他們為我們處理大大小小的問題，尤其在酒樓座位安排上面，整天我們兩夫妻也不用操心細節，只要專心影相。</p>
<p>沒有你們的幫忙，結婚當日不會這麼順利，在此再向他們衷心說聲多謝！
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/my-life/558/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASUS RT-N12 + DD-WRT 韌體</title>
		<link>http://www.hkcode.com/internet-notes/557</link>
		<comments>http://www.hkcode.com/internet-notes/557#comments</comments>
		<pubDate>Tue, 05 Jan 2010 00:54:39 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>互聯網筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/internet-notes/557</guid>
		<description><![CDATA[用了幾年的的 router 最近有些怪怪的，發生經常 hang 機的情況，升級 firmware 後也是一樣，唯有花錢買過一台。
最後選擇了 ASUS RT-N12，首先是比較喜歡其簡潔的設計，而它使用的晶片是 BCM4716，時脈 300Mhz，4M FLASH + 32MB DDR RAM，連線數量可達 30,000 條。而著名第三方韌體商 DD-WRT 的韌體也支援 RT-N12，升級過程十分順利。
用了幾天後，目前也十分穩定，而且長時間開啟後，機身也沒有過熱的情況，是值得推薦的產品。
官方網頁: http://www.asus.com/product.aspx?P_ID=xq8udon10ZTLU7o2&#038;templete=2
DD-WRT RT-N12: http://www.dd-wrt.com/phpBB2/viewtopic.php?t=62896

]]></description>
			<content:encoded><![CDATA[<p>用了幾年的的 router 最近有些怪怪的，發生經常 hang 機的情況，升級 firmware 後也是一樣，唯有花錢買過一台。</p>
<p>最後選擇了 ASUS RT-N12，首先是比較喜歡其簡潔的設計，而它使用的晶片是 BCM4716，時脈 300Mhz，4M FLASH + 32MB DDR RAM，連線數量可達 30,000 條。而著名第三方韌體商 DD-WRT 的韌體也支援 RT-N12，升級過程十分順利。</p>
<p>用了幾天後，目前也十分穩定，而且長時間開啟後，機身也沒有過熱的情況，是值得推薦的產品。</p>
<p>官方網頁: <a href="http://www.asus.com/product.aspx?P_ID=xq8udon10ZTLU7o2&#038;templete=2" target="_blank">http://www.asus.com/product.aspx?P_ID=xq8udon10ZTLU7o2&#038;templete=2</a><br />
DD-WRT RT-N12: <a href="http://www.dd-wrt.com/phpBB2/viewtopic.php?t=62896" target="_blank">http://www.dd-wrt.com/phpBB2/viewtopic.php?t=62896</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/internet-notes/557/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google Public DNS Servers 開放使用</title>
		<link>http://www.hkcode.com/internet-notes/556</link>
		<comments>http://www.hkcode.com/internet-notes/556#comments</comments>
		<pubDate>Fri, 11 Dec 2009 04:14:45 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>互聯網筆記</category>

		<guid isPermaLink="false">http://www.hkcode.com/internet-notes/556</guid>
		<description><![CDATA[上星期 Google 開放了類似 OpenDNS 的 DNS服務，以下是 DNS 的 IP:
8.8.8.8
8.8.4.4
在 Linux 下如果要改用 Google 的 DNS，只要修改 /etc/resolv.conf 檔案，將原本使用的 DNS 改成以下即可:
nameserver 8.8.8.8
nameserver 8.8.4.4
可能是因為 Google 的用戶群龐大，其 DNS 內的 cache 也較豐富，所以很多時瀏覽網站時，感覺 resolve 的時間也很快，比自己 ISP 的反應更佳。但大家要留意，當使用 Google 的 DNS 時，實際上上網的紀錄 Google 也可以知道，關心私穩方面問題的朋友要留意了。

]]></description>
			<content:encoded><![CDATA[<p>上星期 Google 開放了類似 OpenDNS 的 DNS服務，以下是 DNS 的 IP:</p>
<p>8.8.8.8<br />
8.8.4.4</p>
<p>在 Linux 下如果要改用 Google 的 DNS，只要修改 /etc/resolv.conf 檔案，將原本使用的 DNS 改成以下即可:</p>
<p>nameserver 8.8.8.8<br />
nameserver 8.8.4.4</p>
<p>可能是因為 Google 的用戶群龐大，其 DNS 內的 cache 也較豐富，所以很多時瀏覽網站時，感覺 resolve 的時間也很快，比自己 ISP 的反應更佳。但大家要留意，當使用 Google 的 DNS 時，實際上上網的紀錄 Google 也可以知道，關心私穩方面問題的朋友要留意了。
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/internet-notes/556/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MySQL 微調技巧</title>
		<link>http://www.hkcode.com/programming/555</link>
		<comments>http://www.hkcode.com/programming/555#comments</comments>
		<pubDate>Fri, 06 Nov 2009 12:56:11 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>程式設計分享</category>

		<guid isPermaLink="false">http://www.hkcode.com/programming/555</guid>
		<description><![CDATA[以下會介紹一些簡易的 MySQL 效能微調技巧，這些方法都是透過 my.cnf 的參數完成，而不需要重新編譯 MySQL。
Key Buffer
key buffer 是系統索引可用的緩存空間大小，對處理索引有很大的影響。設定 key buffer 的大小要根據自己的需要而定，而一個較簡單的方法是使用 25% 的記憶體空間作為 key buffer 使用。如果是獨立的資料庫伺服器可考慮使用更大的空間，例如 50%。
通這設定 key buffer 的大小，可以減少硬碟 I/O 操作對 MySQL 的影響。
以下是 key buffer 在 my.cnf 的設定方法：
key_buffer = 512M
Query Cache
這是 SQL Query 的緩存，將 query 的查詢結果暫存在記憶體裡面，直至資料被更新為止。
query_cache_size = 128MB
query_cache_limit = 4MB
Table Cache
對於同時要存取多個資料表十分重要，這是設定同時可開啟資料表的數目。
table_cache = 512
Sort Buffers
sort_buffer_size (在舊版本是 sort_buffer) 是設定 grouping 及 sorting 的緩存。
sort_buffer_size = 32M
myisam_sort_buffer_size [...]]]></description>
			<content:encoded><![CDATA[<p>以下會介紹一些簡易的 MySQL 效能微調技巧，這些方法都是透過 my.cnf 的參數完成，而不需要重新編譯 MySQL。</p>
<p><strong>Key Buffer</strong><br />
key buffer 是系統索引可用的緩存空間大小，對處理索引有很大的影響。設定 key buffer 的大小要根據自己的需要而定，而一個較簡單的方法是使用 25% 的記憶體空間作為 key buffer 使用。如果是獨立的資料庫伺服器可考慮使用更大的空間，例如 50%。<br />
通這設定 key buffer 的大小，可以減少硬碟 I/O 操作對 MySQL 的影響。</p>
<p>以下是 key buffer 在 my.cnf 的設定方法：</p>
<p>key_buffer = 512M</p>
<p><strong>Query Cache</strong><br />
這是 SQL Query 的緩存，將 query 的查詢結果暫存在記憶體裡面，直至資料被更新為止。</p>
<p>query_cache_size = 128MB<br />
query_cache_limit = 4MB</p>
<p><strong>Table Cache</strong><br />
對於同時要存取多個資料表十分重要，這是設定同時可開啟資料表的數目。</p>
<p>table_cache = 512</p>
<p><strong>Sort Buffers</strong><br />
sort_buffer_size (在舊版本是 sort_buffer) 是設定 grouping 及 sorting 的緩存。</p>
<p>sort_buffer_size = 32M<br />
myisam_sort_buffer_size = 32M
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/programming/555/feed/</wfw:commentRss>
		</item>
		<item>
		<title>轉用 HTC Magic</title>
		<link>http://www.hkcode.com/my-life/554</link>
		<comments>http://www.hkcode.com/my-life/554#comments</comments>
		<pubDate>Thu, 17 Sep 2009 13:46:41 +0000</pubDate>
		<dc:creator>Sam Tang</dc:creator>
		
		<category>生活隨筆</category>

		<guid isPermaLink="false">http://www.hkcode.com/my-life/554</guid>
		<description><![CDATA[使用 Nokia 手機已經有幾年的時間，而且可能是因為自己一直使用舊款的 PDA 得出的錯覺，所以對於輕觸式手機一直也有保留，可能怕自己用不慣。但始終都想試試基於 Linux kernel 的 Android 系統，上星期便買了 HTC Magic，不買最新款 Hero 是因為較喜歡 Magic 的外觀。
用上手的感覺是輕觸式操作沒有想像中困難，只是操作上的概念與以往所使用的手機有得大的分別。以前所用的是一部手機，而 HTC Magic 更像一部 PDA，或者算是流動的電腦。對我最重要的功能是上網瀏覽及電郵，以上兩樣的表現十分滿意，尤其是上網瀏覽的拉近及拉遠功能十分方便。

]]></description>
			<content:encoded><![CDATA[<p>使用 Nokia 手機已經有幾年的時間，而且可能是因為自己一直使用舊款的 PDA 得出的錯覺，所以對於輕觸式手機一直也有保留，可能怕自己用不慣。但始終都想試試基於 Linux kernel 的 Android 系統，上星期便買了 HTC Magic，不買最新款 Hero 是因為較喜歡 Magic 的外觀。</p>
<p>用上手的感覺是輕觸式操作沒有想像中困難，只是操作上的概念與以往所使用的手機有得大的分別。以前所用的是一部手機，而 HTC Magic 更像一部 PDA，或者算是流動的電腦。對我最重要的功能是上網瀏覽及電郵，以上兩樣的表現十分滿意，尤其是上網瀏覽的拉近及拉遠功能十分方便。
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hkcode.com/my-life/554/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
