在Linux系统中,防火墙的配置与管理涉及多种命令行操作,无需特定编程语言,以下是关于Linux防火墙(主要涉及Firewalld和iptables)的配置步骤及说明。
Firewalld
查看所有开放的端口:
使用命令firewall-cmd --zone=public --list-ports
可以查看当前公开区域(public zone)下所有开放的端口列表。
添加端口:
若需永久添加TCP协议的80端口,应使用命令firewall-cmd --zone=public --add-port=80/tcp --permanent
。
删除端口:
删除端口时,命令中的“public”前需加上空格,即firewall-cmd --zone= public --remove-port=80/tcp --permanent
。
刷新配置:
当对防火墙做出更改后,需要使用firewall-cmd --reload
命令来刷新配置,使更改生效。
状态查看与操作:
查看防火墙状态systemctl status firewalld
启动防火墙systemctl start firewalld
停止防火墙systemctl stop firewalld
重启防火墙systemctl restart firewalld
设置开机启动systemctl enable firewalld
关闭开机启动systemctl disabled firewalld
(注意:“disabled”前应有空格)
Iptables
对于Iptables,这是Linux系统中的另一个防火墙管理工具,也主要通过命令行操作。
添加端口(以TCP协议为例):
编辑Iptables规则时,通常使用文本编辑器如vi,进入配置文件/etc/sysconfig/iptables
后,添加如下规则:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -s [ip] --dport [port] -j ACCEPT
这条规则允许从指定IP地址到指定端口的TCP连接。
状态查看与操作:
查看Iptables状态service iptables status
或使用iptables -L
查看详细规则。
开启Iptablesservice iptables start
重启Iptablesservice iptables restart
停止Iptablesservice iptables stop
步骤详细阐述了Linux系统中Firewalld和Iptables的配置与管理方法,通过命令行操作即可完成,无需特定的编程语言。