iptables 防火墙(下)
iptables 防火墙(下)
1. 常见的隐含匹配条件:
1.1 端口匹配: --sport 源端口、--dport 目的端口

1.2 TCP标记匹配: -tcp-flags 检查范围被设置的标记

1.3 ICMP类型匹配: --icmp-type ICMP类型常见的icmp类型
- 8 Echo request--->回显请求( Ping请求)
- 8 0 Echo Reply--->回显应答(Ping 应答)
- 8 3 错误回显

2. 常用的显示匹配条件:
2.1 多端口匹配:
- -m multiport --sports源端口列表、
- -m multiport --dports目的端口列表

2.2 IP范围匹配:
-m iprange --src-range IP范围

2.3 MAC地址匹配:
-m mac --mac-source MAC地址

2.4 状态匹配: -m state --state 连接状态
- 常见的连接状态:
- NEW: 新连接,与任何连接无关
- ESTABLISHED: 响应请求或已建立连接的
- RELATED: 与已连接有相关性的,如FTP数据连接


3.SNAT策略
3.1 SNAT作用:
局域网主机共享单个公网IP地址接入Internet
3.2 SNAT策略的原理
源地址转换,Source Network Address Translation修改数据包的源地址
3.3 固定的外网IP地址

[root@iptables02 ~]# iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -o eth1 -j SNAT --to-source 192.168.100.100
3.4 非固定外网IP地址或ADSL

[root@iptables02 ~]# iptables -t nat -I POSTROUTING -s 192.168.200.0/24 -o eth0 -j MASQUERADE
4. DNAT策略
4.1 DNAT 原理
在Internet环境中,通过网关服务器中正确设置DNAT策略可实现企业所注册的网站或域名必须对应公网IP地址。
4.2 DNAT转发规则1:发内网Web服务

[root@iptables02 ~]# iptables -t nat -A PREROUTING -i eth1 -d 192.168.100.100 -p tcp --dport 80 -j DNAT --to-destination 192.168.200.99
4.3 (2) DNAT转换规则2:发布时修改目标端口

