1.iptables安装
yum install -y iptables && yum install -y iptables-services
2.iptables开启:
/bin/systemctl start iptables.service
3.保存当前配置
service iptables save
iptables-save > /etc/sysconfig/iptables
4.开始自启
systemctl enable iptables.service
示例脚本
#!/bin/bash
iptables -I FORWARD -j REJECT --reject-with icmp-host-prohibited
iptables -I INPUT -j REJECT --reject-with icmp-host-prohibited
#允许22端口通过端口连接
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
#允许网卡流入
iptables -I INPUT -i lo -j ACCEPT
#禁止ping
iptables -I INPUT -p icmp -j REJECT
#允许建立联机
iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT