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 防火墙常用规则的更多相关文章

  1. 15.linux iptables防火墙规则vsftp服务

    一.服务所开启的端口号.          dhcp 67       samba 139 445       http 80  https 443       mysql 3306         ...

  2. Iptables 防火墙常用配置

    转至:https://blog.csdn.net/lswzw/article/details/87971259 Iptables 防火墙常用配置 概念 命令行模式 查看 & 命令 -n:直接显 ...

  3. Linux下iptables防火墙用法规则详解

    管理网络流量是系统管理员必需处理的最棘手工作之一,我们必需规定连接系统的用户满足防火墙的传入和传出要求,以最大限度保证系统免受×××.很多用户把 Linux 中的iptables当成一个防火墙,从严格 ...

  4. CentOS Linux iptables 防火墙

    快速安装,配置,启动,检查 - 关闭 5002 - 5011 端口开放所有其它 yum install iptables iptables -F iptables -X iptables -Z ipt ...

  5. iptables防火墙常用配置介绍

    参考地址 http://www.cnblogs.com/metoy/p/4320813.html http://netfilter.org/ iptables http://man.chinaunix ...

  6. linux iptables 防火墙简介

    iptables防火墙简介 Netfilter/Iptables(以下简称Iptables)是unix/linux自带的一款优秀且开放源代码的安全自由的基于包过滤的防火墙工具,它的功能十分强大,使用非 ...

  7. iptables防火墙常用命令

    iptables防火墙启动停止和基本操作 iptables是centos7之前常用的防火墙,在centos7上使用了firewall 防火墙基本操作: # 查询防火墙状态 service iptabl ...

  8. Linux iptables防火墙

    查找安装包yum list | grep iptables 安装iptables yum install iptables-services 重启防火墙使配置文件生效 systemctl restar ...

  9. Linux iptables 防火墙

    内容摘要 防火墙 防火墙定义 防火墙分类 netfilter/iptables netfilter 设计架构 iptables 简述 iptables 命令详解 命令语法 table 参数 comma ...

随机推荐

  1. psu补丁

    1.查看命令 su - oracle opatch lspatches su - grid opatch lspatches

  2. 【HDU4034】Graph

    题目大意:给定一个图的最短路,求原图中至少存在多少条边. 题解:利用 Floyd 的性质,枚举边 d[i][j],若存在一个不是两端点的点,使得 d[i][j]=d[i][k]+d[k][j] 成立, ...

  3. Python修炼之路-Socket

    网络编程 socket套接字 socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄,应用程序通常通过“套接字”向网络发出请求或者应答网络请求. socket ...

  4. ax2+bx+c=0的根的算法

    每日一练作业 写一个函数,接受三个整数a, b, c,计算ax2+bx+c=0 的根. 另外,在计算时应当判断 b2 - 4ac 是否大于0. 我们什么都没有,唯一的本钱就是青春.梦想让我与众不同,奋 ...

  5. 移动端ios和安卓input问题

    在钉钉开发微应用的时候. 安卓和苹果输入input框的时候.失去焦点和获取焦点会有明显的上下跳动 因此我用绝对定位把位置固定在一个地方.就不会有跳动

  6. 【leetcode】638. Shopping Offers

    题目如下: In LeetCode Store, there are some kinds of items to sell. Each item has a price. However, ther ...

  7. python 使用嵌套函数报local variable xxx referenced before assignment或者 local variable XXX defined in enclosing scope

    情况一: a 直接引用外部的,正常运行 def toplevel(): a = 5 def nested(): print(a + 2) # theres no local variable a so ...

  8. linux-文件系统-5

    cat /proc/partions cat /proc/mounts mount [options] -o [option] -t 文件类型 设备 挂载目录 设备: (1)设备文件:例如/dev/s ...

  9. teradata安装

    一,下载 步骤1 - 从链接下载所需的VM版本,http://downloads.teradata.com/download/database/teradata-express-for-vmware- ...

  10. js 数组 splice 函数 多线程

    <script type="text/javascript"> var arr = new Array(6) arr[0] = "00" arr[1 ...