IPTables 沒有按照我的要求執行

IPTables 沒有按照我的要求執行

這裡的社區太棒了!

我有一個 ASUS 3100 無線路由器和大約 4 個 IP 攝影機。在我的舊路由器上,很容易阻止傳出流量,這樣我就可以確保攝影機不會「打電話回家」。我想對這個路由器做同樣的事情,所以我決定先使用連接埠轉送工具,然後開始尋找 IPTABLES。 我不知道這是否是 asuswrt-merlin 在路由器管理工具和 iptables 上使用連接埠轉送的問題。我懷疑不是……對吧?

我的目標:

  1. 預設阻止 192.168.1.0/29 的傳出和傳入流量
  2. 例外:我想打開 120:130,但僅限少數受信任的 IP(工作或朋友家)。假設這些 IP 是 150.150.150.150 和 250.250.250.0/24(我使用瀏覽器訪問這些端口,但這可能並不重要),所以如果我想訪問 CAMERA #2,它將是 DDNS.dns.com:121
  3. 例外:攝影機透過 SMTPS(連接埠 465)發送電子郵件,因此我想打開它,以便它可以發送電子郵件。

不想阻止輸入/輸出,因為我有一些物聯網東西在其他地方進行通信,所以我不想更改預設策略來阻止它。除非我誤解了它是如何工作的。

我用最新的 Asuswrt-Merlin 刷新了路由器並打開了 JFFS 自訂腳本。我在/jffs/scripts/名為 的檔案下建立了一個檔案firewall-start。我編輯了以 shebang 開頭的文件並添加了一些規則(稍後會再討論)。我用了service restart_firewall。我遇到的問題是我沒有得到適當的結果,而且我很可能寫錯了規則和/或順序。

我嘗試了 iptables Forward,我嘗試了 iptables INPUT & OUTPUT,我嘗試了“INSERT”/“APPEND”的組合,由於某種奇怪的原因,它要么阻止所有內容,要么讓它完全打開。它永遠不會遵循我的最終目標。我確信這與 FORWARD 或 INPUT 或 OUTPUT 的某些順序或預設規則有關,但我只是無法弄清楚。

我也一次插入一個規則。開始很簡單。

iptables -I FORWARD -d 192.168.1.0/29 -p tcp --dport 17111 -j DROP

這就把它掉了。有時它很挑剔,因為如果我嘗試 canyouseeme.org,它說成功放入程式碼,它仍然說成功。有時它說它失敗了(意味著它掉落了),所以有時這就是我遇到的情況,但聽起來可能是一個不相關的問題。然後我對自己說,好吧,這有效。現在讓我們在這之後添加一個 INSERT 規則,因為顯然 INSERT 會到達頂部,所以我在上面的程式碼之後添加了以下內容:

iptables -I FORWARD -s myworkip -d 192.168.1.0/29 -p tcp --dport 121 -j ACCEPT

文件中的這兩個內容就是這樣。我刷新 iptables,然後重新啟動防火牆啟動服務以使其獲取新規則。我使用iptables -L我發現它的順序是正確的。透過重新載入網頁 ddns.dns.com:121 和 nada 進行測試。它不會加載。是一些緩存嗎?需要時間嗎?有時我等了5分鐘還是沒有任何反應。我再次使用 canyouseeme.org,但它仍然顯示上次 DROP 程式碼失敗。

我需要一些專家來幫助我。這是我現在現有的 iptable:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       icmp --  anywhere             anywhere             icmp echo-request
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
DROP       all  --  anywhere             anywhere             state INVALID
PTCSRVWAN  all  --  anywhere             anywhere
PTCSRVLAN  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             state NEW
ACCEPT     all  --  anywhere             anywhere             state NEW
OVPN       all  --  anywhere             anywhere             state NEW
ACCEPT     udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc
INPUT_ICMP  icmp --  anywhere             anywhere
DROP       all  --  anywhere             anywhere

Chain FORWARD (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
other2wan  all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             state INVALID
ACCEPT     all  --  anywhere             anywhere
NSFW       all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate DNAT
OVPN       all  --  anywhere             anywhere             state NEW
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain ACCESS_RESTRICTION (0 references)
target     prot opt source               destination

Chain FUPNP (0 references)
target     prot opt source               destination

Chain INPUT_ICMP (1 references)
target     prot opt source               destination
RETURN     icmp --  anywhere             anywhere             icmp echo-request
RETURN     icmp --  anywhere             anywhere             icmp timestamp-request
ACCEPT     icmp --  anywhere             anywhere

Chain NSFW (1 references)
target     prot opt source               destination

Chain OVPN (2 references)
target     prot opt source               destination

Chain PControls (0 references)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

Chain PTCSRVLAN (1 references)
target     prot opt source               destination

Chain PTCSRVWAN (1 references)
target     prot opt source               destination

Chain SECURITY (0 references)
target     prot opt source               destination
RETURN     tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/SYN limit: avg 1/sec burst 5
DROP       tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/SYN
RETURN     tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/RST limit: avg 1/sec burst 5
DROP       tcp  --  anywhere             anywhere             tcpflags: FIN,SYN,RST,ACK/RST
RETURN     icmp --  anywhere             anywhere             icmp echo-request limit: avg 1/sec burst 5
DROP       icmp --  anywhere             anywhere             icmp echo-request
RETURN     all  --  anywhere             anywhere

Chain default_block (0 references)
target     prot opt source               destination

Chain logaccept (0 references)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere             state NEW LOG level warning tcp-sequence tcp-options ip-options prefix "ACCEPT "
ACCEPT     all  --  anywhere             anywhere

Chain logdrop (0 references)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere             state NEW LOG level warning tcp-sequence tcp-options ip-options prefix "DROP "
DROP       all  --  anywhere             anywhere

Chain other2wan (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere

先致謝!

相關內容