Linux iptables 防火墙常用规则
iptables 安装
yum install iptables
iptables 规则清除
iptables -F
iptables -X
iptables -Z
开放指定的端口
允许本地回环接口(即运行本机访问本机)
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
允许所有本机向外的访问
iptables -A OUTPUT -j ACCEPT
允许访问22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
允许访问80端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
允许指定IP访问22
iptables -I INPUT -s 192.168.0.19 -p tcp --dport 22 -j ACCEPT
禁止其他未允许的规则访问
iptables -A INPUT -j REJECT
iptables -A FORWARD -j REJECT
屏蔽IP
屏蔽单个IP的命令是
iptables -I INPUT -s 123.45.6.7 -j DROP
封整个段即从123.0.0.1到123.255.255.254的命令
iptables -I INPUT -s 123.0.0.0/ -j DROP
封IP段即从123.45.0.1到123.45.255.254的命令
iptables -I INPUT -s 124.45.0.0/ -j DROP
封IP段即从123.45.6.1到123.45.6.254的命令是
iptables -I INPUT -s 123.45.6.0/ -j DROP
查看已添加的iptables规则
iptables -L -n
删除已添加的iptables规则
查看添加的规则条数
iptables -n -L -v --line-number
比如要删除INPUT里序号为8的规则,执行:
iptables -D INPUT
保存规则
service iptables save
重启服务
service iptables restart
iptables 配置文件
vi /etc/sysconfig/iptables
打开主动模式21端口
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
全部开放FTP传输
加载模块:
modprobe ip_nat_ftp
modprobe ip_conntrack
modprobe ip_conntrack_ftp
加上一条规则:
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
iptables只允许指定ip地址访问指定端口
iptables -A INPUT -s xxx.xxx.xxx.xxx -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -d xxx.xxx.xxx.xxx -p tcp --sport 22 -j ACCEPT
上面这两条,请注意--dport为目标端口,当数据从外部进入服务器为目标端口;反之,数据从服务器出去则为数据源端口,使用 --sport
同理,-s是指定源地址,-d是指定目标地址。
关闭所有的端口
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
yum允许下载随机产生的高端口
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --sport 53 -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 10000:65535 -j ACCEPT
允许Ping
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
禁Ping
iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP
Linux iptables 防火墙常用规则的更多相关文章
- 15.linux iptables防火墙规则vsftp服务
一.服务所开启的端口号. dhcp 67 samba 139 445 http 80 https 443 mysql 3306 ...
- Iptables 防火墙常用配置
转至:https://blog.csdn.net/lswzw/article/details/87971259 Iptables 防火墙常用配置 概念 命令行模式 查看 & 命令 -n:直接显 ...
- Linux下iptables防火墙用法规则详解
管理网络流量是系统管理员必需处理的最棘手工作之一,我们必需规定连接系统的用户满足防火墙的传入和传出要求,以最大限度保证系统免受×××.很多用户把 Linux 中的iptables当成一个防火墙,从严格 ...
- CentOS Linux iptables 防火墙
快速安装,配置,启动,检查 - 关闭 5002 - 5011 端口开放所有其它 yum install iptables iptables -F iptables -X iptables -Z ipt ...
- iptables防火墙常用配置介绍
参考地址 http://www.cnblogs.com/metoy/p/4320813.html http://netfilter.org/ iptables http://man.chinaunix ...
- linux iptables 防火墙简介
iptables防火墙简介 Netfilter/Iptables(以下简称Iptables)是unix/linux自带的一款优秀且开放源代码的安全自由的基于包过滤的防火墙工具,它的功能十分强大,使用非 ...
- iptables防火墙常用命令
iptables防火墙启动停止和基本操作 iptables是centos7之前常用的防火墙,在centos7上使用了firewall 防火墙基本操作: # 查询防火墙状态 service iptabl ...
- Linux iptables防火墙
查找安装包yum list | grep iptables 安装iptables yum install iptables-services 重启防火墙使配置文件生效 systemctl restar ...
- Linux iptables 防火墙
内容摘要 防火墙 防火墙定义 防火墙分类 netfilter/iptables netfilter 设计架构 iptables 简述 iptables 命令详解 命令语法 table 参数 comma ...
随机推荐
- 牛客练习赛26 D xor序列 (线性基)
链接:https://ac.nowcoder.com/acm/contest/180/D 来源:牛客网 xor序列 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他 ...
- JS 循环遍历 总结
一.循环遍历语句 for...in... (ES5) 语法:javascript for(keys in obj){} 适用:遍历对象 说明: 1.keys表示obj对象的每一个键值对的键(键名),所 ...
- ZROI 19.07.31 AB班ACM
写在前面:非常感谢cjc和djh两位神仙带我,非常感谢他们给了我一次躺赢的机会. 虽然我被硬点成了代码手,但我写的基本每次都有一堆罚时.然而djh爷全部1A,tql. 题目按照一血时间升序,大致符合难 ...
- 移动端 使用 vConsole调试
前言 用vue 写移动端代码,有个报名页面 就在iOS 9下出现问题,vue的循环渲染都正常,一开始的数据也能取到.证明不是vue的兼容性问题 但是在用户点击按钮发现不能点击进入跳转 工具 推荐使用 ...
- CodeForces-1167C
链接: https://vjudge.net/problem/CodeForces-1167C 题意: In some social network, there are n users commun ...
- Python---项目需求分析
一.软件工程 .软件工程:工程化方法解决软件问题 操作步骤 1.需求分析 前台:给基础用户使用的页面 后台:给操作者/admin等使用的页面系统 不是服务器前后台概念 2.小米前台 商品展示 商品详情 ...
- J2EE知识总结——面试、笔试
9.2 jdk 1.8的新特性(核心是Lambda 表达式) 参考链接:http://www.bubuko.com/infodetail-690646.html (1)接口的默认方法 (给接口添加一个 ...
- chrome scrollTop 获取失败问题及解决方案
https://blog.csdn.net/h357650113/article/details/78384621
- 新建com组件项目步骤
一.菜单栏 新建->项目->ATL->ATL项目->动态链接库 后续默认完成二.菜单栏 项目->添加类->ATL控件->“写入类的命名如:CeshiMai ...
- IDEA mapping箭头要怎么样设置哈(Free MyBatis插件)
效果如下图: 当我们点击箭头的时候,会快速切换到我们相关联的类位置,就不用再像以前一样还要去找 而 Free MyBatis是一款让我们操作更加方便的插件,你值得拥有哦~~~ idea 选择 File ...