<?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>iptables &#8211; richliu&#039;s blog</title>
	<atom:link href="https://blog.richliu.com/tag/iptables/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.richliu.com</link>
	<description>Linux, 工作, 生活, 家人</description>
	<lastBuildDate>Fri, 19 Dec 2025 17:31:41 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>[Gentoo] 2025 小升級流水帳</title>
		<link>https://blog.richliu.com/2025/12/20/6441/gentoo-2025-%e5%b0%8f%e5%8d%87%e7%b4%9a%e6%b5%81%e6%b0%b4%e5%b8%b3/</link>
					<comments>https://blog.richliu.com/2025/12/20/6441/gentoo-2025-%e5%b0%8f%e5%8d%87%e7%b4%9a%e6%b5%81%e6%b0%b4%e5%b8%b3/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Fri, 19 Dec 2025 17:31:37 +0000</pubDate>
				<category><![CDATA[Blog/wiki]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[nft]]></category>
		<category><![CDATA[升級]]></category>
		<guid isPermaLink="false">https://blog.richliu.com/?p=6441</guid>

					<description><![CDATA[<p>都什麼年代了，本來應該不會再寫這種升級流水帳了，不過今天當作日記寫一下吧因為今天有三件大事同時發生，總覺得該紀 [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2025/12/20/6441/gentoo-2025-%e5%b0%8f%e5%8d%87%e7%b4%9a%e6%b5%81%e6%b0%b4%e5%b8%b3/">[Gentoo] 2025 小升級流水帳</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>都什麼年代了，本來應該不會再寫這種升級流水帳了，不過今天當作日記寫一下吧<br />因為今天有三件大事同時發生，總覺得該紀念一下<br />* 五個人的大法官自己只有比總共八人，最低門檻六人少一人，所以可以用緊急事*態做成決議<br />* 台北捷運有一個人丟煙霧彈後殺了三個人，傷了五個人<br />* 我今天才發現 Linux kernel 6.18 已經拿掉 iptables </p>



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



<p>大概幾個月前我就發現硬碟有聲音，但是因為使用很正常，所以一直很懶得去處理，大概一個月前才跑去檢查那顆發出聲音，並不是功能影響到我，而是聲音實在讓我太抓狂了。</p>



<p>研究了半天，想說最近 SSD 和 DRAM 都狂漲，剛好看到美亞有黑五特價 Seagate IronWolf Pro 12TB 大概一顆 7500 左右，比 8TB 牌價還便宜，也比我現在用的 Toshiba 大了一倍，再瞄了一下台灣的價格大概都在 11500 左右，想想不想研究了，踩雷就算了吧</p>



<p>訂購中間可以感覺到美亞的落後，光出貨就花了十二天，沒有運貨途中資訊，讓常常買淘寶的我覺得 Amazon 真的是不行，雖然是黑五特價週，但是也太慢了吧</p>



<p>更換的時候我會順便升級系統，就碰到一堆問題</p>



<h2 class="wp-block-heading">Genkernel dmraid 編譯錯誤</h2>



<p>跑 genkernel 會出現  dmraid 的錯誤訊息</p>



<pre class="wp-block-code"><code>misc/file.c: In function 'rw_file':
misc/file.c:64:19: error: initialization of 'ssize_t (*)(void)' {aka 'long int (*)(void)'} from incompatible pointer type 'ssize_t (*)(int,  void *, long unsigned int)' {aka 'long int (*)(int,  void *, long unsigned int)'} &#91;-Wincompatible-pointer-types]
   64 |                 { read, "read"},
      |                   ^~~~
misc/file.c:64:19: note: (near initialization for 'rw_spec&#91;0].func')
In file included from /usr/include/unistd.h:1217,
                 from ./internal.h:24,
                 from misc/file.c:8:
/usr/include/bits/unistd.h:26:1: note: 'read' declared here
   26 | read (int __fd, __fortify_clang_overload_arg0 (void *, ,__buf), size_t __nbytes)
      | ^~~~
misc/file.c:65:19: error: initialization of 'ssize_t (*)(void)' {aka 'long int (*)(void)'} from incompatible pointer type 'ssize_t (*)(int,  const void *, size_t)' {aka 'long int (*)(int,  const void *, long unsigned int)'} &#91;-Wincompatible-pointer-types]
   65 |                 { write, "writ"},
      |                   ^~~~~
misc/file.c:65:19: note: (near initialization for 'rw_spec&#91;1].func')
/usr/include/unistd.h:378:16: note: 'write' declared here
  378 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
      |                ^~~~~
misc/file.c:79:18: error: too many arguments to function 'rw->func'; expected 0, have 3
   79 |         else if (rw->func(fd, buffer, size) != size)
format/ddf/ddf1.c: In function 'check_rd':
format/ddf/ddf1.c:891:25: warning: comparison between 'enum type' and 'enum status' &#91;-Wenum-compare]
  891 |         return rd->type != s_broken;
      |                         ^~
format/ataraid/hpt37x.c: In function 'hpt37x_log':
format/ataraid/hpt37x.c:353:19: warning: taking address of packed member of 'struct hpt37x' may result in an unaligned pointer value &#91;-Waddress-of-packed-member]
  353 |         for (el = hpt->errorlog; el &lt; hpt->errorlog + 32; el++) {
      |                   ^~~</code></pre>



<p>問了 Gemini 和 DeepSeek 後的結果都是</p>



<pre class="wp-block-preformatted">簡單來說，dmraid 這段程式碼非常老舊，它的函數指標定義不嚴謹。在舊版編譯器中，它把函數定義為 (void)（不接受參數）但卻傳入了參數，以前編譯器可能睜一隻眼閉一隻眼，但現在的編譯器（如 GCC 14）預設將這種「指標類型不相容」視為 Error (錯誤) 而不是 Warning，導致編譯失敗。<br /><br />以下是修復方案，你需要修改原始碼中的 misc/file.c 檔案。（下略)</pre>



<p>總之就是花了一點時間找，但是 AI 不識 genkernel ，所以也無從改起，看了一下 genkernel 是採用自己設定 package 自己編的方式，而沒有從 portage 將 patch 拿過來用，所以會 compile 錯誤。不過查了一下 dmraid 最後的 package 是 2010 年 release ，現在應該沒有人用 dmraid ，都是用 mdadm ，之前放在設定檔內應該是相容性的問題，在 /etc/genkernel.conf mark 掉 dmraid 就可以了。</p>



<h2 class="wp-block-heading">init[1]: Id &#8220;f0&#8221; respawning too fast: disabled for 5 minutes</h2>



<p>這個並不是這次升級的錯誤訊息，而是一直出現在我系統內的，問 GPT 的結果是</p>



<pre class="wp-block-preformatted">這通常發生在 /etc/inittab 中定義的某個終端機（TTY）或服務（識別碼為 f0）嘗試啟動但立即失敗，導致 init 陷入不斷重啟的無窮迴圈。<br /><br />1. 找出 f0 是什麼<br />開啟 /etc/inittab 檔案，搜尋 f0 這一行：<br />grep "f0" /etc/inittab<br />常見的內容可能如下： f0:12345:respawn:/sbin/getty 9600 ttyS0<br /><br />2. 常見原因與解決方法<br />序列埠設備不存在 (Serial Port)： 如果 f0 指向的是 /dev/ttyS0（或 ttyUSB0），但該硬體沒插好、驅動沒掛載或在虛擬機中未配置，getty 就會噴錯並結束。<br /><br />解決：若不需要該序列埠，在該行最前面加上 # 註解掉。<br /><br />波特率 (Baud Rate) 錯誤： 設定了硬體不支援的速率。<br /><br />解決：檢查設定是否為正確的 9600 或 115200。<br /><br />執行檔路徑錯誤： /sbin/getty 或指定的程式路徑不存在。<br /><br />解決：確認檔案路徑正確，或改用 agetty。<br /><br />3. 套用變更<br />修改完 /etc/inittab 並存檔後，不需要重新開機，執行以下指令讓 init 重新讀取配置：<br /><br />Bash<br /><br />telinit q</pre>



<p>查了一下果然如此，不過上一代的 GPT 就不知道是什麼，主要是我現在 f0 那一段的 ttyAMA0 不知道為什麼不見了，這個是 ARM 常見的 console ，可能要花時間再查一下問題</p>



<h2 class="wp-block-heading">Linux kernel 6.18 不支援 iptables </h2>



<p>這個我比較崩潰，原來的 kernel 是 6.12 ，換到 6.18 之後感覺天都蹋了，想到我學 iptables 的時候那時候還是 ipchains 的尾聲，想想都快 20 年了，整天與 iptables 為伍，都知道要怎麼下指令和 debug ，但是現在僅僅只有 nft 了，如果你的 iptables 僅有 firewall ，還是可以用 iptables-nft 做轉換，但是如果是有一些特別的指令，像 TCPMSS 之類的，那還是建議改用 nft </p>



<p>還好這年代有 GPT ，直接餵 Gemini 和 DeepSeek ，DeepSeek 吐出來的比較簡潔，所以我就用 DeepSeek 產出的，因為我的網路稍複雜，產生出來的還是有些小問題，不過看了一下就知道怎麼改，問題不大</p>



<p>問題比較大的像是這行，這個 nft 有自己的指令不吃，而且也很難整合進原來的 nft table 內，我碰到的是不知道為什麼 iptables 都會重新產生一次，或是完全無法用，最後還是放棄回去用 nft</p>



<pre class="wp-block-preformatted">$IPTBIN -i $i -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu</pre>



<p>還好第二次就比較順了，但是有個奇怪的點是，我的 sysctl 內的 ip forward 設定跑掉了，不知道誰偷偷改了</p>



<p>沒了 iptables 好失落啊，感覺什麼東西離我而去<br />想當年做 Hardware NAT 的時候天天跟 iptables / Linux kernel tcp stack 為伍，我是有感情的<img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f62d.png" alt="😭" class="wp-smiley" style="height: 1em; max-height: 1em;" /><img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f62d.png" alt="😭" class="wp-smiley" style="height: 1em; max-height: 1em;" /><img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f62d.png" alt="😭" class="wp-smiley" style="height: 1em; max-height: 1em;" /><img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f62d.png" alt="😭" class="wp-smiley" style="height: 1em; max-height: 1em;" /><img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f62d.png" alt="😭" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>其它像什麼 virbr0 消失就要吃自己的狗食了<a href="https://blog.richliu.com/2025/07/27/6345/gentoo-virt-manager-libvirt-virbr0-doesnt-exist/"> [Gentoo] virt-manager/libvirt virbr0 doesn’t exist</a></p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2025/12/20/6441/gentoo-2025-%e5%b0%8f%e5%8d%87%e7%b4%9a%e6%b5%81%e6%b0%b4%e5%b8%b3/">[Gentoo] 2025 小升級流水帳</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.richliu.com/2025/12/20/6441/gentoo-2025-%e5%b0%8f%e5%8d%87%e7%b4%9a%e6%b5%81%e6%b0%b4%e5%b8%b3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>QEMU Network Problem When Run With Docker</title>
		<link>https://blog.richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/</link>
					<comments>https://blog.richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/#respond</comments>
		
		<dc:creator><![CDATA[richliu]]></dc:creator>
		<pubDate>Wed, 16 Oct 2019 06:44:21 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[qemu]]></category>
		<guid isPermaLink="false">https://blog.richliu.com/?p=4190</guid>

					<description><![CDATA[<p>如果 Docker 和 QEMU 同時執行時，QEMU 內部透過 tap interface bridge 到 [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/">QEMU Network Problem When Run With Docker</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>如果 Docker 和 QEMU 同時執行時，QEMU 內部透過 tap interface bridge 到 host network 的網路會出不去<br /><br />這個問題的原因是 Docker 起來之後，會將 iptables 的 packet forward 預設變成 DROP<br /><br />這時可以在 Docker 起來的時候將 bridge interface 加到 iptables 規則內即可，首先編輯 systemd docker service </p>



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



<pre class="wp-block-preformatted">EDITOR=vim sudo -E systemctl edit docker</pre>



<p>加上這一段</p>



<pre class="wp-block-preformatted">[Service] 
ExecStartPre=/sbin/iptables -A FORWARD -p all -i br0 -j ACCEPT 
ExecStopPost=/sbin/iptables -D FORWARD -p all -i br0 -j ACCEPT</pre>



<p><br />再重啟你的 Docker 就好了</p>



<pre class="wp-block-preformatted">sudo systemctl stop docker 
sudo systemctl start docker </pre>



<p>要不然就簡單一點，將 FORWARD rule 從預設 DROP 變成 ACCEPT</p>



<pre class="wp-block-preformatted">[Service] 
ExecStartPre=/sbin/iptables -P FORWARD ACCEPT </pre>



<p>ref<br /><a href="https://bbs.archlinux.org/viewtopic.php?id=233727" target="_blank" rel="noreferrer noopener" aria-label="[SOLVED] Docker breaks existing bridge I use for KVM/QEMU (opens in a new tab)">[SOLVED] Docker breaks existing bridge I use for KVM/QEMU</a></p>
<p>The post <a rel="nofollow" href="https://blog.richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/">QEMU Network Problem When Run With Docker</a> appeared first on <a rel="nofollow" href="https://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.richliu.com/2019/10/16/4190/qemu-network-problem-when-run-with-docker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>[Linux] 限制時間上 Facebook</title>
		<link>https://blog.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://blog.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">http://blog.richliu.com/?p=1885</guid>

					<description><![CDATA[<p>Facebook 花去太多時間, 所以在 Linux 上加了一條 Rule 限制自己 時間模組是用 iptab [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://blog.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://blog.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://blog.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://blog.richliu.com">richliu&#039;s blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.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>
