1、NAT是什么:
NAT(network address translation)为网络地址转换,用于实现私有网络和公有网络之间的访问
公网地址和私网地址:
公网地址在互联网上有唯一的标识,到2019年11月26日,公网地址使用完毕,现在需要公网地址只能花钱买。
私网地址:这个指的是内部网络地址,一般用于局域网,IANA规定私网地址不在Internet上分配,用于一个公司或单位内部;
2、NAT的原理:
当内网数据包经过路由器的时候,NAT会将源ip地址转化为公网ip地址,当公网的数据包经过路由器的时候,nat会将数据包的目的ip地址转化为私网ip地址
3、NAT的作用:
1、解决了一个ipv4地址不足的问题;
2、实现了内部网络访问外部网络,但是外网无法访问内网,保护了内网安全性,隐藏内部网络;
3、NAT server 可以防止内网服务器被攻击,因为访问是通过映射到了公网ip;
4、实验配置:
实验一:静态NAT配置
注意:静态配置的公网ip不能与端口ip重复
R1配置:
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.1.254 24
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 200.1.1.1 24
[R1-GigabitEthernet0/0/1]q
###静态nat配置,将两个私网地址与公网地址一对一映射
[R1]int g0/0/1 ##进入设置的端口
[R1-GigabitEthernet0/0/1]nat static enable ##开启静态nat
[R1-GigabitEthernet0/0/1]nat static global 200.1.1.100 inside 192.168.1.1
[R1-GigabitEthernet0/0/1]nat static global 200.1.1.90 inside 192.168.1.2
[R1-GigabitEthernet0/0/1]q
#注意不能直接使用 接口地址200.1.1.1 会显示冲突!!!!
###需要配置到202.1.1.0网段的静态路由
[R1]ip route-static 202.1.1.0 24 200.1.1.2
###查看静态nat
[R1]dis nat static
Static Nat Information:
Interface : GigabitEthernet0/0/1
Global IP/Port : 200.1.1.100/----
Inside IP/Port : 192.168.1.1/----
Protocol : ----
VPN instance-name : ----
Acl number : ----
Netmask : 255.255.255.255
Description : ----
Global IP/Port : 200.1.1.90/----
Inside IP/Port : 192.168.1.2/----
Protocol : ----
VPN instance-name : ----
Acl number : ----
Netmask : 255.255.255.255
Description : ----
R2配置:
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 200.1.1.2 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 202.1.1.2 24
[Huawei-GigabitEthernet0/0/1]q
实验测试:
实验二:动态nat设置,并且不做端口映射
R1配置:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.1.254 24
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 200.1.1.1 24
[R1-GigabitEthernet0/0/1]q
###先建立nat 地址池,注意这里的公网地址不能与路由器接口的ip地址重复!!
[R1]nat address-group 1 200.1.1.10 200.1.1.20
[R1]acl 2000
[R1-acl-basic-2000]rule permit source 192.168.1.0 0.0.0.255 ##允许所有私网地址通过
[R1-acl-basic-2000]int g0/0/1
[R1-GigabitEthernet0/0/1]nat outbound 2000 address-group 1 no-pat ##将公网地址池和acl匹配表对应
### no-pat表示不做端口映射
[R1]ip route-static 202.1.1.0 24 200.1.1.2
实验检测:nat公网范围中的ip随机与私网ip进行映射转换
实验三:easyip类型
1.使用acl列表匹配私网的ip地址
2.将所有的私网地址映射成路由器当前接口的公网地址
R1的配置:
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 192.168.1.254 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 200.1.1.1 24
[Huawei-GigabitEthernet0/0/1]q
##将私网的ip匹配到ac表中
[Huawei]acl 2000
[Huawei-acl-basic-2000]rule permit source 192.168.1.0 0.0.0.255
###切换至外网的接口,设置nat调用acl匹配
[Huawei-acl-basic-2000]int g0/0/1
[Huawei-GigabitEthernet0/0/1]nat outbound 2000
##需要配置路由表访问202.1.1.0网段
[Huawei]ip route-static 202.1.1.0 24 200.1.1.2
##查看对应关系
[Huawei]dis nat outbound
NAT Outbound Information:
--------------------------------------------------------------------------
Interface Acl Address-group/IP/Interface Type
--------------------------------------------------------------------------
GigabitEthernet0/0/1 2000 200.1.1.1 easyip
--------------------------------------------------------------------------
Total : 1
类型是easyip
R2配置:
注意,本实验中R2不需要设置静态路由,因为不需要直接访问192.168.1.0网段,内网被隐藏了,是通过公网转换的!!!
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 200.1.1.2 24
[Huawei-GigabitEthernet0/0/0]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 202.1.1.2 24
[Huawei-GigabitEthernet0/0/1]q
抓包查看:
实验四:NAT server
R1配置:
[R1]int g0/0/1
[R1-GigabitEthernet0/0/1]nat server protocol tcp global current-interface 80 ins
ide 192.168.1.100 80
Warning:The port 80 is well-known port. If you continue it may cause function fa
ilure.
Are you sure to continue?[Y/N]:y
Info: The NAT in the network has existed.
Already existing configuration will be covered with current configure. [Y/N]:
y
[R1-GigabitEthernet0/0/1]