Centos7防火墙设置

来源:互联网 发布:钢铁力量六级车数据 编辑:程序博客网 时间:2024/05/19 06:36

centos7服务启动与之前的版本有所区别,下面来看几个常用的指令:
1 启动防火墙

 /bin/systemctl start iptables.service

2 关闭防火墙

 /bin/systemctl stop iptables.service

3 设置防火墙

vim /etc/sysconfig/iptables

配置可以如下所示:

# Firewall configuration written by system-config-firewall# Manual customization of this file is not recommended.*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 8088 -j ACCEPT #设置可接受的端口号-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT

4 查看本机防火墙设置情况

iptables -L -n[root@localhost conf]# iptables -L -nChain INPUT (policy ACCEPT)target     prot opt source               destination         ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8088 REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)target     prot opt source               destination         REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)target     prot opt source               destination         

5 常见配置
首先添加INPUT链,INPUT链的默认规则是DROP,所以我们就写需要ACCETP(通过)的链,为了能采用远程SSH登陆,我们要开启

iptables -A INPUT -p tcp --dport 22 -j ACCEPTiptables -A OUTPUT -p tcp --sport 22 -j ACCEPT

如果做了WEB服务器,开启80端口.

 iptables -A INPUT -p tcp --dport 80 -j ACCEPT

如果做了邮件服务器,开启25,110端口.

iptables -A INPUT -p tcp --dport 110 -j ACCEPTiptables -A INPUT -p tcp --dport 25 -j ACCEPT

如果做了FTP服务器,开启21端口

iptables -A INPUT -p tcp --dport 21 -j ACCEPTiptables -A INPUT -p tcp --dport 20 -j ACCEPT

如果做了DNS服务器,开启53端口

 iptables -A INPUT -p tcp --dport 53 -j ACCEPT

如果你还做了其他的服务器,需要开启哪个端口,照写就行了.上面主要写的都是INPUT链,凡是不在上面的规则里的,都DROP允许icmp包通过,也就是允许ping

iptables -A OUTPUT -p icmp -j ACCEPT (OUTPUT设置成DROP)iptables -A INPUT -p icmp -j ACCEPT  (INPUT设置成DROP)
原创粉丝点击