Centos7 防火墙开放端口和查看已开放的端口命令汇总

Centos7跟centos6版本的系统有很大区别,一般来说centos6是用iptables来查看防火墙状态,但是到了centos7版本,这个命令就被firewalld命令取代了,当然,有些centos7版本仍然可以用iptables命令。下面我们来看看centos7常用的几个firewalld命令。

一、使用firewalld

1、查看防火墙状态

systemctl status firewalld 

2、启动

systemctl start firewalld

3、停止

systemctl disable firewalld

4、禁用

systemctl stop firewalld

5、查看所有打开的端口

 firewall-cmd--zone=public --list-ports

6、添加开放端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

(--permanent永久生效,没有此参数重启后失效)

7、重新载入(更新防火墙规则)

firewall-cmd --reload

8、查看端口是否开放

firewall-cmd --zone=public --query-port=80/tcp

9、删除

firewall-cmd --zone=public --remove-port=80/tcp --permanent

二、使用iptables

切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。

1、停止并禁用 firewalld

systemctl stop firewald.service

systemctl disable firewald.service

2、安装iptables-services、iptables-devel

yum install -y iptables-services iptables-devel 

3、启用并启动iptables

systemctl enable iptables.service

systemctl start iptables.service

4、查看iptables配置文件

vim /etc/sysconfig/iptables

5、开启转发功能

(1) 在 /etc/sysctl.conf 中添加 net.ipv4.ip_forward=1

vim /etc/sysctl.conf

输入i 进入编辑,添加net.ipv4.ip_forward=1

(2) sudo sysctl -p 同步内核参数

(3) 继续查看内核参数 less /proc/sys/net/ipv4/ip_forward  如果为1 则配置生效

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值