当前位置:网站首页>SNAT、DNAT 防火墙规则的备份和还原
SNAT、DNAT 防火墙规则的备份和还原
2022-07-28 16:25:00 【云归有鹤】
前言:主播这几天有心事,所以没有前言拐友们

目录
1.6.1先给两台机器安装httpd服务和iptables服务
1.SNAT原理及应用
局域网主机共享单个公网IP地址接入Internet(私有IP不能在Internet中正常路由)
1.2.SNAT原理
源地址转换,根据指定条件修改数据包的源IP地址,通常被叫做源映射
简单来说就是修改数据包的源地址
1.3.SNAT转换前提条件
1.局域网各个主机已正确设置IP地址、子网掩码、默认网关地址
2.Linux网关开启IP路由转发
临时打开:
echo 1 > /proc/sys/net/ipv4/ip_forward
或
sysctl -w net.ipv4.ip_forward=1两种方法
永久打开:
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1 将此行写入配置文件
sysctl -p 将取修改后的配置
1.4SNAT转换1:固定的公网IP地址
1.iptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o ens37 -j SNAT --to 10.0.0.1
2.ptables -t nat -A POSTROUTING -s 192.168.100.0/24 -o ens37 -j SNAT --to-source 10.0.0.1-10.0.0.10两种
3.192.168.100.0/24内网ip , -o 出站外网网卡ens37 ,10.0.0.1-10.0.0.10外网ip或地址池
1.5小知识扩展
一个ip地址做SNAT转换,一般可以让内网100到200台主机实现上网
1.6DNAT实验
1.6.1先给两台机器安装httpd服务和iptables服务


1.6.2将原有的网络改成自定义模式并多添加一张网卡


1.6.3修改ens33和ens37的网卡并重启



1.6.4永久开启IP路由的转发


1.6.5SNAT转换:固定的公网IP地址

1.6.6 修改第二台机器的网卡并重启



安装apache服务并验证
1.6.7修改windows配置


1.6.8验证结果

2.DNAT转换前提条件
2.1DNAT转换前提条件
1.局域网的服务器能够访问Internet
2.网关的外网地址有正确的DNS解析记录
3Linux网关开启IP路由转发
打开DNAT
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p2.2DNAT 应用环境
1.在Internet中发布位于局域网内的服务器
2.3DNAT原理
1.修改数据包的目的地址
2.4DNAT转换1:发布内网的Web服务
1.#把从ens33进来的要访问web服务的数据包目的地址转换为 192.168.100.118
iptables -t nat -A PREROUTING -i ens33 -d 12.0.0.1 -p tcp--dport 80 -j DNAT --to 192.168.100.118
或
2.iptables -t nat -A PREROUTING -i ens33 -d 12.0.0.1 -p tcp--dport 80-j DNAT --to-destination 192.168.100.118
入站|外网网卡 | 外网ip 内网服务器ip
2.5DNAT转换2∶ 发布时修改目标端口
1.#发布局域网内部的OpenSSH服务器, 外网主机需使用250端口进行连接
iptables-t nat -A PREROUTING -i ens33 -d 12.0.0.1 -p tcp--dport 250-jDNAT --to 192.168.100.102:22
2.6DNT案例
2.6.1修改window的网络配置


2.6.2修改第二台虚拟机的网卡并重启
![]()
![]()


2.6.3设置DNAT转换
2.6.4验证结果

3.总结
SNAT与DNAT是对防火墙数据传输的完美诠释
边栏推荐
- Goweb开发之Beego框架实战:第一节 Beego框架介绍
- Why do I choose to use go language?
- Microservice Architecture - service registry and service gateway (6.8) (Reprint)
- 零基础利用Unity3D开发AR应用并远程下载3D模型
- 堡垒机的作用
- Use of influxdb2
- Visual studio 2012/2015 releases web applications together with.Cs source code
- Verilog daily question (vl6 data series to parallel circuit)
- Verilog 每日一题 (VL28 加减计数器)
- 高速电路设计实践——概述
猜你喜欢

使用阿里云免费的SSL证书

net框架

Unity shader uses rendered texture to achieve glass effect

Verilog daily question (vl6 data series to parallel circuit)

Use Alibaba cloud's free SSL certificate

Unity3d shader achieves ablation effect

Goweb开发之Beego框架实战:第四节 数据库配置及连接

Verilog daily question (vl5 signal generator)

Net framework

Unity shader realizes water wave effect with noise texture
随机推荐
【impala】【报错解决】 Impala cannot read or execute the parent directory of dfs.domain.socket.path的解决方法
高速电路设计实践——概述
Self study examination in April 2021
Janus series article 3 API usage guide videoroom creating a new video room
Pytorch Foundation: similarities and differences between torch.mul, torch.mm and torch.matmul
Differences between CNSA and CASC and CASIC
Some attention code explanations
Algorithm learning: leetcode interview question 09. implement queue with two stacks
Verilog 每日一题(VL29 单端口RAM)
Using SQL server agent job to restore the database regularly
线性代数及矩阵论(七)
侦察机与预警机的区别
Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
Gray code and binary conversion and typical examples (4bits gray code counter)
Learn about service discovery in kubernetes
Verilog daily question (simple implementation of VL30 RAM)
Kubernetes service and ingress you need to master
The actual combat of the beego framework of goweb development: Section III program execution process analysis
微服务架构-服务注册中心和服务网关(6.8) (转载)
Steps to configure V530 switch