Redhat Linux防火墙管理

Redhat Linux防火墙管理

Redhat7以前使用iptables防火墙

添加允许通过端口

在/etc/sysconfig/iptables中添加配置

[root@localhost ~]# vi /etc/sysconfig/iptables
...
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 3306 -j ACCEPT

或通过iptables命令添加

[root@localhost sysconfig]# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 5432 -j ACCEPT
[root@localhost sysconfig]# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT

保存配置,重启防火墙生效

[root@localhost etc]#  /etc/rc.d/init.d/iptables save
[root@localhost start-scripts]# service iptables restart

查看防火墙配置

[root@localhost start-scripts]# iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:mysql 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:mysql 
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 
ACCEPT     udp  --  anywhere             anywhere            state NEW udp dpt:postgres 
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:postgres 

Redhhat7使用firewalld管理防火墙

查看防火墙允许端口

 firewall-cmd --list-all

添加允许通过端口

通过firewall-cmd –permanent添加永久允许通过端口

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=5432/tcp

重新载入防火配置,使之生效

[root@localhost ~]# firewall-cmd --reload

或重启防火墙使之生效

[root@localhost ~]# service firewalld restart

删除端口

firewall-cmd --zone=public --remove-port=6022/tcp --permanent
firewall-cmd --reload
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值