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

原创
2016/09/26 20:16
阅读数 1.3K

防火墙开启和关闭(iptables):

  • 即时生效,重启失效
#开启
service iptables start
#关闭
service iptables stop
  • 重启生效
#开启
chkconfig iptables on
#关闭
chkconfig iptables off

一般的服务器,如 centOS 7 之前的 centOS 版本和 redHat 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 7 之后版本:

CentOS 7.0默认使用的是 firewall 作为防火墙,firewall开放端口命令如下。(也可以选择停止firewall安装iptables)

firewall-cmd --zone=public --add-port=5121/tcp --permanent
# --zone 作用域
# --add-port=5121/tcp 添加端口,格式为:端口/通讯协议
# --permanent 永久生效,没有此参数重启后失效

直接关闭防火墙

$ systemctl stop firewalld.service 

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部