给centos7 安装iptables防火墙
时间:2019-09-30 15:39:31 来源:xwidea.com 作者:xwidea.com 点击:1166次
我们都知道centos7默认是没有安装iptables的,那么我们如何在centos7里面安装iptables呢? 下面就来讲解一下:
1、#停止firewall systemctl stop firewalld.service
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
2、安装iptables防火墙
yum install -y iptables
yum install iptables-services
3、编辑iptables规则
vi /etc/sysyconfig/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 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT:wq执行保存退出
4、启动iptables
systemctl start iptables.service
网友评论