<?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>as &#8211; richliu&#039;s blog</title>
	<atom:link href="https://richliu.com/tag/as/feed/" rel="self" type="application/rss+xml" />
	<link>https://richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Mon, 07 Oct 2019 15:22:03 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[Linux] 限制時間上 Facebook</title>
		<link>https://richliu.com/2015/12/15/1885/linux-%e9%99%90%e5%88%b6%e6%99%82%e9%96%93%e4%b8%8a-facebook/</link>
					<comments>https://richliu.com/2015/12/15/1885/linux-%e9%99%90%e5%88%b6%e6%99%82%e9%96%93%e4%b8%8a-facebook/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Mon, 14 Dec 2015 17:29:02 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[as number]]></category>
		<category><![CDATA[facebok]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[IPv6]]></category>
		<guid isPermaLink="false">https://richliu.com/?p=1885</guid>

					<description><![CDATA[<p>Facebook 花去太多時間, 所以在 Linux 上加了一條 Rule 限制自己 時間模組是用 iptab [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2015/12/15/1885/linux-%e9%99%90%e5%88%b6%e6%99%82%e9%96%93%e4%b8%8a-facebook/">[Linux] 限制時間上 Facebook</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>

Facebook 花去太多時間, 所以在 Linux 上加了一條 Rule 限制自己

</p>



<span id="more-1885"></span>



<p>

時間模組是用 iptables 的 time , 寫起來像是這樣

</p>



<pre class="wp-block-preformatted">iptables -N limit_fb => 新增一個新個 Rule 叫 limit_fb
iptables -A OUTPUT -p tcp -m tcp -m time --kerneltz --timestart 22:00 --timestop 18:00 --dport 443 -j limit_fb

--timestart 是開始時間
--timestop 是結束時間
--kerneltz 是使用本地時間, 不設預設用 UTC </pre>


<p>因為 Facebook 都是用 https , 所以沒有很好的方式可以過濾 url<br />所以我選擇用 IP/RANGE 的方式阻擋.<br />Facebook 的所有 IP 位置可以從 AS 取得<br />用一個簡單的指令就可以取得</p>
<blockquote>
<p>$ whois -h whois.radb.net &#8216;!gAS32934</p>
</blockquote>
<p>將所有的 IP 加到 Rule tables 內</p>
<blockquote>
<p>FBAS=`whois -h whois.radb.net &#8216;!gAS32934&#8217; | tail -n 2 | head -n 1`<br />for i in $FBAS; do<br />$iptables -I limit_fb -d $i -j DROP<br />done</p>
</blockquote>
<p>效果還不錯</p>
<p>最近又接上 IPv6 了, 如果要取得 Facebook IPv6 的範圍, 可以用這個指令</p>
<blockquote>
<p>FBAS=`whois -h whois.radb.net &#8212; &#8216;-i origin AS32934&#8217; | grep route6 | awk &#8216;{print $2}&#8217;`<br />for i in $FBAS; do<br />$ip6tables -I limit_fb -d $i -j DROP<br />done</p>
</blockquote>
<p>ref.<br /><a href="https://raymii.org/s/snippets/Get_all_IP_ranges_from_an_AS_number.html" target="_blank" rel="noopener noreferrer">Get all IP ranges from an AS number</a><br /><a href="https://ma.ttias.be/whois-at-the-cli-get-all-ip-ranges-from-an-as-number/" target="_blank" rel="noopener noreferrer">Whois at the CLI: get all IP ranges from an AS number</a></p>


<p>懶得加一篇文章了<br /><br />最近要限制小孩看電視，找出電視的 IP ，下這個指令</p>



<pre class="wp-block-preformatted">iptables -A FORWARD -p tcp -s 192.168.1.163 -m state --state NEW,ESTABLISHED -m time --timestart 06:00 --timestop 18:00  --weekdays Mon,Tue,Wed,Thu,Fri --kerneltz -j REJECT</pre>



<p>比起限制 Facebook 的指令，這邊多了 weekdays ，只限制星期一到星期五的晚上六點之前，六點之後因為在家就可以直接限制了</p>
<p>The post <a rel="nofollow" href="https://richliu.com/2015/12/15/1885/linux-%e9%99%90%e5%88%b6%e6%99%82%e9%96%93%e4%b8%8a-facebook/">[Linux] 限制時間上 Facebook</a> appeared first on <a rel="nofollow" href="https://richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://richliu.com/2015/12/15/1885/linux-%e9%99%90%e5%88%b6%e6%99%82%e9%96%93%e4%b8%8a-facebook/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
