R2是client,R1是内网边界路由器,R3是ISP的路由器,R4是模拟server
环境搭建:路由器模拟PC
R2:client
Router>enable
Router#conf
Router#configure t
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname client-R1
client-R1(config)#no ip routing
client-R1(config)#interface ethernet 0/0
client-R1(config-if)#no shutdown
client-R1(config-if)#ip address 192.168.10.1 255.255.255.0
client-R1(config-if)#exit
client-R1(config)#ip default-gateway 192.168.10.254
client-R1(config)#
R4:server
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname server-R4
server-R4(config)#no ip routing
server-R4(config)#interface ethernet 0/0
server-R4(config-if)#no shutdown
server-R4(config-if)#ip address 100.1.1.1 255.255.255.0
server-R4(config-if)#exit
server-R4(config)#ip default-gateway 100.1.1.254
server-R4(config)#
R1:
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R1
R1(config)#interface ethernet 0/0
R1(config-if)#no shutdown
R1(config-if)#ip address 192.168.10.254 255.255.255.0
R1(config-if)#exit
R1(config)#interface ethernet 0/1
R1(config-if)#no shutdown
R1(config-if)#ip address 12.1.1.1 255.255.255.0
R1(config-if)#exit
R1(config)#
R3:
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R3
R3(config)#interface ethernet 0/1
R3(config-if)#ip address 12.1.1.2 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#interface ethernet 0/0
R3(config-if)#no shutdown
R3(config-if)#ip address 100.1.1.254 255.255.255.0
R3(config-if)#exit
R3(config)#
R1做NAT:
R1C:
ip nat inside source static 192.168.10.1 120.1.1.100
思科查看:
show ip nat translation
R1C:
interface Ethernet 0/1 (连接外网的接口)
ip nat outside(定义该接口为外网接口)
exit
interface Ethernet 0/0(内网接口)
ip nat inside(定义该接口为内网接口)
R3#:
ip route 120.1.1.100 255.255.255.255 Ethernet 0/1 12.1.1.1(配置静态,确保得到回包)
R1也要有路由才能PING100.1.1.1
R1#:
ip route 0.0.0.0 0.0.0.0 Ethernet 0/1 12.1.1.2(默认路由)
client可以与serverPING通
当R3没有配置路由条目(no掉静态路由),要在配置协议宣告(用户与运行商之间的协议是BGP,这里模拟使用IGP)
R1#:
router eigrp 90
no auto-summary
network 12.1.1.1 0.0.0.0
R3#:
router eigrp 90
no auto-summary
network 12.1.1.2 0.0.0.0
R1和R3路由间已经建好邻居,R1写静态可以同步到R3
R1#:
ip route 120.1.1.100 255.255.255.255 null 0(指向空接口)
router eigrp 90
redistribute static (将静态的路由重分发进eigrp,但不能让缺省路由做重分发,设置条件)
exit
ip prefix-list 10 seq 10 permit 120.1.1.100/32
route-map static permit 10
match ip address prefix-list 10
exit
router eigrp 90
redistribute static route-map static(重分发启用设置的条件)
client与server可以PING通
动态NAT:
R1去掉null0接口
R1:
no ip route 120.1.1.100 255.255.255.255 null 0
no router eigrp 90
R3:
no router eigrp 90
R1#:
interface Ethernet 0/1外网接口
ip nat outside
interface Ethernet 0/0
ip nat inside
exit
去掉静态NAT表项:
no ip nat inside source static 192.168.10.1 120.1.1.100
ip nat pool PC 12.1.1.100 12.1.1.110 network 255.255.255.0 (prefix-length 24)
写地址池名字PC,100到110,掩码24,255.255.255.0可以写为prefix-length 24
access-list 10 permit 192.168.10.0 0.0.0.255(写acl,1-199,)
ip nat inside source list 10 pool PC(当收到包,符合acl10的条件,转换为PC的地址池)
查看地址池使用show ip nat translations
R1(config)#do show ip nat translations
Pro Inside global Inside local Outside local Outside global
--- 12.1.1.100 192.168.10.1 --- ---
R1(config)#
表项消失也能从外到内也能访问,ping 12.1.1.100
PAT:在之前的试验基础上
R1:
no ip nat inside source list 10 pool PC(去掉该地址池)
yes再按回车
no ip nat pool PC
ip nat pool R1 12.1.1.1 12.1.1.1 prefix-length 24(地址池R1,地址.1)
alc依旧是10(Access-list 10 permit 192.168.10.0 0.0.0.255(写acl,1-199,)已经写了,不用写第二次)
ip nat inside source list 10 pool R1 overload(只要添加了overload就是开启了PAT)
end
R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
icmp 12.1.1.1:4 192.168.10.1:4 100.1.1.1:4 100.1.1.1:4
R1#
直接用接口做地址转换
R1:
no ip nat inside source list 10 pool R1 overload
Ip nat inside source list 10 interface Ethernet 0/1 overload(转换用接口IP)
PC1:192.168.10.1/24,网关192.168.10.254
AR1:gigabitEthernet0/0/0:192.168.10.254/24
GigabitEthernet0/0/1:12.1.1.1/24
AR2:gigabitEthernet0/0/1:12.1.1.2/24
GigabitEthernet0/0/0:100.1.1.254/24
SERVER:100.1.1.1/24
AR1是内网的边界路由
让例如120.1.1.0/24的网络为目的的包发给R1,R1运行了OSPF或EIGRP等协议,在R1写一条路由指向null 0接口,重分发后其他路由器知道发包给120.1.1.0/24发给R1
当NAT地址转换表里拥有私有地址到公有地址映射,会根据公有地址响应ARP请求
AR1需要写静态路由,地址转换后的数据包需要发送给AR2,
ip route-static 0.0.0.0 0.0.0.0 12.1.1.2
静态地址转换
AR1:
ip router static 0.0.0.0 0.0.0.0 Ethernet 0/0/1 12.1.1.2
Interface Ethernet 0/0/1(外网接口)
Nat static global 12.1.1.100 inside 192.168.10.1(将私有地址192.168.10.1转换为公有地址12.1.1.100)
ARP查看:display arp brief
NAT转换信息:display nat static
[AR1]display arp brief
IP ADDRESS MAC ADDRESS EXPIRE(M) TYPE INTERFACE VLAN/CEVLAN
------------------------------------------------------------------------------
192.168.10.254 00e0-fc12-2ae3 I - GE0/0/0
192.168.10.1 5489-98a9-3d63 20 D-0 GE0/0/0
12.1.1.1 00e0-fc12-2ae4 I - GE0/0/1
12.1.1.2 00e0-fc38-4b6e 20 D-0 GE0/0/1
------------------------------------------------------------------------------
Total:4 Dynamic:2 Static:0 Interface:2
[AR1]dis
[AR1]display na
[AR1]display nat s
[AR1]display nat server
[AR1]display nat session
[AR1]display nat static
Static Nat Information:
Interface : GigabitEthernet0/0/1
Global IP/Port : 12.1.1.100/----
Inside IP/Port : 192.168.10.1/----
Protocol : ----
v*n instance-name : ----
Acl number : ----
Netmask : 255.255.255.255
Description : ----
Total : 1
动态nat,AR1清除之前的配置:
nat address-group 7 12.1.1.100 12.1.1.110 (0-7个,地址池100到110)
acl number 2000(acl的编号)
rule 10 permit source 192.168.10.0 0.0.0.255(10是排序,让原地址在192.168..10.0的范围转换)
interface Ethernet 0/0/1(连接外网的接口)
nat outbound 2000 address-group 7 no-pat(发包前做检测,只要源IP地址满足2000的规则,就会从地址池7中找地址转发,并且不支持PAT多对一的复用)
display nat address-group(查看包含的NAT地址)
display nat outbound(查看在什么接口部署的调用)
R1也要写缺省路由
ip route static 0.0.0.0 0.0.0.0 Ethernet 0/0/1 12.1.1.2
[AR1]display nat outbound
NAT Outbound Information:
--------------------------------------------------------------------------
Interface Acl Address-group/IP/Interface Type
--------------------------------------------------------------------------
GigabitEthernet0/0/1 2000 7 no-pat
--------------------------------------------------------------------------
Total : 1
[AR1]display nat address-group
NAT Address-Group Information:
--------------------------------------
Index Start-address End-address
--------------------------------------
7 12.1.1.100 12.1.1.110
--------------------------------------
Total : 1
[AR1]
EasyIP配置:
在动态NAT的基础上:
AR1:
interface Ethernet 0/0/1
undo nat outbound 2000 address-group 7 no-pat
nat outbound 2000
display nat outbound
AR2:
Ip route-static 0.0.0.0 0.0.0.0 12.1.1.1
[AR1]display nat outbound
NAT Outbound Information:
--------------------------------------------------------------------------
Interface Acl Address-group/IP/Interface Type
--------------------------------------------------------------------------
GigabitEthernet0/0/1 2000 12.1.1.1 easyip
--------------------------------------------------------------------------
Total : 1
[AR1]
注:
华为内网服务器发布于公网地址上:
nat server protocol tcp 202.10.10.1 www inside 192.168.1.1 8080(192.168.1.1:8080的server发布于202.10.10.1地址上)
思科:ip nat inside source static tcp 192.168.1.1 8080 202.10.10.1 80 extendable