阻止程式使用互聯網

阻止程式使用互聯網

有沒有辦法在 Debian 中阻止某些程式連接到互聯網(阻止傳出連接的防火牆),例如,阻止在 wine 中運行的 Windows 程式打電話回家?

答案1

你可以使用Linux容器建立一個沒有網路介面的環境。例如,如果我建立一個如下的設定檔:

# lxc.network.type = empty

然後啟動一個 shell,如下圖所示:

# lxc-execute --name bash -f /tmp/lxc.conf /bin/bash

我會發現在這個 shell 中除了以下之外沒有可用的網路設備lo

# ifconfig -a
lo        Link encap:Local Loopback  
          LOOPBACK  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

請注意,您必須是 root 才能運行lxc-execute,因此讓它在您的桌面環境中運行wine可能會很棘手。

顯然還有一個sandbox指令可作為 SELinux 的一部分。這是使用沙箱運行 Firefox 的範例。這需要您啟用 selinux。

答案2

更簡單的方法是以不同使用者身分執行 WINE 程式並設定 netfilter 來丟棄來自該使用者的資料包。

例如,其中「wineusername」是您的 Wine 用戶,em1 是您的網路介面:

iptables -A OUTPUT -o em1 -m owner --uid-owner wineusername -j DROP
iptables -A FORWARD -o em1 -m owner --uid-owner wineusername -j DROP
iptables -A INPUT -o em1 -m owner --uid-owner wineusername -j DROP

相關內容