NAT(Network Address Translation)

当今的互联网是由一个个小的自治系统组成,一个家庭,一个企业就是一个小的自治系统
自治系统内部有着众多的设备需要IP地址联网,每个地址都需要去IANA申请明显做不到,所以就会使用私有IP地址进行分配
私有IP地址无法做到互联网通信,在内网之中就需要一个默认网关来代替大家请求互联网数据
NAT网络地址转换技术能够将数据包中的IP地址进行转换

静态NAT

  • 一对一映射,为每个内部的地址指定一个公网IP地址
  • 这种方法主要用在内网中存在需要对公网提供服务的服务器的场景,类似的例子有WEB服务器、邮件服务器、FTP服务器等

    拓扑

    5_JPX$PI%}R~IY}((O(YUC5.png

步骤

  • 地址配置

    1. R1(config)#int e0/0
    2. R1(config-if)#ip add 192.168.13.1 255.255.255.0
    3. R1(config-if)#no sh
    4. R1(config-if)#int e0/1
    5. *Feb 1 07:53:24.935: %LINK-3-UPDOWN: Interface Ethernet0/0, changed state to up
    6. *Feb 1 07:53:25.946: %LINEPROTO-5-UPDOWN: Line protocol on Interface
    7. Ethernet0/0, changed state to up
    8. R1(config-if)#int e0/1
    9. R1(config-if)#ip add 100.12.12.1 255.255.255.0
    10. R1(config-if)#no sh
    11. R1(config-if)#
    12. *Feb 1 07:53:40.608: %LINK-3-UPDOWN: Interface Ethernet0/1, changed state to up
    13. *Feb 1 07:53:41.615: %LINEPROTO-5-UPDOWN: Line protocol on Interface
    14. Ethernet0/1, changed state to up
    15. R1(config-if)#
    16. R2(config)#int e0/0
    17. R2(config-if)#ip add 100.12.12.2 255.255.255.0
    18. R2(config-if)#no sh
    19. R2(config-if)#int lo0
    20. R2(config-if)#ip add 2.2.2.2 255.255.255.0
    21. R3(config)#int e0/0
    22. R3(config-if)#ip add 192.168.13.3 255.255.255.0
    23. R3(config-if)#no sh
  • 在R1和R3上添加默认路由指向运营商 ```bash R1(config)#ip route 0.0.0.0 0.0.0.0 100.12.12.2

R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.13.1

  1. - R1上做静态路由转换, 找运营商获得一个公网IP地址, 假设是 100.12.12.3 ,然后将其对应的分配给 192.168.13.3 ,那么R3在上网的时候就可以用公网IP地址对外了
  2. ```bash
  3. R1(config)#int e0/0
  4. R1(config-if)#ip nat inside
  5. R1(config-if)#int e0/1
  6. R1(config-if)#ip nat outside
  7. R1(config-if)#exit
  8. R1(config)#ip nat inside source static 192.168.13.3 100.12.12.3
  • 验证R3是否能访问外网
    1. R3#ping 2.2.2.2
    2. Type escape sequence to abort.
    3. Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:
    4. .!!!!
    5. Success rate is 80 percent (4/5), round-trip min/avg/max = 1/1/2 ms