<?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>icez network &#187; geodns</title>
	<atom:link href="http://www.icez.net/blog/tags/geodns/feed" rel="self" type="application/rss+xml" />
	<link>http://www.icez.net/blog</link>
	<description>Technical Blog by icez network</description>
	<lastBuildDate>Mon, 30 Jan 2012 17:31:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>0083 &#124; GeoDNS for BIND 9.2+</title>
		<link>http://www.icez.net/blog/373/geodns-for-bind-9-2</link>
		<comments>http://www.icez.net/blog/373/geodns-for-bind-9-2#comments</comments>
		<pubDate>Wed, 04 Nov 2009 10:44:17 +0000</pubDate>
		<dc:creator>icez</dc:creator>
				<category><![CDATA[IP Network]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[geodns]]></category>

		<guid isPermaLink="false">http://www.icez.net/blog/?p=373</guid>
		<description><![CDATA[เอาไว้ทำ CDN ได้ครับ ให้ dns lookup ออกมาตามประเทศ shell script (จำที่มาไม่ได้ ขออภัยด้วยครับ) #!/bin/bash cd /tmp /bin/rm -f GeoIPCountryCSV.zip wget -T 5 -t 1 http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip unzip GeoIPCountryCSV.zip &#124;&#124; exit 1 &#160; echo -n &#34;Creating CNM (Country,Net/Mask) CSV file...&#34; awk -F \&#34; 'function s(c,b,e,l,m,n) {l = log(e-b+1)/log(2); m = 2^32-2^int(l); n = and(m,e); if (n == and(m,b)) {printf [...]]]></description>
			<content:encoded><![CDATA[<p>เอาไว้ทำ CDN ได้ครับ ให้ dns lookup ออกมาตามประเทศ</p>
<p>shell script (จำที่มาไม่ได้ ขออภัยด้วยครับ)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> GeoIPCountryCSV.zip
<span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-T</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-t</span> <span style="color: #000000;">1</span> http:<span style="color: #000000; font-weight: bold;">//</span>geolite.maxmind.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>geoip<span style="color: #000000; font-weight: bold;">/</span>database<span style="color: #000000; font-weight: bold;">/</span>GeoIPCountryCSV.zip
<span style="color: #c20cb9; font-weight: bold;">unzip</span> GeoIPCountryCSV.zip <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Creating CNM (Country,Net/Mask) CSV file...&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> <span style="color: #000000; font-weight: bold;">\&quot;</span> <span style="color: #ff0000;">'function s(c,b,e,l,m,n) {l = log(e-b+1)/log(2); m = 2^32-2^int(l); n = and(m,e); if (n == and(m,b)) {printf &quot;%s,%u.%u.%u.%u/%u\n&quot;,c,b/2^24%256,b/2^16%256,b/2^8%256,b%256,32-l} else {s(c,b,n-1); s(c,n,e)}} s($10,$6,$8)'</span> GeoIPCountryWhois.csv <span style="color: #000000; font-weight: bold;">&gt;</span> cnm.csv
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> GeoIPCountryWhois.csv
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;DONE<span style="color: #000099; font-weight: bold;">\n</span>Generating BIND GeoIP.acl file...&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">for</span> c <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> , <span style="color: #ff0000;">'{print $1}'</span> cnm.csv <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> -u<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;acl <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$c</span><span style="color: #000099; font-weight: bold;">\&quot;</span> {&quot;</span>
  <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^<span style="color: #007800;">$c</span>,&quot;</span> cnm.csv <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> , <span style="color: #ff0000;">'{print &quot;\t&quot;$2&quot;;&quot;}'</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;};<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>named.GeoIP.acl
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> cnm.csv
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DONE&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>named reload
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>แล้วไปแก้ named.conf</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">include</span> <span style="color: #7f007f;">&quot;/etc/named.GeoIP.acl&quot;</span>;
view <span style="color: #7f007f;">&quot;thailand&quot;</span> {
    match-clients { TH; };
        match-clients { TH; };
        zone <span style="color: #7f007f;">&quot;upic.me&quot;</span> {
                type master;
                file <span style="color: #7f007f;">&quot;master/th.db.upic.me&quot;</span>;
        };
}
view <span style="color: #7f007f;">&quot;inter&quot;</span> {
        match-clients { any; };
        zone <span style="color: #7f007f;">&quot;upic.me&quot;</span> {
                type master;
                file <span style="color: #7f007f;">&quot;master/all.db.upic.me&quot;</span>;
        };
};</pre></div></div>

<p>อยากได้ประเทศไหนก็ลองดู code ในไฟล์ /etc/named.GeoIP.acl ละกันครับ<br />
ส่วน&#8230; script ด้านบน<br />
เซฟแล้วเอาใส่ใน cron ด้วยเลยจะดีมาก รันสัปดาห์ละครั้ง</p>
]]></content:encoded>
			<wfw:commentRss>http://www.icez.net/blog/373/geodns-for-bind-9-2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: www.icez.net @ 2012-02-10 17:34:18 -->
