如何永久禁用 GNU/linux 网络?

如何永久禁用 GNU/linux 网络?

即使有网卡(可能插入了电缆),如何才能使 Ubuntu 12 无法与网络通信?

我发现这个答案建议删除 NIC 驱动程序,但我担心升级过程中可能会重新安装驱动程序。我没有太多管理 Linux 的经验。

运行不具备网络功能的 GNU/linux 是否有最佳实践?

答案1

您可以通过禁用 Linux 内核中的不同网络功能来实现这一点。禁用所有网络选项将会产生破坏性影响(因为某些程序确实使用环回接口进行操作 - 其中之一是 X 服务器)。但有帮助的方法是禁用内核中的任何 NIC 设备驱动程序。这将确保没有外部网络活动。

但还有另一点——正如你所说:

but I'm concerned that the driver might be re-installed during an upgrade

这假设执行更新的用户具有系统的 root 访问权限。如果是这种情况 - 您无法使用类似软件的解决方案解决问题。由于用户具有 root 访问权限(和知识)- 用户将能够进行任何更改。

另一点 - 即使用户没有 root 访问权限 - 也可以启动 Linux 实时发行版并对计算机的配置文件进行任何更改,包括用新的内核映像替换内核映像(从而启用 NIC 驱动程序)。

这一切都与一个简单的事实有关 - 如果一个人可以物理访问计算机 - 他就可以改变计算机上的任何内容(只要他有知识和工具)。

以下是一些可能的方法:

  1. 如果用户不具备高级 Linux 知识编译 Linux 内核在我看来,内核中没有 NIC 驱动程序(不要忘记 USB 网卡)就足够了。

  2. 另外,您可以在 BIOS 设置中禁用网卡 - 但同样,如果有人可以物理访问计算机,则可以重置这些设置。

  3. 您可以设置iptables规则来拒绝任何外部网络流量。

  4. 使用物理安全设备如端口锁套件;

答案2

CONFIG_NET=n

此选项控制内核中的网络支持。但正如文档本身所说,这可能会破坏许多执行网络操作的用户空间程序:

menuconfig NET
    bool "Networking support"
    select NLATTR
    select GENERIC_NET_UTILS
    select BPF
    ---help---
      Unless you really know what you are doing, you should say Y here.
      The reason is that some programs need kernel networking support even
      when running on a stand-alone machine that isn't connected to any
      other computer.

      If you are upgrading from an older kernel, you
      should consider updating your networking tools too because changes
      in the kernel and the tools often go hand in hand. The tools are
      contained in the package net-tools, the location and version number
      of which are given in <file:Documentation/Changes>.

      For a general introduction to Linux networking, it is highly
      recommended to read the NET-HOWTO, available from
      <http://www.tldp.org/docs.html#howto>.

我已经在以下位置测试过该选项:https://github.com/cirosantilli/linux-kernel-module-cheat/blob/71d673bac48f43a2e38f5e1e4f94b10da15b7cee/kernel_config_fragment#L58

结果:许多(所有?)网络系统返回故障状态并且不执行任何操作,例如:

# nc -l -p 8000 127.0.0.1
nc: socket: Function not implemented

TODO:UNIX 套接字?该版本中不存在nc,我懒得尝试。

我仍然可以使用 shell 并调用基本实用程序。但是例如 X-server 需要网络系统调用才能工作,并且无法正常启动。

相关内容