当前位置: 首页 > 科技观察

Linux防火墙基本设置及打开端口命令

时间:2023-03-12 04:05:45 科技观察

关闭防火墙CentOS7、RedHat7之前的Linux发行版打开和关闭防火墙(iptables):立即生效,重启无效7.打开和关闭Linux发行版之后的防火墙RedHat7(firewall):systemctlstopfirewalld.serviceopenportCentOS7,RedHat7之前Linux发行版开放端口#命令模式open5212portCommand#打开5212端口接收数据/sbin/iptables-IINPUT-ptcp--dport5212-jACCEPT#开启5212端口发送数据/sbin/iptables-IOUTPUT-ptcp--dport5212-jACCEPT#保存配置/etc/rc.d/init.d/iptablessave#重启防火墙服务/etc/rc.d/init.d/iptablesrestart#查看是否开启成功/etc/init.d/iptablesstatusLinuxdistributionsafterCentOS7andRedHat7openportsfirewall-cmd--zone=public--add-port=5121/tcp--permanent#--zonescope#--add-port=5121/tcp添加端口,格式为:端口/通信协议#--permanent***生效t,没有这个参数,重启后会失效