[root@iptables02 ~]# iptables -t nat -A PREROUTING -i eth1 -d 192.168.100.100 -p tcp --dport 80 -j DNAT --to-destination 192.168.200.99:8080
5. 项目实战
项目要求:三台主机,要求其中部署Nginx(iptables01),另外一台可以查看到网页内容
注:主机2与主机3均无网关
5.1 部署环境
| 主机名 | 主机IP(1) | 主机IP(2) | 网卡模式(1) | 网卡模式(2) | 主机网关 |
|---|---|---|---|---|---|
| iptables01 | 192.168.200.99 | NET8 | 192.168.200.100 | ||
| iptables02 | 192.168.200.100 | 192.168.100.100 | NET8 | NET1(仅主机) | |
| iptables03 | 192.168.100.110 | NET8 |
5.2 部署网卡配置文件
5.2.1 iptables01的网卡配置文件
[root@iptables01 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@iptables01 network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.200.99 #本主机的IP
NETMASK=255.255.255.0
GATEWAY=192.168.200.100 #本主机的网关,iptables02第一个网卡的IP
5.2.2 iptables02的网卡配置文件
[root@iptables02 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@iptables02 network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.200.100 #本主机的IP,iptables01的网关
NETMASK=255.255.255.0
[root@iptables02 network-scripts]# cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.100.100 #本主机的IP,iptables03的网关
NETMASK=255.255.255.0
5.2.3 iptables03的网卡配置文件
[root@iptables03 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@iptables03 network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.100.110 #本主机的IP
NETMASK=255.255.255.0
5.2.4 Nginx
Nginx部署略。。。
[root@iptables01 ~]# curl www.yangwenbo.com
192.168.200.99 welcome to yunjisuan Nginx网页内容
5.3 修改iptables02转发的配置
[root@iptables02 /]# sed -n '7p' /etc/sysctl.conf
net.ipv4.ip_forward = 1 #修改成1
5.4 对来往网卡IP做限制

[root@iptables02 ~]# iptables -t nat -A POSTROUTING -s 192.168.200.0/24 -o eth1 -j SNAT --to-source 192.168.100.100
[root@iptables02 ~]# iptables -t nat -A PREROUTING -i eth1 -d 192.168.100.100 -p tcp --dport 80 -j DNAT --to-destination 192.168.200.99:8080
[root@iptables02 ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere 192.168.100.100 tcp dpt:http to:192.168.200.99:8080
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
SNAT all -- 192.168.200.0/24 anywhere to:192.168.100.100
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
5.5 PC主机映射并查看
[root@iptables03 ~]# curl www.yangwenbo.com
192.168.200.99 welcome to yunjisuan
iptables 防火墙(下)的更多相关文章
- 在iptables防火墙下开启vsftpd的端口
在开启vsftpd端口后发现用客户端工具能登陆,但无法浏览文件和新建文件.此时看了一下ftp的协议,发现ftp有主动模式和被动模式.在服务端开21端口是让客户端进来,并没有出去的端口,还在服务端开启出 ...
- Linux下iptables防火墙用法规则详解
管理网络流量是系统管理员必需处理的最棘手工作之一,我们必需规定连接系统的用户满足防火墙的传入和传出要求,以最大限度保证系统免受×××.很多用户把 Linux 中的iptables当成一个防火墙,从严格 ...
- CentOS下配置iptables防火墙 linux NAT(iptables)配置
CentOS下配置防火墙 配置nat转发服务CentOS下配置iptables防火墙 linux NAT(iptables)配置 CentOS下配置iptables 1,vim /etc/syscon ...
- (转载)Linux下IPTABLES防火墙的设定
(转载)http://www.jefflei.com/post/1760.html 1.iptables防火墙启动和停止 启动iptables防火墙时命令行输入 #service iptables s ...
- centos6.5下系统编译定制iptables防火墙扩展layer7应用层访问控制功能及应用限制QQ2016上网
iptables防火墙扩展之layer7应用层访问控制 概述: iptables防火墙是工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙.以基于网络层的数据包过滤机制为主,同 ...
- Linux下 iptables防火墙 放开相关port 拒绝相关port 及查看已放开port
我用的是fedora 14 1. 查看iptables 防火墙已经开启的port:/etc/init.d/iptables status [root@hzswtb2-mpc ~]#/etc/rc.d/ ...
- Centos7下安装iptables防火墙
说明:centos7默认使用的firewalld防火墙,由于习惯使用iptables做防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables进行防火墙规则设 ...
- 编译内核实现iptables防火墙layer7应用层过滤 (三)
在前面的两篇文章中我们主要讲解了Linux防火墙iptables的原理及配置规则,想博友们也都知道iptables防火墙是工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙.以 ...
- [moka同学摘录]iptables防火墙规则的添加、删除、修改、保存
文章来源:http://www.splaybow.com/post/iptables-rule-add-delete-modify-save.html 本文介绍iptables这个Linux下最强大的 ...
随机推荐
- JavaScript阶乘算法
题目: 计算所提供整数的阶乘. 如果使用字母n代表一个整数,则阶乘是所有小于或等于n的整数的乘积. 阶乘通常简写成 n! 例如: 5! = 1 * 2 * 3 * 4 * 5 = 120 使用递归实现 ...
- JDBC、ibatis(mybatis)、Hibernate有什么不同?
①JDBC编程流程固定,同时将sql语句和java代码混在了一起,经常需要拼凑sql语句,细节很繁琐: ②ibatis(mybatis)它不完全是一个ORM框架,因为MyBatis需要程序员自己编写S ...
- Qt Unknown module(s) in QT: webengine
到今天位置好像Qt 出到了5.10还是5.9.x吧,本身是用MSVC 5.7.0本身就有支持 webengine这个模块 然后跟风升级了5.9.1,公司项目不用qt框架了用VC渣渣6.0.....然后 ...
- 【leetcode】998. Maximum Binary Tree II
题目如下: We are given the root node of a maximum tree: a tree where every node has a value greater than ...
- Centos MySQL 5.7安装、升级教程
MySQL 5.7安装.升级笔记分享: 卸载当前的 MySQL 查看当前 MySQL 版本: ? 1 2 [root@coderknock ~]# mysql -V mysql Ver 14.14 D ...
- PHP filter_var() 函数
定义和用法 filter_var() 函数通过指定的过滤器过滤一个变量. 如果成功,则返回被过滤的数据.如果失败,则返回 FALSE. 语法 filter_var(variable, filter, ...
- POJ 3414 Pots (dfs,这个代码好长啊QAQ)
Description You are given two pots, having the volume of A and B liters respectively. The following ...
- APICloud框架——总结一下最近开发APP遇到的一些问题 (二)
高度自适应 flex布局 允许子元素伸缩 手机号正则 function checkPhone(data){ if(!(/^1[34578]\d{9}$/.test(data))){ alert(&qu ...
- window环境mysql卸载不干净
停止MySQL服务1添加删除程序中卸载MySQL2到安装目录删除MySQL3删除:C:\Documents and Settings\All Users\Application Data\MySQL ...
- AcWing 214. Devu和鲜花 (容斥)打卡
Devu有N个盒子,第i个盒子中有AiAi枝花. 同一个盒子内的花颜色相同,不同盒子内的花颜色不同. Devu要从这些盒子中选出M枝花组成一束,求共有多少种方案. 若两束花每种颜色的花的数量都相同,则 ...