Linux防火墙规则的查看、添加、删除和修改
这里只列出比较常用的参数,详细的请查看man iptables
1、查看
iptables -nvL –line-number
-L查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数。
-n不对ip地址进行反查,加上这个参数显示速度会快很多。
-v输出详细信息,包含通过该规则的数据包数量,总字节数及相应的网络接口。
–line-number显示规则的序列号,这个参数在删除或修改规则时会用到。
2、添加
添加规则有两个参数:-A和-I。其中-A是添加到规则的末尾;-I可以插入到指定位置,没有指定位置的话默认插入到规则的首部。
当前规则:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.4 0.0.0.0/0
添加一条规则到尾部:
[root@test ~]# iptables -A INPUT -s 192.168.1.5 -j DROP
再插入一条规则到第三行,将行数直接写到规则链的后面:
[root@test ~]# iptables -I INPUT 3 -s 192.168.1.3 -j DROP
查看:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
4 DROP all -- 192.168.1.4 0.0.0.0/0
5 DROP all -- 192.168.1.5 0.0.0.0/0
可以看到192.168.1.3插入到第三行,而原来的第三行192.168.1.4变成了第四行。
3、删除
删除用-D参数
删除之前添加的规则iptables -A INPUT -s 192.168.1.5 -j DROP:
[root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP
有时候要删除的规则太长,删除时要写一大串,既浪费时间又容易写错,这时我们可以先使用--line-number找出该条规则的行号,再通过行号删除规则。
[root@test ~]# iptables -nv --line-number
iptables v1.4.7: no command specified
Try `iptables -h' or 'iptables --help' for more information.
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
删除第二行规则
[root@test ~]# iptables -D INPUT 2
4、修改
修改使用-R参数
先看下当前规则:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.5 0.0.0.0/0
将第三条规则改为ACCEPT:
[root@test ~]# iptables -R INPUT 3 -j ACCEPT
再查看下:
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
第三条规则的target已改为ACCEPT。
Linux防火墙规则的查看、添加、删除和修改的更多相关文章
- CentOS7 firewalld防火墙 启动 关闭 禁用 添加删除规则等 常用命令
CentOS7 firewalld防火墙 常用命令1.firewalld的基本使用启动: systemctl start firewalld关闭: systemctl stop firewalld查看 ...
- linux下添加删除,修改,查看用户和用户组
一.组操作 1.创建组: groupadd test #增加一个test组 2.修改组 groupmod -n test2 test #将test组的名子改成test2 3.删除组 groupdel ...
- mongodb查看操作记录方法以及用户添加删除权限修改密码
前一阵跑程序时发现一个问题,同事导出了部分数据,但是在merge回原库时竟然和原库的数据对不上,后来找了半天发现是原库数据少了. 找了很多资料发现很多人认为的操作日志和我想的不太一样...找了半条才发 ...
- linux共享内存的查看与删除
在使用共享内存的程序异常退出时,由于没有释放掉共享内存,在调试时会出现错误.您可以使用shell命令来查看与释放已经分配的共享内存,下面将详细说明如何进行查看和释放分配的共享内存的方法. 预备知识 L ...
- git查看添加删除远程仓库
查看远程仓库 git remote -v 删除远程仓库 git remote remove origin 添加远程仓库 git remote add origin 仓库地址 关联远程分支 重新关联远程 ...
- Linux 用户和组的 添加/删除
1.建用户:adduser phpq //新建phpq用户passwd phpq //给phpq用户设置密码 2.建工作组groupadd test //新建test工作组 3.新建用户同时增加工作组 ...
- Linux下创建、查看、提取和修改静态库(*.a)
先说明一点,静态库文件是由多个目标文件打包而成的,在windows下静态库文件的后缀是.lib,而在linux下静态库文件的后缀是.a(a是archive的缩写,也就是文档文件). 废话少说,下面直接 ...
- Mysql中索引的 创建,查看,删除,修改
创建索引 MySQL创建索引的语法如下: ? 1 2 3 CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name [USING index_type] ON ...
- linux通过命令行查看MySQL编码并修改-简洁版方法
云服务器环境:CentOS 7.4 因为服务器配置较低,故使用MySQL5.5 未进行设置前 1.查看字符编码: mysql> show variables like '%character%' ...
随机推荐
- 如何获取xcassets中LaunchImage图片
NSDictionary * dic = @{@"320x480" : @"LaunchImage-700", @"320x568" : @ ...
- Go的50度灰:Golang新开发者要注意的陷阱和常见错误
Go的50度灰:Golang新开发者要注意的陷阱和常见错误 http://colobu.com/2015/09/07/gotchas-and-common-mistakes-in-go-golang/
- iptables 工具
iptables 工具 参考文档: https://www.frozentux.net/iptables-tutorial/cn/iptables-tutorial-cn-1.1.19.html ...
- html中input输入框屏蔽鼠标右键
<label> <input id="ckdestinationId" type="text" oncontextmenu="ret ...
- 10 steps to becoming the developer everyone wants
You thought it was all about programming skills. But you were wrong! Great code is fine, yet command ...
- logback logback.xml常用配置详解(三)
logback logback.xml常用配置详解 <filter> <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NEUTRAL,ACCEPT其中之 ...
- Spring常用的接口和类(二)
七.BeanPostProcessor接口 当需要对受管bean进行预处理时,可以新建一个实现BeanPostProcessor接口的类,并将该类配置到Spring容器中. 实现BeanPostPro ...
- 今天逛VC驿站 的收获
1.C++ 如何定义一个定长字符串, 若不足位数,就补字符串"0"? eg: CString str1 = “123”;不足20位,前面补“0”,实现效果为“00000000000 ...
- [POJ1936]All in All
[POJ1936]All in All 试题描述 You have devised a new encryption technique which encodes a message by inse ...
- js检测是否安装了flash插件
function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 var isIE = ...