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

<channel>
	<title>How to Config &#187; อัทศักดิ์ วงศ์กิตตะ</title>
	<atom:link href="http://www.howtoconfig.com/author/auttasak/feed" rel="self" type="application/rss+xml" />
	<link>http://www.howtoconfig.com</link>
	<description>how to config - how to configure</description>
	<lastBuildDate>Fri, 29 Apr 2011 09:52:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>การ Mount HDD ด้วย Label</title>
		<link>http://www.howtoconfig.com/os/%e0%b8%81%e0%b8%b2%e0%b8%a3-mount-hdd-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-label.html</link>
		<comments>http://www.howtoconfig.com/os/%e0%b8%81%e0%b8%b2%e0%b8%a3-mount-hdd-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-label.html#comments</comments>
		<pubDate>Fri, 29 Apr 2011 09:48:45 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Disk Label]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=136</guid>
		<description><![CDATA[สวัสดีครับหลังจากห่างหายไปนาน คิดว่าช่วงนี้จะพยายามเข้ามา Update บ่อยๆนะครับ   ช่วงนี้มีงานต้องติดตั้งเว็บ Download ไฟล์ให้ลูกค้าโดยมีเครื่องหลายๆเครื่อง และแต่ละเครื่องมี Card SATA  เพิ่มขึ้น ทำให้แต่ละเครื่องมี HDD ไม่ต่ำกว่า 10 ก้อน ก่อนนี้ผมใช้การ Mount ผ่าน /etc/fstab    โดยการกำหนด device ไปตรงๆ แต่เมื่อ HDD มีปัญหาจำเป็นต้องถอดออกไปเปลี่ยน  จะเกิดปัญหา Device เปลี่ยนตำแหน่ง ทำให้ไม่สามารถ Mount HDD ได้      ด้วยเหตุนี้ผมจึงได้ใช้วิธีการ Mount HDD ผ่าน &#8220;Disk Label&#8221; Disk Label  คือการใส่ป้ายชื่อกำกับให้แต่ละ Partition โดยสามารถกำหนดความยาวได้สูงสุดถึง 160 ตัวอักษร    และหากเมื่อเราเอา HDD ก้อนดังกล่าวไปใช้งานเครื่องอื่น ก็สามารถเห็น [...]]]></description>
			<content:encoded><![CDATA[<p>สวัสดีครับหลังจากห่างหายไปนาน คิดว่าช่วงนี้จะพยายามเข้ามา Update บ่อยๆนะครับ   ช่วงนี้มีงานต้องติดตั้งเว็บ Download ไฟล์ให้ลูกค้าโดยมีเครื่องหลายๆเครื่อง และแต่ละเครื่องมี Card SATA  เพิ่มขึ้น ทำให้แต่ละเครื่องมี HDD ไม่ต่ำกว่า 10 ก้อน</p>
<p>ก่อนนี้ผมใช้การ Mount ผ่าน /etc/fstab    โดยการกำหนด device ไปตรงๆ แต่เมื่อ HDD มีปัญหาจำเป็นต้องถอดออกไปเปลี่ยน  จะเกิดปัญหา Device เปลี่ยนตำแหน่ง ทำให้ไม่สามารถ Mount HDD ได้      ด้วยเหตุนี้ผมจึงได้ใช้วิธีการ Mount HDD ผ่าน &#8220;Disk Label&#8221;</p>
<p>Disk Label  คือการใส่ป้ายชื่อกำกับให้แต่ละ Partition โดยสามารถกำหนดความยาวได้สูงสุดถึง 160 ตัวอักษร    และหากเมื่อเราเอา HDD ก้อนดังกล่าวไปใช้งานเครื่องอื่น ก็สามารถเห็น Label เดียวกันทั้งหมด</p>
<p><strong>วิธีการตั้งชื่อ Label</strong></p>
<p>สำหรับการตั้งชื่อจะใช้คำสั่ง  tune2fs  สำหรับ Partition ที่ใช้ Filesystem  ที่เป็น ext2, ext3     และใช้คำสั่ง  tune4fs สำหรับ ext4  โดยมีคำสั่งดังนี้</p>
<p>Ext4 Partition</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tune4fs <span style="color: #660033;">-L</span> dl2-01 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda1</pre></div></div>

<p>ส่วนของไฟล์  /etc/fstab</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">LABEL</span>=<span style="color: #000000; font-weight: bold;">/</span>                 <span style="color: #000000; font-weight: bold;">/</span>                               ext3            defaults        <span style="color: #000000;">1</span> <span style="color: #000000;">1</span>
tmpfs                   <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>shm                        tmpfs   defaults        <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
devpts                  <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>pts                        devpts  <span style="color: #007800;">gid</span>=<span style="color: #000000;">5</span>,<span style="color: #007800;">mode</span>=<span style="color: #000000;">620</span>  <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
sysfs                           <span style="color: #000000; font-weight: bold;">/</span>sys                            sysfs           defaults        <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
proc                            <span style="color: #000000; font-weight: bold;">/</span>proc                           proc            defaults        <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
&nbsp;
<span style="color: #007800;">LABEL</span>=dl2-00            <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>dl2-00            ext4            defaults        <span style="color: #000000;">0</span> <span style="color: #000000;">0</span>
<span style="color: #007800;">LABEL</span>=dl2-01            <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>dl2-01            ext4            defaults        <span style="color: #000000;">0</span> <span style="color: #000000;">0</span></pre></div></div>

<p>    แค่นี้เครื่อง Server ก็จะเมาท์ HDD โดยใช้ Disk Label แล้วครับ   หาเราทำการถอดหรือเพิ่ม HDD เข้าไปก็จะไม่มีปัญหากับ HDD ที่มีอยู่ครับผม</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2F%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3-mount-hdd-%25e0%25b8%2594%25e0%25b9%2589%25e0%25b8%25a7%25e0%25b8%25a2-label.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/%e0%b8%81%e0%b8%b2%e0%b8%a3-mount-hdd-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-label.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use IPMI on Debian</title>
		<link>http://www.howtoconfig.com/system/how-to-use-ipmi-on-debian.html</link>
		<comments>http://www.howtoconfig.com/system/how-to-use-ipmi-on-debian.html#comments</comments>
		<pubDate>Mon, 01 Nov 2010 18:00:17 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[System]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[IPhone]]></category>
		<category><![CDATA[IPMI]]></category>

		<guid isPermaLink="false">http://www.siambox.com/blog/?p=52</guid>
		<description><![CDATA[โหลด IPMI Kernel Modules modprobe ipmi_watchdog modprobe ipmi_poweroff modprobe ipmi_msghandler modprobe ipmi_devintf modprobe ipmi_si ติดตั้ง ipmitool apt-get install ipmitool ทำการ config ipmi ipmitool lan set 1 ipaddr 192.168.1.101 ipmitool lan set 1 netmask 255.255.255.0 ipmitool lan set 1 defgw ipaddr 192.168.1.254 ipmitool lan set 1 password mypassword ipmitool lan set 1 access on ipmitool lan [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.yellowkompressor.com/ipmi-touch/screenshots/"><img class="alignnone" title="IPMI Touch" src="http://www.yellowkompressor.com/ipmi-touch/wp-content/uploads/ipmi-touch-on-iPhone-e1270867381478.png" alt="" width="250" height="375" /></a></p>
<p>โหลด IPMI Kernel Modules</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">modprobe ipmi_watchdog
modprobe ipmi_poweroff
modprobe ipmi_msghandler
modprobe ipmi_devintf
modprobe ipmi_si</pre></div></div>

<p>ติดตั้ง ipmitool</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ipmitool</pre></div></div>

<p>ทำการ config ipmi</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ipmitool lan <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #000000;">1</span> ipaddr 192.168.1.101
ipmitool lan <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #000000;">1</span> netmask 255.255.255.0
ipmitool lan <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #000000;">1</span> defgw ipaddr 192.168.1.254
ipmitool lan <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #000000;">1</span> password mypassword
ipmitool lan <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #000000;">1</span> access on
ipmitool lan <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #000000;">1</span> arp respond on
ipmitool mc reset cold</pre></div></div>

<p>วิธีการใช้งาน</p>
<p>ดู สถาณะ Power</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ipmitool <span style="color: #660033;">-H</span> 192.168.1.101 <span style="color: #660033;">-U</span> root <span style="color: #660033;">-P</span> mypassword power status</pre></div></div>

<p>Reset  เครื่อง</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ipmitool <span style="color: #660033;">-H</span> 192.168.1.101 <span style="color: #660033;">-U</span> root <span style="color: #660033;">-P</span> mypassword power reset</pre></div></div>

<p>หากท่านใช้ iPhone  ผมแนะนำ <a href="http://www.yellowkompressor.com" target="_blank">IPNI Touch</a> ครับ  สามารถสั่ง Power On/Off/Reset  ได้เลย ทำให้ Admin อย่างเราๆมีชีวิตที่แสนสบายขึ้นเยอะเลยครับ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fsystem%2Fhow-to-use-ipmi-on-debian.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/system/how-to-use-ipmi-on-debian.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenVPN on UDP 53 &#8211; ไปที่ไหนก็เล่น Net ได้!!!</title>
		<link>http://www.howtoconfig.com/os/debian/openvpn-on-udp-53-%e0%b9%84%e0%b8%9b%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b9%84%e0%b8%ab%e0%b8%99%e0%b8%81%e0%b9%87%e0%b9%80%e0%b8%a5%e0%b9%88%e0%b8%99-net-%e0%b9%84%e0%b8%94%e0%b9%89.html</link>
		<comments>http://www.howtoconfig.com/os/debian/openvpn-on-udp-53-%e0%b9%84%e0%b8%9b%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b9%84%e0%b8%ab%e0%b8%99%e0%b8%81%e0%b9%87%e0%b9%80%e0%b8%a5%e0%b9%88%e0%b8%99-net-%e0%b9%84%e0%b8%94%e0%b9%89.html#comments</comments>
		<pubDate>Mon, 25 Oct 2010 08:07:42 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.siambox.com/blog/?p=43</guid>
		<description><![CDATA[สมัยนี้ไปไหนก็มีก็มี Wifi ให้เราใช้งาน ไม่ว่าจะเป็นแบบฟรี หรือ เสียเงิน    วันนี้ผมเอาจุดอ่อน ที่ผู้ให้บริการ Hotspot  มองข้ามคือ การเปิด Any DNS  หรือ การเปิดให้ Client สามารถ Query DNS ข้างน้อกได้ โดยไม่ได้ทำการ Auth      ซึ่ง Wifi หลายๆที่เปิดไว้เพื่อความสะดวก   แต่ตรงนี้แหละเป็นจุดอ่อน  ที่จะทำให้เราสามารถใช้งาน Internet ได้โดยไม่โดนจำกัด Bandwidth สิ่งที่ต้องเตรียม ต้องมี Server ที่เป็น Fix IP ไว้ข้างนอก ติดตั้ง OpenVPN ติดตั้ง Server apt-get install openvpn openvpn --genkey --secret /etc/openvpn/mysecret.key &#160; vi /etc/openvpn/server-udp-53.conf # File /etc/openvpn/server-udp-53.conf dev [...]]]></description>
			<content:encoded><![CDATA[<p>สมัยนี้ไปไหนก็มีก็มี Wifi ให้เราใช้งาน ไม่ว่าจะเป็นแบบฟรี หรือ เสียเงิน    วันนี้ผมเอาจุดอ่อน ที่ผู้ให้บริการ Hotspot  มองข้ามคือ การเปิด Any DNS  หรือ การเปิดให้ Client สามารถ Query DNS ข้างน้อกได้ โดยไม่ได้ทำการ Auth      ซึ่ง Wifi หลายๆที่เปิดไว้เพื่อความสะดวก   แต่ตรงนี้แหละเป็นจุดอ่อน  ที่จะทำให้เราสามารถใช้งาน Internet ได้โดยไม่โดนจำกัด Bandwidth</p>
<p>สิ่งที่ต้องเตรียม</p>
<ol>
<li>ต้องมี Server ที่เป็น Fix IP ไว้ข้างนอก</li>
<li>ติดตั้ง OpenVPN</li>
</ol>
<p>ติดตั้ง Server</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> openvpn
openvpn <span style="color: #660033;">--genkey</span> <span style="color: #660033;">--secret</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>mysecret.key
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">vi</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>openvpn<span style="color: #000000; font-weight: bold;">/</span>server-udp-<span style="color: #000000;">53</span>.conf</pre></div></div>

<pre># File /etc/openvpn/server-udp-53.conf
dev tap
mode p2p
proto udp
#ping 1
port 53
ifconfig 10.10.10.1 255.255.255.252
secret /etc/openvpn/mysecret.key
tun-mtu 1500
tun-mtu-extra 32
mssfix 1400

push "route 192.168.10.0 255.255.255.0"</pre>
<p>ติดตั้ง Client</p>
<p>Download Client จาก   http://openvpn.net/index.php/openvpn-client.html  และทำการติดตั้ง</p>
<p>Copy file  mysecret.key   มาไว้ในเครื่อง  และสร้างไฟล์ config   โดยใช้ชื่อ     client.ovpn</p>
<pre>#file client.ovpn
dev tap
mode p2p
proto udp
remote &lt;IP Server&gt;
#ping 1
port 53
ifconfig 10.10.30.2 255.255.255.252
secret mysecret.key

tun-mtu 1500
tun-mtu-extra 32
mssfix 1400
ping 5</pre>
<p>แค่นี้ก็สามารถ  Connect VPN ผ่าน  UDP/53 ได้แล้วครับ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fdebian%2Fopenvpn-on-udp-53-%25e0%25b9%2584%25e0%25b8%259b%25e0%25b8%2597%25e0%25b8%25b5%25e0%25b9%2588%25e0%25b9%2584%25e0%25b8%25ab%25e0%25b8%2599%25e0%25b8%2581%25e0%25b9%2587%25e0%25b9%2580%25e0%25b8%25a5%25e0%25b9%2588%25e0%25b8%2599-net-%25e0%25b9%2584%25e0%25b8%2594%25e0%25b9%2589.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/debian/openvpn-on-udp-53-%e0%b9%84%e0%b8%9b%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b9%84%e0%b8%ab%e0%b8%99%e0%b8%81%e0%b9%87%e0%b9%80%e0%b8%a5%e0%b9%88%e0%b8%99-net-%e0%b9%84%e0%b8%94%e0%b9%89.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Citrix &#8211; Missing gpg key</title>
		<link>http://www.howtoconfig.com/os/debian/citrix-missing-gpg-key.html</link>
		<comments>http://www.howtoconfig.com/os/debian/citrix-missing-gpg-key.html#comments</comments>
		<pubDate>Wed, 20 Oct 2010 18:39:43 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[apt-get]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://www.siambox.com/blog/?p=30</guid>
		<description><![CDATA[วันนี้ติดตั้ง Xen Server  และลง Debian ในเครื่อง  Xen จะทำการ Add  source ของ citrix ให้เองอัตโนมัตติ   แต่เมื่อเราทำการ update  package   จะฟ้อง Error  ว่าไม่พบ GPG key ของ Citrix     เราสามารถติดตั้งได้  ดั่งนี้ server:~# wget -q http://updates.vmd.citrix.com/XenServer/5.5.0/GPG-KEY -O- &#124; apt-key add - แค่นี้เวลาเราสั่ง apt-get ก็จะไม่ฟ้อง error gpg key อีกแล้วครับ]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" style="margin: 10px;" title="Xen Server" src="http://www.citrix.com/site/resources/dynamic/additional/demos/bin/mm/inpg/landing_xenserver.jpg" alt="" width="576" height="198" />วันนี้ติดตั้ง Xen Server  และลง Debian ในเครื่อง  Xen จะทำการ Add  source ของ citrix ให้เองอัตโนมัตติ   แต่เมื่อเราทำการ update  package   จะฟ้อง Error  ว่าไม่พบ GPG key ของ Citrix     เราสามารถติดตั้งได้  ดั่งนี้</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server:~<span style="color: #666666; font-style: italic;"># wget -q http://updates.vmd.citrix.com/XenServer/5.5.0/GPG-KEY -O- | apt-key add -</span></pre></div></div>

<p>แค่นี้เวลาเราสั่ง apt-get  ก็จะไม่ฟ้อง error gpg key อีกแล้วครับ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fdebian%2Fcitrix-missing-gpg-key.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/debian/citrix-missing-gpg-key.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HA Proxy High Performance TCP/HTTP Load Balancer</title>
		<link>http://www.howtoconfig.com/system/load-balancing/ha-proxy-high-performance-tcphttp-load-balancer.html</link>
		<comments>http://www.howtoconfig.com/system/load-balancing/ha-proxy-high-performance-tcphttp-load-balancer.html#comments</comments>
		<pubDate>Wed, 20 Oct 2010 17:14:39 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[Load balancing]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[haproxy]]></category>
		<category><![CDATA[load balance]]></category>

		<guid isPermaLink="false">http://www.siambox.com/blog/?p=5</guid>
		<description><![CDATA[วันนี้ประเดิม Blog แรกด้วย HAProxy   ซึ่งเป็น Software load balance  ที่สามารถทำงานได้ถึง Layer7    หลักๆผมเอามาทำเป็น HTTP Load Balance    เป้าหมายหลักๆที่ต้องการคือ แยกโหลดไปยังเครื่อง Web Node แต่ละเครื่องได้ กำหนด weight  ของแต่ละ Server ได้ สามารถทำ health check script ได้เอง สามารถ ทำงานได้ในระดับ Layer 7 ได้ หลังจากผมใช้งาน Linux-Ha (ipvsadm) มานาน  ผมพบปัญหาว่า บางครั้งหากเครื่อง Web Node มีปัญหาเครื่อง Load balance จะไม่ปลดโหลดออก ทำให้ผู้ใช้งานไม่สามารถใช้งานได้       ผมเลยลองค้นหาเรื่อง L7 Load Balance   จึงมาพบ  HA Proxy    [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้ประเดิม Blog แรกด้วย HAProxy   ซึ่งเป็น Software load balance  ที่สามารถทำงานได้ถึง Layer7    หลักๆผมเอามาทำเป็น HTTP Load Balance    เป้าหมายหลักๆที่ต้องการคือ</p>
<ul>
<li>แยกโหลดไปยังเครื่อง Web Node แต่ละเครื่องได้</li>
<li>กำหนด weight  ของแต่ละ Server ได้</li>
<li>สามารถทำ health check script ได้เอง</li>
<li>สามารถ ทำงานได้ในระดับ Layer 7 ได้</li>
</ul>
<p>หลังจากผมใช้งาน Linux-Ha (ipvsadm) มานาน  ผมพบปัญหาว่า บางครั้งหากเครื่อง Web Node มีปัญหาเครื่อง Load balance  จะไม่ปลดโหลดออก ทำให้ผู้ใช้งานไม่สามารถใช้งานได้       ผมเลยลองค้นหาเรื่อง L7 Load Balance   จึงมาพบ  HA Proxy    เลยลอง apt-get install haproxy   ดูพบว่าใน Debian ก็มี package มาให้ เลยลองติดตั้งพบว่า สามารถตอบสนอง ความต้องการของผมได้เป็นอย่างดี  ยังไงลองมาดูกันครับ ว่าติดตั้งและใช้งานเป็นยังไง</p>
<p style="text-align: center;"><a href="http://www.siambox.com/blog/wp-content/uploads/2010/10/HAProxy-1.jpg"><img class="size-medium wp-image-49 aligncenter" style="margin-top: 10px; margin-bottom: 10px;" title="HAProxy 1" src="http://www.siambox.com/blog/wp-content/uploads/2010/10/HAProxy-1-212x300.jpg" alt="" width="212" height="300" /></a></p>
<p><strong>ติดตั้ง</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> haproxy</pre></div></div>

<pre style="padding-left: 30px;"># File /etc/haproxy/haproxy.cfg
global
 daemon
 user            haproxy
 group   haproxy
 maxconn 8192
 log             127.0.0.1       local0
 log             127.0.0.1       local1 notice
 stats           socket  /var/run/haproxy.sock mode 666

defaults
 log             global
 mode    http
 option  httplog
 option  dontlognull
 option  httpclose
 #option forwardfor

 stats           enable
 retries 3
 option  redispatch
 maxconn 65535
 contimeout      5000
 clitimeout      50000
 srvtimeout      50000

listen  igetweb.com 0.0.0.0:80
 balance roundrobin

 acl     url_static              path_beg                /images /image /css
 acl     url_static              path_end                .jpg .jpeg .JPG .gif .png .ico .css .zip .tgz .gz .rar .bz2 .doc .xls .exe .pdf .ppt .txt .tar .mid .midi .wav .bmp .rtf .js .swf .wma .wmv

 use_backend             pool_static                     if url_static
 default_backend         pool_dynamic

backend pool_dynamic
 balance roundrobin
 option  httpchk HEAD /check.txt HTTP/1.0
 server web1 192.168.1.11:80  check inter 2000 fall 3 weight 1
 server web2 192.168.1.12:80  check inter 2000 fall 3 weight 1

backend pool_static
 balance roundrobin
 option  httpchk HEAD /check.txt HTTP/1.0
 server web1 192.168.1.21:80  check inter 2000 fall 3 weight 1
 server web2 192.168.1.22:80  check inter 2000 fall 3 weight 1
</pre>
<p>ส่วนสำคัญคือ ACL   โดยเราได้ทำการประกาศ ACL ที่ชื่อ  url_static  โดยหากผู้ใช้งานเรียก  url ที่ขึ้นต้นด้วย /image /images /css หรือ ไฟล์ที่ลงท้ายด้วย  jpg, jpge   และทำการประกาศว่า  หาก macth acl  url_static  ให้ไปเรียกใช้  pool_static     แค่นี้เราก็มี L7 Load Balance  ไว้ใช้งาน โดยไม่ต้องเสียงินหลักแสน ซื้อ Hardware Load balance แล้วครับ</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fsystem%2Fload-balancing%2Fha-proxy-high-performance-tcphttp-load-balancer.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/system/load-balancing/ha-proxy-high-performance-tcphttp-load-balancer.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Speedup Dynamic and Static Content with Nginx</title>
		<link>http://www.howtoconfig.com/os/debian/speedup-dynamic-static-content-nginx.html</link>
		<comments>http://www.howtoconfig.com/os/debian/speedup-dynamic-static-content-nginx.html#comments</comments>
		<pubDate>Sun, 09 May 2010 11:42:03 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[NFS]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Web Server]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=100</guid>
		<description><![CDATA[พูดถึงปัญหาของเว็บใหญ่ๆทั่วไป ก็คงไม่เว็บเรื่องระบบ File System เพราะปัจจุบันมีแค่ NFS เท่านั้นที่ทำการ Share ไฟล์ได้ใน Unix หากจะหันไปให้ SAN หรือ iSCSI ราคาก็แสนแพง เพราะฉนั้นระบบใหญ่แค่ไหนก็มีปัญหาที่ระบบไฟล์ทุกที เราจึงต้องลบ Traffic ที่จะวิ่งไปดึงจาก NFS ให้น้อยที่สุด วันนี้ผมมีอีกทางออกให้คือการแยก Static และ Dynamic Content ออกจากกัน เพราะหากเราแยกได้แล้ว เราสามารถที่จะ Sync Dynamic Content ให้ไปอยู่ใน Local disk ได้หรือ จะทำการเลือกใช้ Web Server ให้เหมาะสมกับระบบที่เราดูแลได้ง่ายขึ้น apt-get install nginx แก้ไขไฟล์ /etc/nginx/nginx.conf user www-data; &#160; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; &#160; worker_processes 16; [...]]]></description>
			<content:encoded><![CDATA[<p>พูดถึงปัญหาของเว็บใหญ่ๆทั่วไป ก็คงไม่เว็บเรื่องระบบ File System  เพราะปัจจุบันมีแค่ NFS เท่านั้นที่ทำการ Share ไฟล์ได้ใน Unix    หากจะหันไปให้ SAN หรือ iSCSI  ราคาก็แสนแพง เพราะฉนั้นระบบใหญ่แค่ไหนก็มีปัญหาที่ระบบไฟล์ทุกที   เราจึงต้องลบ Traffic ที่จะวิ่งไปดึงจาก NFS ให้น้อยที่สุด   วันนี้ผมมีอีกทางออกให้คือการแยก Static และ  Dynamic Content ออกจากกัน  เพราะหากเราแยกได้แล้ว เราสามารถที่จะ Sync Dynamic Content  ให้ไปอยู่ใน Local disk  ได้หรือ จะทำการเลือกใช้ Web Server ให้เหมาะสมกับระบบที่เราดูแลได้ง่ายขึ้น</p>
<p><img src="http://www.howtoconfig.com/content/uploads/2010/05/nginx.jpg" alt="" /><br />
<span id="more-100"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> nginx</pre></div></div>

<p>แก้ไขไฟล์  /etc/nginx/nginx.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user www-data;
&nbsp;
error_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>error.log;
pid        <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>nginx.pid;
&nbsp;
worker_processes  <span style="color: #000000;">16</span>;
worker_rlimit_nofile <span style="color: #000000;">32768</span>;
events <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	worker_connections  <span style="color: #000000;">8192</span>;
	use epoll;
<span style="color: #7a0874; font-weight: bold;">&#125;</span> 
&nbsp;
http <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    include       <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>mime.types;
&nbsp;
    access_log	<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>access.log;
&nbsp;
    sendfile			on;
    <span style="color: #666666; font-style: italic;">#tcp_nopush		on;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#keepalive_timeout	 0;</span>
    keepalive_timeout	<span style="color: #000000;">65</span>;
    tcp_nodelay		on;
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">gzip</span>			on;
&nbsp;
    include <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>conf.d<span style="color: #000000; font-weight: bold;">/*</span>.conf;
    include <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-enabled<span style="color: #000000; font-weight: bold;">/*</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>แก้ไขไฟล์   สร้างไฟล์ /etc/nginx/site-enable/default</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">upstream pool_dynamic <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	server 192.168.1.11:<span style="color: #000000;">80</span>;
	server 192.168.1.12:<span style="color: #000000;">80</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
upstream pool_static <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	server 192.168.1.11:<span style="color: #000000;">80</span>;
	server 192.168.1.12:<span style="color: #000000;">80</span>;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	listen   <span style="color: #000000;">80</span>;
	server_name  _;
&nbsp;
	<span style="color: #666666; font-style: italic;">#access_log /var/log/nginx/localhost.access.log;</span>
	access_log	off;
&nbsp;
	location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		proxy_pass		http:<span style="color: #000000; font-weight: bold;">//</span>pool_dynamic;
		include		<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>proxy.conf;
		access_log		<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>dynamic.access.log;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	location ~<span style="color: #000000; font-weight: bold;">*</span> ^.+.<span style="color: #7a0874; font-weight: bold;">&#40;</span>jpg<span style="color: #000000; font-weight: bold;">|</span>jpeg<span style="color: #000000; font-weight: bold;">|</span>gif<span style="color: #000000; font-weight: bold;">|</span>png<span style="color: #000000; font-weight: bold;">|</span>ico<span style="color: #000000; font-weight: bold;">|</span>css<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">zip</span><span style="color: #000000; font-weight: bold;">|</span>tgz<span style="color: #000000; font-weight: bold;">|</span>gz<span style="color: #000000; font-weight: bold;">|</span>rar<span style="color: #000000; font-weight: bold;">|</span>bz2<span style="color: #000000; font-weight: bold;">|</span>doc<span style="color: #000000; font-weight: bold;">|</span>xls<span style="color: #000000; font-weight: bold;">|</span>exe<span style="color: #000000; font-weight: bold;">|</span>pdf<span style="color: #000000; font-weight: bold;">|</span>ppt<span style="color: #000000; font-weight: bold;">|</span>txt<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">tar</span><span style="color: #000000; font-weight: bold;">|</span>mid<span style="color: #000000; font-weight: bold;">|</span>midi<span style="color: #000000; font-weight: bold;">|</span>wav<span style="color: #000000; font-weight: bold;">|</span>bmp<span style="color: #000000; font-weight: bold;">|</span>rtf<span style="color: #000000; font-weight: bold;">|</span>js<span style="color: #000000; font-weight: bold;">|</span>swf<span style="color: #000000; font-weight: bold;">|</span>wma<span style="color: #000000; font-weight: bold;">|</span>wmv<span style="color: #7a0874; font-weight: bold;">&#41;</span>$ <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		proxy_pass		http:<span style="color: #000000; font-weight: bold;">//</span>pool_static;
		include		<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>proxy.conf;
		<span style="color: #666666; font-style: italic;">#access_log	/var/log/nginx/static.access.log;</span>
		access_log		off;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	location ~ <span style="color: #000000; font-weight: bold;">/</span>\.ht <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		deny  all;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	location <span style="color: #000000; font-weight: bold;">/</span>nginx_status <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		<span style="color: #666666; font-style: italic;"># copied from http://blog.kovyrin.net/2006/04/29/monitoring-nginx-with-rrdtool/</span>
		stub_status	on;
		access_log		off;
		allow			all;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>สร้างไฟล์ /etc/nginx/proxy.conf</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">proxy_redirect			off;
proxy_set_header		Host <span style="color: #007800;">$host</span>;
proxy_set_header		X-Real-IP <span style="color: #007800;">$remote_addr</span>;
proxy_set_header		X-Forwarded-For <span style="color: #007800;">$proxy_add_x_forwarded_for</span>;
client_max_body_size		10m;
client_body_buffer_size	128k;
proxy_connect_timeout	<span style="color: #000000;">90</span>;
proxy_send_timeout		<span style="color: #000000;">90</span>;
proxy_read_timeout		<span style="color: #000000;">90</span>;
proxy_buffer_size		4k;
proxy_buffers			<span style="color: #000000;">4</span> 32k;
proxy_busy_buffers_size	64k;
proxy_temp_file_write_size	64k;</pre></div></div>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fdebian%2Fspeedup-dynamic-static-content-nginx.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/debian/speedup-dynamic-static-content-nginx.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeBSD tip: SUDO Email alert</title>
		<link>http://www.howtoconfig.com/os/ubuntu/freebsdscurity_sudo_email_alert.html</link>
		<comments>http://www.howtoconfig.com/os/ubuntu/freebsdscurity_sudo_email_alert.html#comments</comments>
		<pubDate>Sun, 09 May 2010 10:56:51 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=98</guid>
		<description><![CDATA[แนวคิดคือ Server ที่เราดูแลมี System Admin หลายคนที่สามารถ Access เป็น Root ได้ แล้วเราจะรู้ได้ไงว่า ใคร Login เข้าไปยัง Server ทางออกของผมคือ Allow User ที่ sshd ให้มีแค่ admin เท่านั้นที่เข้าได้ และให้ sudo เป็น root และจะมีอีเมล์แจ้งเตือนมายัง ผู้ดูแล เพื่อทราบว่าเข้าไปทำอะไร 1. sshd ให้แก้ไขไฟล์ /etc/ssh/sshd_config เพิ่ม AllowUsers เช่น AllowUsers auttasak 2. แก้ไข /usr/local/etc/sudoers ดั่งนี้ Defaults mailto=admin@domain.com,mail_always root ALL=(ALL) ALL auttasak ALL=(ALL) NOPASSWD: ALL หลังจากนั้นให้ทำการ Restart SSH [...]]]></description>
			<content:encoded><![CDATA[<p>แนวคิดคือ Server ที่เราดูแลมี System Admin หลายคนที่สามารถ Access เป็น Root ได้  แล้วเราจะรู้ได้ไงว่า ใคร Login เข้าไปยัง Server    ทางออกของผมคือ Allow User ที่ sshd  ให้มีแค่ admin เท่านั้นที่เข้าได้ และให้ sudo เป็น root   และจะมีอีเมล์แจ้งเตือนมายัง ผู้ดูแล เพื่อทราบว่าเข้าไปทำอะไร</p>
<p>1. sshd   ให้แก้ไขไฟล์ /etc/ssh/sshd_config  เพิ่ม          AllowUsers     เช่น<br />
AllowUsers auttasak</p>
<p>2. แก้ไข  /usr/local/etc/sudoers ดั่งนี้</p>
<p>Defaults mailto=admin@domain.com,mail_always<br />
root            ALL=(ALL) ALL<br />
auttasak      ALL=(ALL) NOPASSWD: ALL</p>
<p>หลังจากนั้นให้ทำการ Restart SSH ครับ     เมื่อใดที่มีคน sudo จะมีอีเมล์แจ้งไปยัง  admin@domain.com    แบบนี้ทำให้เราทราบได้ว่ามีคน sudo เป็น root เมื่อใดบ้าง</p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fubuntu%2Ffreebsdscurity_sudo_email_alert.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/ubuntu/freebsdscurity_sudo_email_alert.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use wget on FreeBSD Ports with proxy</title>
		<link>http://www.howtoconfig.com/os/freebsd/wget-freebsd-ports-proxy.html</link>
		<comments>http://www.howtoconfig.com/os/freebsd/wget-freebsd-ports-proxy.html#comments</comments>
		<pubDate>Tue, 27 Apr 2010 18:53:54 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=95</guid>
		<description><![CDATA[เพื่อนๆคงเจอปัญหาเมื่อต้องการติดตั้งโปรแกรมผ่าน Ports ของ FreeBSD ซึ้งจะต้องโหลด Source จากต่างประเทษปต่ปัญหาคือ ISP บางเจ้าในไทย Link Inter ช้าเหลือเกิน ทางออกคือใช้ proxy แทน มาดูวิธีเลยครับ echo &#34;FETCH_CMD=wget&#34; &#62;&#62; /etc/make.conf echo &#34;FETCH_BEFORE_ARGS=-nc --progress=bar --read-timeout=60&#34; &#62;&#62; /etc/make.conf &#160; HTTP_PROXY=http://user:pass@proxy.domain.com:3128/ FTP_PROXY=http://user:pass@proxy.domain.com:3128/ export HTTP_PROXY FTP_PROXY แค่นี้เพื่อนๆก็สามารถลงโปรแกรมผ่าน wget โดยใช้ Proxy ได้แล้วครับ]]></description>
			<content:encoded><![CDATA[<p>      เพื่อนๆคงเจอปัญหาเมื่อต้องการติดตั้งโปรแกรมผ่าน Ports ของ FreeBSD  ซึ้งจะต้องโหลด Source  จากต่างประเทษปต่ปัญหาคือ ISP บางเจ้าในไทย Link Inter ช้าเหลือเกิน   ทางออกคือใช้ proxy แทน มาดูวิธีเลยครับ</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;FETCH_CMD=wget&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>make.conf
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;FETCH_BEFORE_ARGS=-nc --progress=bar --read-timeout=60&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>make.conf
&nbsp;
<span style="color: #007800;">HTTP_PROXY</span>=http:<span style="color: #000000; font-weight: bold;">//</span>user:pass<span style="color: #000000; font-weight: bold;">@</span>proxy.domain.com:<span style="color: #000000;">3128</span><span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">FTP_PROXY</span>=http:<span style="color: #000000; font-weight: bold;">//</span>user:pass<span style="color: #000000; font-weight: bold;">@</span>proxy.domain.com:<span style="color: #000000;">3128</span><span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">export</span> HTTP_PROXY FTP_PROXY</pre></div></div>

<p>แค่นี้เพื่อนๆก็สามารถลงโปรแกรมผ่าน wget โดยใช้ Proxy ได้แล้วครับ  </p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Ffreebsd%2Fwget-freebsd-ports-proxy.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/freebsd/wget-freebsd-ports-proxy.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IPTables statefull firewall for Linux</title>
		<link>http://www.howtoconfig.com/os/ubuntu/iptables_statefull_firewall_linux_debian_centos.html</link>
		<comments>http://www.howtoconfig.com/os/ubuntu/iptables_statefull_firewall_linux_debian_centos.html#comments</comments>
		<pubDate>Tue, 23 Mar 2010 11:04:18 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Shell script]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[INPUT]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=87</guid>
		<description><![CDATA[หายไปนานครับ วันี้เอาเรื่องเก่าๆมาหากินใหม่ IPTables ที่ทำๆอยู่ทุกวันนี้แหละครับ พอดีทำ Shell Script ทิ้งไว้เลยเอามาแจกจ่ายให้เพื่อนๆเอาไปใช้งาน หลายๆคนถามว่าทำไมต้องเขียนเอง ก็เหตุผลง่ายๆครับ เราเขียนเองเรารู้ทุกๆ rules ที่มันทำงานอย่างไร เวลาเกิดปัญหา เราสามารถแก้ไขปัญหาได้ รวดเร็ว มาดูความสามารถของ script firewall ตัวนี้ครับ ความสามารถ: &#8211; State full firewall &#8211; สามารถกำหนด Interface ที่ทำงานได้ &#8211; สามารถกำหนด VIP IP ได้ &#8211; สามารถกำหนด Band IP ได้ &#8211; มีการเก็บ Log ลง syslog &#8211; ป้องกันการ Scan port ได้ &#8211; ป้องกัน IP Spoofig &#8211; ป้องกัน [...]]]></description>
			<content:encoded><![CDATA[<p>     หายไปนานครับ วันี้เอาเรื่องเก่าๆมาหากินใหม่ IPTables ที่ทำๆอยู่ทุกวันนี้แหละครับ พอดีทำ Shell Script ทิ้งไว้เลยเอามาแจกจ่ายให้เพื่อนๆเอาไปใช้งาน   หลายๆคนถามว่าทำไมต้องเขียนเอง   ก็เหตุผลง่ายๆครับ   เราเขียนเองเรารู้ทุกๆ rules ที่มันทำงานอย่างไร เวลาเกิดปัญหา เราสามารถแก้ไขปัญหาได้ รวดเร็ว  มาดูความสามารถของ script firewall ตัวนี้ครับ</p>
<p>ความสามารถ:<br />
  &#8211; State full  firewall<br />
  &#8211; สามารถกำหนด Interface ที่ทำงานได้<br />
  &#8211; สามารถกำหนด VIP IP ได้<br />
  &#8211; สามารถกำหนด Band IP ได้<br />
  &#8211; มีการเก็บ Log ลง syslog<br />
  &#8211; ป้องกันการ Scan port ได้<br />
  &#8211; ป้องกัน IP Spoofig<br />
  &#8211; ป้องกัน SSH Attatch<br />
<span id="more-87"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># rc.firewall - Initial IP Firewall</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">INET_IFACE</span>=<span style="color: #ff0000;">&quot;eth0&quot;</span>
<span style="color: #007800;">IPTABLES</span>=<span style="color: #ff0000;">&quot;/sbin/iptables&quot;</span>
&nbsp;
<span style="color: #007800;">IP_ALLOW</span>=<span style="color: #ff0000;">&quot;61.19.249.66&quot;</span>
<span style="color: #007800;">IP_BAND</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #007800;">ICMP_ALLOW</span>=<span style="color: #ff0000;">&quot;0 3 5 11&quot;</span>
<span style="color: #007800;">TCP_ALLOW</span>=<span style="color: #ff0000;">&quot;22 25 53 80 8000 90 3128 20001&quot;</span> 
<span style="color: #007800;">UDP_ALLOW</span>=<span style="color: #ff0000;">&quot;53&quot;</span>
&nbsp;
<span style="color: #007800;">FTP_PORT</span>=<span style="color: #ff0000;">&quot;1024:65335&quot;</span>
<span style="color: #007800;">FTP_ENABLE</span>=<span style="color: #000000;">1</span>
&nbsp;
&nbsp;
<span style="color: #007800;">SSH_ATTACH</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">SSH_HITCOUNT</span>=<span style="color: #000000;">5</span>
<span style="color: #007800;">SSH_PORT</span>=<span style="color: #000000;">22</span>
&nbsp;
<span style="color: #007800;">PORTSCAN_CHECK</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">SPOOFINGIP_CHECK</span>=<span style="color: #000000;">1</span>
&nbsp;
<span style="color: #007800;">LOGLEVEL</span>=<span style="color: #ff0000;">&quot;DEBUG&quot;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Load IPTables Modules</span>
<span style="color: #666666; font-style: italic;">#</span>
modprobe ip_conntrack
modprobe ip_conntrack_ftp
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Reset IPTables</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-F</span> <span style="color: #660033;">-t</span> nat
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-X</span> <span style="color: #660033;">-t</span> nat
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Create separate chains for ICMP, TCP and UDP to traverse</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> vip_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> band_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> icmp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> tcp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> udp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> log_attach
&nbsp;
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> DROP_TRAFFIC
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Drop packet</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> DROP_TRAFFIC <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-j</span> REJECT <span style="color: #660033;">--reject-with</span> tcp-reset 
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> DROP_TRAFFIC <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">-j</span> REJECT <span style="color: #660033;">--reject-with</span> icmp-port-unreachable
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Log Attack</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> log_attach <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;Attack:&quot;</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> log_attach <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># VIP IPaddress</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> ip <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$IP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> vip_packets <span style="color: #660033;">-s</span> <span style="color: #007800;">$ip</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Band IPaddress</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> ip <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$IP_BAND</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> band_packets <span style="color: #660033;">-s</span> <span style="color: #007800;">$ip</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># ICMP rules</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> icmp <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$ICMP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> icmp_packets <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--icmp-type</span> <span style="color: #007800;">$icmp</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># TCP rules</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> port <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$TCP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> tcp_packets <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$port</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># UDP rules</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">for</span> port <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$UDP_ALLOW</span>
<span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> udp_packets <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">-s</span> <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$port</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># INPUT chain</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ALL <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> ESTABLISHED,RELATED <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">--syn</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> log_attach
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Rules for incoming packets from the internet</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SPOOFINGIP_CHECK</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> spoofing_check
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 169.254.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">16</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 172.16.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">12</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 127.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 224.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 224.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 240.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 240.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-s</span> 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 0.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 239.255.255.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">24</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> spoofing_check <span style="color: #660033;">-d</span> 255.255.255.255 <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> spoofing_check
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$SSH_ATTACH</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> sshattach_check
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> sshattach_check <span style="color: #660033;">-m</span> recent <span style="color: #660033;">--set</span> <span style="color: #660033;">--name</span> SSH
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> sshattach_check <span style="color: #660033;">-m</span> recent <span style="color: #660033;">--update</span> <span style="color: #660033;">--seconds</span> <span style="color: #000000;">60</span> <span style="color: #660033;">--hitcount</span> <span style="color: #007800;">$SSH_HITCOUNT</span> <span style="color: #660033;">--name</span> SSH <span style="color: #660033;">-j</span> log_attach
&nbsp;
        <span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #007800;">$SSH_PORT</span> <span style="color: #660033;">-m</span> state <span style="color: #660033;">--state</span> NEW <span style="color: #660033;">-j</span> sshattach_check
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Port scan</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PORTSCAN_CHECK</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-N</span> check-flags
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN,URG,PSH <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;NMAP:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL FIN,URG,PSH <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL ALL <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;XMAS:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL ALL <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL SYN,RST,ACK,FIN,URG <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;XMAS-PSH:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL SYN,RST,ACK,FIN,URG <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL NONE <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;NULL_SCAN:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> ALL NONE <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;SYN/RST:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,RST SYN,RST <span style="color: #660033;">-j</span> DROP_TRAFFIC
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-m</span> limit <span style="color: #660033;">--limit</span> <span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span>minute <span style="color: #660033;">-j</span> LOG <span style="color: #660033;">--log-level</span> <span style="color: #007800;">$LOGLEVEL</span> <span style="color: #660033;">--log-prefix</span> <span style="color: #ff0000;">&quot;SYN/FIN:&quot;</span>
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> check-flags <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--tcp-flags</span> SYN,FIN SYN,FIN <span style="color: #660033;">-j</span> DROP_TRAFFIC
&nbsp;
	<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> check-flags
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FTP_ENABLE</span>&quot;</span> == <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #666666; font-style: italic;">#Allow FTP traffic (Control)</span>
        iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">-j</span> ACCEPT
        iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">21</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">-j</span> ACCEPT
&nbsp;
        <span style="color: #666666; font-style: italic;">#Allow FTP traffic (Data)</span>
        iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">--dport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> ACCEPT
        iptables <span style="color: #660033;">-A</span> OUTPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--sport</span> <span style="color: #000000;">20</span> <span style="color: #660033;">--dport</span> <span style="color: #007800;">$FTP_PORT</span> <span style="color: #660033;">-j</span> ACCEPT
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> vip_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> band_packets
&nbsp;
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> ICMP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> icmp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> TCP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> tcp_packets
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> UDP <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> udp_packets
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Default policy</span>
<span style="color: #007800;">$IPTABLES</span> <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-i</span> <span style="color: #007800;">$INET_IFACE</span> <span style="color: #660033;">-j</span> DROP_TRAFFIC</pre></div></div>

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fos%2Fubuntu%2Fiptables_statefull_firewall_linux_debian_centos.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/os/ubuntu/iptables_statefull_firewall_linux_debian_centos.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>แก้ปัญหา REMOTE_ADDR ใน Reverse Proxy</title>
		<link>http://www.howtoconfig.com/development/remote_addr-http_x_forwarded_for-reverse-proxy.html</link>
		<comments>http://www.howtoconfig.com/development/remote_addr-http_x_forwarded_for-reverse-proxy.html#comments</comments>
		<pubDate>Wed, 18 Feb 2009 17:58:37 +0000</pubDate>
		<dc:creator>อัทศักดิ์ วงศ์กิตตะ</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Reverse Proxy]]></category>
		<category><![CDATA[Web Server]]></category>

		<guid isPermaLink="false">http://www.howtoconfig.com/?p=74</guid>
		<description><![CDATA[สวัสดีครับ วันนี้จิบเบียร์แล้วก็มานั้งทบทวนเรื่องงานที่ทำ  พอดีมีเรื่องเล็กๆน้่อยๆ ที่ผมเองทำและน่าจะเป็นประโยช์กับเพื่อนๆ  เกี่ยวกับการตั้ง Reverse Proxy กับปัญหา เรื่อง IP ที่ show ใน app ของเรา ปกติเวลาเราเขียน Apps หรือ พวกฟรี Webboard ทั้งหลายจะมีการ Check IP จาก $_SERVER['REMOTE_ADDR'] และ $_SERVER['HTTP_X_FORWARDED_FOR']  หากเจอตัวแปล HTTP_X_FORWARDED_FOR   ระบบจะทำการ Record  IP จาก  HTTP_X_FORWARDED_FOR ด้วย   แต่หากว่าบางโปรแกรมที่เขียน จะเก็บแค่   REMOTE_ADDR  ทำให้ IP ที่แสดงในโปรแกรมของเรา  เป็น IP ของ Reverse Proxy แทน Client IP:  203.146.1.1 Proxy IP: 192.168.1.100 Web IP: [...]]]></description>
			<content:encoded><![CDATA[<p>สวัสดีครับ วันนี้จิบเบียร์แล้วก็มานั้งทบทวนเรื่องงานที่ทำ  พอดีมีเรื่องเล็กๆน้่อยๆ ที่ผมเองทำและน่าจะเป็นประโยช์กับเพื่อนๆ  เกี่ยวกับการตั้ง Reverse Proxy กับปัญหา เรื่อง IP ที่ show ใน app ของเรา</p>
<p>ปกติเวลาเราเขียน Apps หรือ พวกฟรี Webboard ทั้งหลายจะมีการ Check IP จาก</p>
<p>$_SERVER['REMOTE_ADDR'] และ $_SERVER['HTTP_X_FORWARDED_FOR']  หากเจอตัวแปล HTTP_X_FORWARDED_FOR   ระบบจะทำการ Record  IP จาก  HTTP_X_FORWARDED_FOR ด้วย   แต่หากว่าบางโปรแกรมที่เขียน จะเก็บแค่   REMOTE_ADDR  ทำให้ IP ที่แสดงในโปรแกรมของเรา  เป็น IP ของ Reverse Proxy แทน<br />
<span id="more-74"></span></p>
<p>Client IP:  203.146.1.1<br />
Proxy IP: 192.168.1.100<br />
Web IP: 192.168.1.1</p>
<p>[Client] ===&gt; [Revert Proxy] ===&gt; [Web Server]</p>
<p>เมื่อ Web Server  ได้รับ Request   Header จะได้ดั่งนี้</p>
<p>$_SERVER['REMOTE_ADDR'] = 192.168.1.100<br />
$_SERVER['HTTP_X_FORWARDED_FOR']  = 203.146.1.1</p>
<p>ทางแก้ง่ายนิดเดียวครับ  แก้ที่ System ไม่ต้องไปขอร้องให้ Programmer แก้ไขโค๊ดแต่อย่างใด  ทางออกอยู่ที่ PHP ครับ    โดย PHP จะมี Parameter อยู่ 2 ตัวคือauto_prepend_file และ auto_append_file</p>
<p>auto_prepend_file จะกำหนดว่า ก่อนที่จะรันไฟล์ php ทุกๆครั้ง จะทำการรันไฟล์นี้ก่อน ส่วน auto_append_file  คือเมื่อทำการรันไฟล์ php ใดๆเสร็จแล้ว จะมารันไฟล์ ที่เรากำหนด      เมื่อเรารู้ดั่งนี้แล้ว  เ้ราก็มาดูโค๊ดแก้ปัญหาเรื่อง Rever Proxy &amp; REMOTE_IP  ได้เลยครับ</p>
<p>1.  ให้เราไปกำหนดที่  php.ini   ใส่พารามิเตอร์  auto_prepend_file &#8220;/etc/php-prepend.php&#8221;</p>
<p>2. แก้ไขไฟล์  /etc/php-prepend.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$real_ip</span>    <span style="color: #339933;">=</span> session_getip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ip</span>        <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span>                    <span style="color: #339933;">=</span> <span style="color: #000088;">$real_ip</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_X_FORWARDED_FOR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> session_getip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_CLIENT_IP&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_CLIENT_IP&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED_FOR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_X_FORWARDED&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;REMOTE_ADDR&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Code ดั่งกล่าว  จะทำการ ดึง IP ที่  HTTP_X_FORWARDED   มาไว้ยัง $real_ip และทำการกำหนดให้  REMOTE_ADDR = $real_ip   ทำให้ app ทั่วไปทีเราเขียนขึ้น ไม่ต้องทำการแก้ไข Code แต่อย่างใด</p>
<p>ป.ล.    ส่วนของ prepend และ append  สามารถนำไปใช้งานได้หลายรูปแบบมากกว่านี้เอาไว้โอกาศหน้า ผมจะมาเขียนบอกเล่าให้เพื่อนๆ ได้อ่านต่อไปครับ <img src='http://www.howtoconfig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.howtoconfig.com%2Fdevelopment%2Fremote_addr-http_x_forwarded_for-reverse-proxy.html&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>]]></content:encoded>
			<wfw:commentRss>http://www.howtoconfig.com/development/remote_addr-http_x_forwarded_for-reverse-proxy.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

