Linux
来源:互联网 发布:ubuntu权限不够 编辑:程序博客网 时间:2024/06/06 09:40
【1】安装iptables
步骤与命令如下:
#先检查是否安装了iptablesservice iptables status#安装iptablesyum install -y iptables#升级iptables(安装的最新版本则不需要)yum update iptables #安装iptables-servicesyum install iptables-services
【2】禁用/停止自带的firewalld服务
步骤与命令如下:
#停止firewalld服务systemctl stop firewalld#禁用firewalld服务systemctl mask firewalld
【3】设置现有规则
步骤与命令参考如下:
#查看iptables现有规则iptables -L -n#先允许所有,不然有可能会杯具iptables -P INPUT ACCEPT#清空所有默认规则iptables -F#清空所有自定义规则iptables -X#所有计数器归0iptables -Z#允许来自于lo接口的数据包(本地访问)iptables -A INPUT -i lo -j ACCEPT#开放22端口iptables -A INPUT -p tcp --dport 22 -j ACCEPT#开放21端口(FTP)iptables -A INPUT -p tcp --dport 21 -j ACCEPT#开放80端口(HTTP)iptables -A INPUT -p tcp --dport 80 -j ACCEPT#开放443端口(HTTPS)iptables -A INPUT -p tcp --dport 443 -j ACCEPT#允许pingiptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT#允许接受本机请求之后的返回数据 RELATED,是为FTP设置的iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT#其他入站一律丢弃iptables -P INPUT DROP#所有出站一律绿灯iptables -P OUTPUT ACCEPT#所有转发一律丢弃iptables -P FORWARD DROP
其他参考规则如下:
#如果要添加内网ip信任(接受其所有TCP请求)iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT#过滤所有非以上规则的请求iptables -P INPUT DROP#要封停一个IP,使用下面这条命令:iptables -I INPUT -s ***.***.***.*** -j DROP#要解封一个IP,使用下面这条命令:iptables -D INPUT -s ***.***.***.*** -j DROP
【4】保存规则设定
将会在/etc/sysconfig/路径下生产iptables文件。
#保存上述规则service iptables save
【5】开启iptables服务
步骤与命令如下:
#注册iptables服务#相当于以前的chkconfig iptables onsystemctl enable iptables.service#开启服务systemctl start iptables.service#查看状态systemctl status iptables.service
参考iptables完整配置如下:
阅读全文
0 0
- linux
- linux
- Linux
- Linux
- LINUX!
- Linux
- linux
- linux
- linux
- Linux
- linux
- linux
- linux
- linux
- Linux
- linux
- linux
- Linux
- PHP开启mysqli扩展
- leetcode 658. Find K Closest Elements 双指针
- logback.xml配置解析
- Elasticsearch聚合查询
- Java并发编程:线程池的使用
- Linux
- echarts图表动态获取后台数据详解(三)--ajax跨域请求
- 解引用指针的双重间接
- 禁止微信内置浏览器调整字体大小
- 从零开始学Python【1】--数据类型及结构
- IT风投
- Jmeter相关笔记
- Ubuntu下Django+Apache+mod_wsgi部署
- 20121221