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 ...
随机推荐
- apache 修改文件上传大小限制
Windows 环境下的修改方法 ================================================================ 第一步:修改在php5下POST文件 ...
- h5 实现页面上拉加载更多数据
您好,您的上拉加载更多的代码来喽: html:(style部分:html部分:js部分--js部分主要就是监控上拉,调接口) //上拉加载更多css <style> .wait-loadi ...
- linux yum错误
一. 错误:File contains no section headers. file: file:///etc/yum.repos.d/upgrade.repo, line: 1 'name=Ce ...
- Eureka实现高可用及为Eureka设置登录账号和密码
本文通过两个eureka相互注册实现注册中心的高可用,同时为注册中心配置认证登录. 需要用到的maven配置 <dependency> <groupId>org.springf ...
- Codeforces 989 P循环节01构造 ABCD连通块构造 思维对云遮月参考系坐标轴转换
A 直接判存不存在连续的三个包含A,B,C就行 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a ...
- Kong组件构成及使用
Service: Service 顾名思义,就是我们自己定义的上游服务,通过Kong匹配到相应的请求要转发的地方 Service 可以与下面的Route进行关联,一个Service可以有很多Route ...
- Java并发编程实战 第13章 显式锁
接口Lock的实现类: ReentrantLock, ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock Reentra ...
- Connection refused 排查过程
Connection refused 排查过程 connection refused 排查 起因 今天在连接 rabbitmq 时,报 Connection refused (如下图),借此机会记 ...
- 使用注解方式实现账户的CRUD
1 需求和技术要求 1.1 需求 实现账户的CRUD. 1.2 技术要求 使用Spring的IOC实现对象的管理. 使用QueryRunner作为持久层的解决方案. 使用C3p0作为数据源. 2 环境 ...
- MySQL不常用、易忽略的小知识
笔者从事开发也有一段时间了,关于数据库方面的一些小知识在这里总结一下 1.count(*),count(1)与count(column)区别 count(*)对行的数目进行计算,包含NULL coun ...