Cyber_Security_Notes/B. 第二阶段/拓扑练习/0902_NAPT.md
2024-09-02 15:17:45 +08:00

258 lines
7.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# NAPT
![image-20240902111523228](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240902111523228.png)
### 一、IP & Routing
- **PC、Client、Server**
- **AR1**
```
[AR1]int g0/0/0
[AR1-GigabitEthernet0/0/0]ip add 192.168.1.254 24
[AR1-GigabitEthernet0/0/0]int g0/0/1
[AR1-GigabitEthernet0/0/1]ip add 100.1.1.1 29
[AR1-GigabitEthernet0/0/1]quit
[AR1]ip route-static 0.0.0.0 0 100.1.1.2
```
- **IPX-dx**
```
[ISP-dx]int g0/0/0
[ISP-dx-GigabitEthernet0/0/0]ip add 100.1.1.2 29
[ISP-dx-GigabitEthernet0/0/0]int g0/0/1
[ISP-dx-GigabitEthernet0/0/1]ip add 200.1.1.254 24
```
### 二、ACL + NAPT单一公网地址
#### 1、配置
- **AR1**
```
[AR1]acl 2000
[AR1-acl-basic-2000]rule 10 permit source 192.168.1.0 0.0.0.255
[AR1-acl-basic-2000]quit
[AR1]nat address-group 1 100.1.1.3 100.1.1.3 //单公网地址
[AR1]int g0/0/1
[AR1-GigabitEthernet0/0/1]nat outbound 2000 address-group 1
```
*解析:*
> 见 `0902_动态NAT.md`
#### 2、测试
- **PC PING Server**
```
PC>ping 200.1.1.1
Ping 200.1.1.1: 32 data bytes, Press Ctrl_C to break
From 200.1.1.1: bytes=32 seq=1 ttl=253 time=63 ms
From 200.1.1.1: bytes=32 seq=2 ttl=253 time=78 ms
From 200.1.1.1: bytes=32 seq=3 ttl=253 time=62 ms
From 200.1.1.1: bytes=32 seq=4 ttl=253 time=47 ms
From 200.1.1.1: bytes=32 seq=5 ttl=253 time=63 ms
--- 200.1.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/62/78 ms
```
- **Client** *【success】*
![image-20240902113419644](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240902113419644.png)
> 多访问几次HTTP服务
- **AR1**
> [AR1]dis nat session all //显示NAT会话表
```
<AR1>dis nat session all
NAT Session Table Information:
Protocol : TCP(6)
SrcAddr Port Vpn : 192.168.1.3 520
DestAddr Port Vpn : 200.1.1.1 20480
NAT-Info
New SrcAddr : 100.1.1.3
New SrcPort : 10241
New DestAddr : ----
New DestPort : ----
Protocol : TCP(6)
SrcAddr Port Vpn : 192.168.1.3 1032
DestAddr Port Vpn : 200.1.1.1 20480
NAT-Info
New SrcAddr : 100.1.1.3
New SrcPort : 10243
New DestAddr : ----
New DestPort : ----
Protocol : TCP(6)
SrcAddr Port Vpn : 192.168.1.3 776
DestAddr Port Vpn : 200.1.1.1 20480
NAT-Info
```
***解析: (以第一块信息为例)***
- NAT会话表的信息提供了关于当前活跃的NAT会话的详细信息。以下是输出内容的解释
- **Protocol**: 传输控制协议TCP其协议号为6。
- **SrcAddr Port Vpn**: 源地址和源端口号以及VPN实例。在这里源地址是192.168.1.3源端口号是520。
- **DestAddr Port Vpn**: 目的地址和目的端口号以及VPN实例。这里的目的地址是200.1.1.1目的端口号是20480。
**NAT-Info** 部分显示了NAT转换后的信息
- **New SrcAddr**: 转换后的源地址这里是100.1.1.3这是地址组1中配置的公网IP地址。
- **New SrcPort**: 转换后的源端口号这里是10241。这表明源端口号也发生了转换这在NAT过程中是常见的称为端口映射Port Mapping或端口转发Port Forwarding
- **New DestAddr** 和 **New DestPort**: 目的地址和目的端口号在NAT转换过程中通常保持不变因此这里显示为"----"。
> 这意味着来自192.168.1.3的源地址和端口号520的数据包在经过NAT转换后会使用新的源地址100.1.1.3和新的端口号10241去访问目的地址200.1.1.1的端口号20480。这种转换允许内部网络中的主机通过公网IP地址访问外部网络。
>
>
### 三、ACL + NAPT复数公网地址
#### 1、配置
- **AR1**
> 删除之前的配置信息
```
[AR1]int g0/0/1
[AR1-GigabitEthernet0/0/1]undo nat outbound 2000 address-group 1
[AR1-GigabitEthernet0/0/1]quit
[AR1]undo acl 2000
[AR1]undo nat address-group 1
```
- **AR1**
```
[AR1]acl 2000
[AR1-acl-basic-2000]rule 10 permit source 192.168.1.0 0.0.0.255
[AR1-acl-basic-2000]quit
[AR1]nat address-group 1 100.1.1.3 100.1.1.5 //复数公网地址
[AR1]int g0/0/1
[AR1-GigabitEthernet0/0/1]nat outbound 2000 address-group 1
```
*解析:*
- `[AR1]nat address-group 1 100.1.1.3 100.1.1.5`创建或修改编号为1的NAT地址组将包含从100.1.1.3到100.1.1.5的IP地址范围
#### 2、测试
- **AR1**
```
<AR1>dis nat session all
NAT Session Table Information:
Protocol : TCP(6)
SrcAddr Port Vpn : 192.168.1.5 264
DestAddr Port Vpn : 200.1.1.1 20480
NAT-Info
New SrcAddr : 100.1.1.3
New SrcPort : 10240
New DestAddr : ----
New DestPort : ----
Protocol : TCP(6)
SrcAddr Port Vpn : 192.168.1.4 264
DestAddr Port Vpn : 200.1.1.1 20480
NAT-Info
New SrcAddr : 100.1.1.5
New SrcPort : 10250
New DestAddr : ----
New DestPort : ----
Protocol : TCP(6)
SrcAddr Port Vpn : 192.168.1.3 2568
DestAddr Port Vpn : 200.1.1.1 20480
NAT-Info
New SrcAddr : 100.1.1.4
New SrcPort : 10244
New DestAddr : ----
New DestPort : ----
```
### 四、ACL + NAPT网段内无冗余IP
![image-20240902141522705](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240902141522705.png)
| 网段 | 网络地址 | 可用主机地址 | 广播地址 | 子网掩码 |
| ------------- | --------- | --------------------- | --------- | --------------- |
| 100.1.1.0 /29 | 100.1.1.0 | 100.1.1.1 & 100.1.1.2 | 100.1.1.3 | 255.255.255.252 |
#### 1、IP & Routing
- **AR1**
```
[AR1]int g0/0/0
[AR1-GigabitEthernet0/0/0]ip add 192.168.1.254 24
[AR1-GigabitEthernet0/0/0]int g0/0/1
[AR1-GigabitEthernet0/0/1]ip add 100.1.1.1 30
[AR1-GigabitEthernet0/0/1]quit
[AR1]ip route-static 0.0.0.0 0 100.1.1.2
```
- **IPX-dx**
```
[ISP-dx]int g0/0/0
[ISP-dx-GigabitEthernet0/0/0]ip add 100.1.1.2 30
[ISP-dx-GigabitEthernet0/0/0]int g0/0/1
[ISP-dx-GigabitEthernet0/0/1]ip add 200.1.1.254 24
```
#### 2、ACL
- **AR1**
```
[AR1]acl 2000
[AR1-acl-basic-2000]rule 10 permit source 192.168.1.0 0.0.0.255
[AR1-acl-basic-2000]quit
[AR1]int g0/0/1
[AR1-GigabitEthernet0/0/1]nat outbound 2000
```
#### 3、NAPT
- **AR1**
```
```
### 五、NAT-Server添加内网服务器
![image-20240902151642145](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240902151642145.png)
![image-20240902151333560](https://picgo-noriu.oss-cn-beijing.aliyuncs.com/Images/image-20240902151333560.png)
#### 1、配置
- **IP & Routing**
-