Linux 基本防火墙设置和开放端口命令

关闭防火墙

CentOS 7RedHat 7 之前的 Linux 发行版防火墙开启和关闭( iptables ):

即时生效,重启失效

#开启
service iptables start
#关闭
service iptables stop

重启生效

#开启
chkconfig iptables on
#关闭
chkconfig iptables off

CentOS 7RedHat 7 之后的 Linux 发行版防火墙开启和关闭( firewall ):

systemctl stop firewalld.service

开放端口

CentOS 7RedHat 7 之前的 Linux 发行版开放端口

#命令方式开放5212端口命令

#开启5212端口接收数据
/sbin/iptables -I INPUT -p tcp --dport 5212 -j ACCEPT


#开启5212端口发送数据
/sbin/iptables -I OUTPUT -p tcp --dport 5212 -j ACCEPT

#保存配置
/etc/rc.d/init.d/iptables save

#重启防火墙服务
/etc/rc.d/init.d/iptables restart

#查看是否开启成功
/etc/init.d/iptables status

CentOS 7RedHat 7 之后的 Linux 发行版开放端口

firewall-cmd --zone=public --add-port=5121/tcp --permanent
# --zone 作用域
# --add-port=5121/tcp 添加端口,格式为:端口/通讯协议
# --permanent 永久生效,没有此参数重启后失效
发布了6 篇原创文章 · 获赞 1 · 访问量 3750
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章