静态NAT
拓扑图
配置
代码
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable //关闭路由器信息
Info: Information center is disabled.
[Huawei]sysname R1 //改用户名
[R1]interface g0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.1.254 24 //配置IP
[R1-GigabitEthernet0/0/0]undo shutdown
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]quit
[R1]interface g0/0/1
[R1-GigabitEthernet0/0/1]ip address 100.1.1.1 24
[R1-GigabitEthernet0/0/1]undo shutdown //进入接口
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R1-GigabitEthernet0/0/1]quit //返回上一步
[R1]interface g0/0/1 //进入接口配置
[R1-GigabitEthernet0/0/1]nat static global 100.1.1.3 inside 192.168.1.1 //私网IP转公网IP
[R1-GigabitEthernet0/0/1]nat static global 100.1.1.4 inside 192.168.1.2
[R1-GigabitEthernet0/0/1]quit
[R1]display nat static
Static Nat Information:
Interface : GigabitEthernet0/0/1
Global IP/Port : 100.1.1.3/----
Inside IP/Port : 192.168.1.1/----
Protocol : ----
VPN instance-name : ----
Acl number : ----
Netmask : 255.255.255.255
Description : ----
Global IP/Port : 100.1.1.4/----
Inside IP/Port : 192.168.1.2/----
Protocol : ----
VPN instance-name : ----
Acl number : ----
Netmask : 255.255.255.255
Description : ----
Total : 2
结果
动态NAT之NAPT
拓扑图
配置(配置与静态NAT无差别)
代码
<Huawei>sys //切换视角
Enter system view, return user view with Ctrl+Z.
[Huawei]undo info-center enable //关闭路由信息表
Info: Information center is disabled.
[Huawei]sysname R1 //修改用户名
[R1]interface g0/0/0 //进入接口配置
[R1-GigabitEthernet0/0/0]ip address 192.168.1.254 24 //配置IP
[R1-GigabitEthernet0/0/0]undo shutdown //打开接口
Info: Interface GigabitEthernet0/0/0 is not shutdown.
[R1-GigabitEthernet0/0/0]quit //回到上一步
[R1]interface g0/0/1
[R1-GigabitEthernet0/0/1]ip address 100.1.1.1 24
[R1-GigabitEthernet0/0/1]undo shutdown
Info: Interface GigabitEthernet0/0/1 is not shutdown.
[R1-GigabitEthernet0/0/1]quit
[R1]nat address-group 1 100.1.1.3 100.1.1.4 //创建NAT地址池
[R1]acl 2000
[R1-acl-basic-2000]rule 10 permit source 192.168.1.0 0.0.0.255 //定义规则编号为10
[R1-acl-basic-2000]quit
[R1]interface g0/0/1
[R1-GigabitEthernet0/0/1]nat outbound 2000 address-group 1 //符合可拿IP地址
[R1-GigabitEthernet0/0/1]quit
结果
三个pc端都能ping(访问)到serve1(服务器),因为是动态的NAT所以其中的IP地址(公网)是一址多用的,比之静态NAT的独有的公网/私网IP,动态NAT的公网IP是可以多个用户使用的,通常用于减少IP地址的使用拥余,或者说是缓解IP地址不足问题。