linux如何禁用161端口
linux如何禁用161端口详细介绍
在 Linux 系统中,若要禁用 161 端口,可依据不同的防火墙工具采用不同的方法,下面为你介绍常用的iptables和firewalld的操作方式。
使用
iptables
iptables是 Linux 系统里常用的防火墙工具,你可以按照以下步骤禁用 161 端口:
- 添加规则:添加规则来阻止所有进入和离开 161 端口的流量。
bash
iptables INPUT udp DROPiptables OUTPUT udp DROP
- 保存规则:为了让规则在系统重启后依然有效,你需要保存这些规则。在不同的 Linux 发行版中,保存规则的命令有所不同。
- Debian/Ubuntu:
bash
iptables-persistentnetfilter-persistent save
- CentOS/RHEL:
bash
yum iptables-servicessystemctl iptables
iptables save
使用
firewalld
firewalld是 CentOS 7 及以上版本、Fedora 等系统默认的防火墙管理工具。你可以按照以下步骤禁用 161 端口:
- 添加规则:使用以下命令来阻止 161 端口的 UDP 流量。
bash
firewall-cmd --add-rich-rule
- 重新加载防火墙:使规则生效。
bash
firewall-cmd
912 firewall-cmd
通过以上操作,161 端口就会被禁用。不过,你要确保禁用该端口不会对系统的正常运行产生影响。