iptables 指定网卡_LINUX系统下的IPTABLES防火墙系统讲解(二)实战操作
![](/assets/blank.gif)
iptables
![](/assets/blank.gif)
数据流方向
iptables操作命令:
#iptables --help
Usage: iptables -[AD] chain rule-specification [options]
iptables -[RI] chain rulenum rule-specification [options]
iptables -D chain rulenum [options]
iptables -[LFZ] [chain] [options]
iptables -[NX] chain
iptables -E old-chain-name new-chain-name
iptables -P chain target [options]
iptables -h (print this help information)
--append -A chain 追加规则
--delete -D chain 删除规则
--delete -D chain rulenum 删除指定序号的规则
--insert -I chain [rulenum] 插入一条规则(default 1=first)
--replace -R chain rulenum 替换一条规则
--list -L [chain] 显示出链或者链中的规则
--flush -F [chain] 在一个链或者所有链中清空规则
--zero -Z [chain] 清空计数
--new -N chain 创建用户自定义链
--delete-chain
-X [chain] 删除用户自定义链
--policy -P chain target 指定默认规则
Change policy on chain to target
--rename-chain
-E old-chain new-chain
重命名用户自定义链
Options:
--proto -p [!] proto 指定协议,!代表取反
--source -s [!] address[/mask] --指定源地址
source specification
--destination -d [!] address[/mask] --指定目标地址
destination specification
--in-interface -i [!] input name[+] --指定数据从哪个网口进来
network interface name ([+] for wildcard)
--jump -j target --匹配动作
target for rule (may load target extension)
--goto -g chain
jump to chain with no return
--match -m match --扩展匹配
extended match (may load extension)
--numeric -n --端口和IP以数值方式显示,不作反解
--out-interface -o [!] output name[+] --指定数据从哪个网口出去
network interface name ([+] for wildcard)
--table -t table --指定使用哪个表 (default: `filter')
--verbose -v --显示详细信息
--line-numbers --显示规则的序号
--exact -x expand numbers (display exact values)
传输层:协议(tcp/udp)
端口(sport/dport)
网络层:
IP地址(sip/dip/icmp)
数据链路层:
mac地址(--mac-source)
物理层:
从哪个网卡进来 -i
从哪个网卡出去 -o
---------------
![](/assets/blank.gif)
iptables
查看:
# iptables -t nat -L -n -v --line
# iptables -t filter -L -n
# iptables -t filter -L INPUT
# iptables -t filter -L INPUT -v -n
# iptables -t filter -L INPUT -n -v --line
# watch -n 0.1 iptables -L INPUT --line -n -v
追加规则:
# iptables -t filter -A INPUT -i lo -j ACCEPT
插入规则:
# iptables -t filter -I INPUT -i eth0 -j ACCEPT --插入成为第一条
# iptables -t filter -I INPUT 3 -i eth0 -j ACCEPT --插入成为第三条规则
替换规则:
# iptables -t filter -R INPUT 3 -i eth1 -j ACCEPT --替换成为指定规则
删除规则:
# iptables -t filter -D INPUT 2 --删除指定链指定编号的规则
+++++++++++
#iptables -t filter -A INPUT -i lo -j ACCEPT
#iptables -t filter -A OUTPUT -o lo -j ACCEPT
#iptables -t filter -A INPUT -i eth0 -s 192.168.0.0/24 -d 192.168.0.250 -j ACCEPT
# iptables -t filter -A INPUT -i eth1 -j ACCEPT
# iptables -L INPUT -n --line -v
# iptables -t filer -I INPUT 2 -i eth2 -j ACCEPT 插入默认第二条
# iptables -t filter -I INPUT -i eth3 -j ACCEPT 插入默认第一条
# iptables -t filter -R INPUT 1 -i eth4 -j ACCEPT 替换默认第一条
#iptables -t filter -D INPUT 1 删除默认第一条
# iptables -t filter -F INPUT 清空filter所有INPUT链
#iptables -t filter -F
#iptables -L INPUT -n --line -v
+++++++++++++++++++
清空规则:
1、清空一张表
# iptables -t filter -F
2、清空一条链中的规则
# iptables -t filter -F INPUT
新建/删除用户自定义的链:
# iptables -t filter -N uplooking新建
# iptables -t filter -X uplooking 删除
# iptables -t filter -X 清空filter表中所有用户自定义链
+++++++++
iptables -t filter -N TCP
iptables -t filter -N UDP
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A INPUT -p tcp -j TCP
++++++++
更改默认规则:
# iptables -t filter -P INPUT ACCEPT
# iptables -t filter -P INPUT DROP
实例应用一(本机的访问控制):
拒绝所有:允许本机能访问所有服务,允许访问DNS,postfix,dovecot,vsftpd,telnet,web,
iptables -t filter -P INPUT DROP
iptables -t filter -P OUTPUT DROP
1.允许本机访问本机的所有服务:
[root@mail ~]# iptables -t filter -A INPUT -i lo -j ACCEPT
[root@mail ~]# iptables -t filter -A OUTPUT -o lo -j ACCEPT
+++++++++
iptables -t filter -A INPUT -p tcp -dport 5902 -i br0 -s 192.168.0.45 -j ACCEPT
iptables -t filter -A OUTPUT -o br0 -p tcp --sport 5902 -d 192.168.0.45 -j ACCEPT
iptables -L -n -v --line
iptables -t filter -A INPUT -i br0 -p tcp --dport 5900:5902 -s 192.168.0.0/24 -j ACCEPT
iptables -t filter -A OUTPUT -o br0 -p tcp --sport 5900:5902 -d 192.168.0.0/24 -j ACCEPT
++++++++++++++
2.允许指定客户机访问我的80端口
[root@mail ~]# iptables -t filter -A INPUT -i eth0 -p tcp --dport 80 -s 10.1.1.111 -j ACCEPT
[root@mail ~]# iptables -t filter -A OUTPUT -o eth0 -p tcp --sport 80 -d 10.1.1.111 -j ACCEPT
[root@mail ~]# iptables -t filter -A INPUT -i eth0 -p tcp --dport 80 -s 10.1.1.0/24 -j ACCEPT
[root@mail ~]# iptables -t filter -A OUTPUT -o eth0 -p tcp --sport 80 -d 10.1.1.0/24 -j ACCEPT
[root@mail ~]# iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
[root@mail ~]# iptables -A OUTPUT -o eth0 -p tcp --sport 22 -j ACCEPT
# iptables -t filter -R INPUT 2 -p tcp -m multiport --dport 20:21,80,443,5900 -j ACCEPT
# iptables -t filter -R OUTPUT 2 -p tcp -m multiport --sport 20:21,80,443,5900 -j ACCEPT
[root@mail ~]# service iptables save --防火规则马上写马上生效,但重启机器或者重iptables服务,规则丢失.
将当前规则保存到 /etc/sysconfig/iptables: [确定]
从非默认位置恢复规则:
# iptables-save > /tmp/iptables.save
# iptables-restore < /tmp/iptables.save
icmp:
[root@mail ~]# iptables -t filter -i eth0 -A INPUT -p icmp -j ACCEPT
[root@mail ~]# iptables -t filter -o eth0 -A OUTPUT -p icmp -j ACCEPT
iptables 指定网卡_LINUX系统下的IPTABLES防火墙系统讲解(二)实战操作相关推荐
- PL/SQL Developer 在windows7 64位系统下连Oaracle11g64位系统的解决经验
PL/SQL Developer 在windows7 64位系统下连Oaracle11g64位系统的解决经验 一.问题现象及解决方法 现象: 1.PL/SQL 无法登录64位数据库 2.在PL/SQL ...
- XP或Win7系统下grub4dos安装双系统ubuntu(32或64)
1.grub4dos在xp系统下引导安装ubuntu系统 先不要删除相关文件,只装好ubuntu不要按照文档做其他修改,保留一会 http://pan.baidu.com/s/1o6wiFr0 这个只 ...
- xp的服务器系统怎么安装win7系统教程,怎么在xp系统下安装win7双系统教程
很多小伙伴跟着网上一些教程学习在xp系统下安装win7双系统,结果失败了,百思不得其解,不知道到底自己到底错在哪里,那么,怎么在xp系统下安装win7双系统?下面快启动小编就为大家分享详细的图文教程, ...
- 在 Windows10 系统下重新安装 Ubuntu22.04 系统
在 Windows10 系统下重新安装 Ubuntu22.04 系统 本文根据 tianyvHon 成功安装为背景,进行详细地讲解在 Windows10 系统下重新安装 Ubuntu22.04 系统. ...
- w ndows7怎么安装,《联想Y460在Wndows7系统下完美安装XP系统的方法.doc
<联想Y460在Wndows7系统下完美安装XP系统的方法 联想Y460在Windows?7系统下完美安装XP系统的方法与注 随着论坛众多Y460用户的出现,各种求助的帖子越来越多,其中最突出的 ...
- 双系统下grub引导windows系统
双系统下grub引导windows系统 我在一台本来有windows的电脑上安装了arch linux,在grub里是没有windows系统的,于是搜索各种文章,花费好长时间才成功.在这里分享一下我的 ...
- mac nginx php-fpm,Mac系统下搭建Nginx+php-fpm实例讲解
分享背景 由于一直在虚拟机的状态下开发PHP,尝试一下mac本地搭建环境.mac本身是自带Apache+php的,在低版本的mac系统中,mac中的php版本是5.6的版本. 本文分享的是在mac的1 ...
- xp的服务器系统怎么安装win7系统教程,教你xp系统下安装win7双系统的教程
双系统就是在计算机上安装两个操作系统,有的网友在问怎么在xp系统下安装Win7双系统,那么今天在这里就为大家分享xp系统下安装Win7双系统的图解教程. 材料/工具 win7的镜像文件, DAEMON ...
- Linux系统下查看和修改 系统时间和硬件时间
Linux系统下查看和修改 系统时间和硬件时间 1.具体命令使用如下: 查看当前系统时间 [root@littlelawson hbase-1.4.0]# date Mon Jun 18 10:36: ...
最新文章
- angular react_Angular 2 vs React:将会有鲜血
- Visual Basic 2005 – 如何播放剪贴簿中的音效数据
- 在线作图|在线做扩增子抽平
- 30年来我只坚持三件事
- OSPF综合(上)---配置
- boost::heap模块实现可变堆的测试程序
- yum配置文件 重启后还原_江湖救急 : CentOS7.5 /usr 目录误删, 恢复操作.
- 负载均衡工具 haproxy剖析
- php转盘中奖率,PHP大转盘中奖概率算法实例_PHP
- Django学习1---安装Django,创建、启动项目
- ql的python学习之路-day3
- I/O(输入/输出)---字节流与字符流
- VeraCrypt文件硬盘加密使用教程
- excel手机版_excel仓库管理手机版导出软件
- 单层for循环最详解
- Cygwin下载安装
- 利用wine使用msoffice软件
- 蓝桥杯泊松分酒java_蓝桥杯-泊松分酒 - steven_wjg的个人空间 - OSCHINA - 中文开源技术交流社区...
- 3年自动化测试,我突然想转测试开发了,开发测试工具平台......
- 基于改进型生成对抗网络生成异构故障样本的方法
热门文章
- centos安装--两张光盘
- 【计算机网络复习 数据链路层】3.3.2 差错控制(纠错编码)
- 计算机应用基础案例实训教程,计算机应用基础案例式实训教程
- fir c语言程序,fir.rar fir的c语言程序 - 下载 - 搜珍网
- matlab/ansys协同的一个例子
- 数字图像处理-1.图像获取
- 建立带头结点的双向链表_尾插法
- SSD300网络结构(pytorch)+多尺度训练与测试
- 《Python 黑科技》探查Mysql数据库,输出数据质量报告
- CompletableFuture详解~思维导图