使用 /etc/hosts 阻止電報

使用 /etc/hosts 阻止電報

我使用 /etc/hosts 來阻止我不想訪問的網域,它適用於大多數網域。然而,它似乎不適用於 Telegram 網路聊天 (web.telegram.org)。

我的文件中有以下幾行:

0.0.0.0 web.telegram.org
0.0.0.0 www.telegram.org
0.0.0.0 telegram.org

但我仍然可以訪問該網站並使用網頁應用程式的全部功能。難道我做錯了什麼?

答案1

由於您正在編輯 /etc/hosts,因此您具有 root 存取權。最好、最優雅的方法是使用 iptables(即阻止封包離開盒子到 www.telegram.org)

可以透過在命令列輸入iptables命令進行測試。

# iptables -A OUTPUT -d www.telegram.org -j REJECT

您可以看到您新增了以下規則:

# iptables -S OUTPUT

-P OUTPUT ACCEPT
-A OUTPUT -d 149.154.167.120/32 -j REJECT --reject-with icmp-port-unreachable

您可以使用以下方法測試對其的嘗試存取:

# wget  web.telegram.org                                                     
--2017-04-26 14:38:01--  http://web.telegram.org/
Resolving web.telegram.org... 149.154.167.120, 2001:67c:4e8:fa60:3:0:811:140
Connecting to web.telegram.org|149.154.167.120|:80... failed: Connection refused.
Connecting to web.telegram.org|2001:67c:4e8:fa60:3:0:811:140|:80... failed: Network is unreachable.

您沒有告訴我們您正在運行什麼作業系統,因此您可能沒有更新版本的 iptables,因此您可能缺少 -S 開關。您可以使用-L:

# iptables -L OUTPUT

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             149.154.167.120     reject-with icmp-port-unreachable 

如果要刪除剛剛新增的規則,只需將上面命令中的 -A 替換為 -D 即可。

注意:如果您希望這些規則在重新啟動後永久生效,您必須手動iptables-save > /etc/sysconfig/iptables將它們新增至 /etc/sysconfig/iptables 中。

iptables 相當複雜,但手冊頁非常有幫助。

(我在我的伺服器上運行 CentOS 6 和 7。firewalld 是 CentOS 7 上新的預設前端,但我安裝了 iptables-services 並使用它,這是完全受支援的。)

答案2

順便說一句,我將主機設定為 127.0.0.1 而不是 0.0.0.0....這可能是您原來的問題。

無論如何,另一個技巧是為有問題的 IP 號碼添加特殊路由:

 # route add -host 10.11.12.13 dev lo

您必須將這些新增至 rc.local (或等效檔案)中,以便在重新啟動時重新建立這些規則。

我用它來阻止那些試圖破解我的網站公司密碼的人。

答案3

它使用 websockets 來獲取訊息

添加

0.0.0.0 zws2.web.telegram.org

PS 檢查如何在 chrome devtools 中調試 websockets

相關內容