12.14 NAT網絡地址轉換實驗

作者做實驗用的是EVE-NG模擬器,相關的請參考:

1.實驗拓撲


NAT網絡地址轉換實驗

其中VPC1~VPC3模擬普通電腦,交換機S1用做二層交換機匯聚VPC1~VPC2的流量,nat操作在路由器R1上進行。交換機S1使用的鏡像為IOL L2-ADVENTERPRISE-M-15.1-20140814.bin,路由器R1使用的鏡像為i86bi-linux-l3-adventerprisek9-12.4.bin

2.對交換機路由器等進行配置

配置VPC的IP地址和網關

VPC1:

VPCS> ip 192.168.1.11/24 192.168.1.1

Checking for duplicate address...

PC1 : 192.168.1.11 255.255.255.0 gateway 192.168.1.1

VPC2:

VPCS> ip 192.168.1.12/24 192.168.1.1

Checking for duplicate address...

PC1 : 192.168.1.12 255.255.255.0 gateway 192.168.1.1

VPC3:

VPCS> ip 100.100.100.100/24

Checking for duplicate address...

PC1 : 100.100.100.100 255.255.255.0

配置交換機,匯聚VPC1~VPC2的流量

交換機S1

Switch>en

Switch#configure terminal

Enter configuration commands, one per line. End with CNTL/Z.

Switch(config)#hostname S1

S1(config)#vlan 10

S1(config-vlan)#exi

S1(config)#int e0/0

S1(config-if)#switchport mode access

S1(config-if)#switchport access vlan 10

S1(config-if)#no shutdown

S1(config-if)#end

S1(config)#int e0/1

S1(config-if)#switchport mode access

S1(config-if)#switchport access vlan 10

S1(config-if)#no shutdown

S1(config-if)#end

S1(config)#int e0/2

S1(config-if)#switchport mode access

S1(config-if)#switchport access vlan 10

S1(config-if)#no shutdown

S1(config-if)#end

在路由器上配置NAT規則

路由器R1

Router>en

Router#configure terminal

Router(config)#hostname R1

配置nat服務和地址池

R1(config)#ip nat pool wlsyahz 100.100.100.11 100.100.100.20 netmask 255.255.255.0

配置將192.168.1.0/24網段的地址轉換為地址池裡的地址

R1(config)#ip nat inside source list 1 pool wlsyahz

R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

在入端口和出端口上啟動nat轉換

R1(config)#interface e0/0

R1(config-if)#ip nat inside

R1(config-if)#exit

R1(config)#interface e0/1

R1(config-if)#ip nat outside

R1(config-if)#end

配置端口0和端口1的ip地址

R1(config)#int ethernet 0/0

R1(config-if)#ip address 192.168.1.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#int ethernet 0/1

R1(config-if)#ip address 100.100.100.1 255.255.255.0

R1(config-if)#no shutdown


3.NAT過程分析

配置完成後我們在R1上使能ip nat debug

R1#debug ip nat

然後從VPC1上ping VPC3

VPCS> ping 100.100.100.100

84 bytes from 100.100.100.100 icmp_seq=1 ttl=63 time=1.073 ms

84 bytes from 100.100.100.100 icmp_seq=2 ttl=63 time=1.079 ms

84 bytes from 100.100.100.100 icmp_seq=3 ttl=63 time=1.072 ms

84 bytes from 100.100.100.100 icmp_seq=4 ttl=63 time=0.552 ms

84 bytes from 100.100.100.100 icmp_seq=5 ttl=63 time=1.071 ms

這時會在R1上會看到VPC1的源地址被轉換成了100.100.10.11

*Dec 8 04:43:49.953: NAT*: s=192.168.1.11->100.100.100.11, d=100.100.100.100 [32645]

*Dec 8 04:43:49.953: NAT*: s=100.100.100.100, d=100.100.100.11->192.168.1.11 [32645]

*Dec 8 04:43:50.954: NAT*: s=192.168.1.11->100.100.100.11, d=100.100.100.100 [32646]

*Dec 8 04:43:50.955: NAT*: s=100.100.100.100, d=100.100.100.11->192.168.1.11 [32646]

在R1的0/1口抓包如下

NAT網絡地址轉換實驗

VPC1給VPC3發包時R1將源地址192.168.1.11轉換成了100.100.100.11(從nat池裡面取的)

在R1的0/0口抓包如下

NAT網絡地址轉換實驗

VPC3給VPC1回包時R1又將目的地址100.100.100.11轉換成了192.168.1.11

從VPC2上ping VPC3,原理相同

VPCS> ping 100.100.100.100

84 bytes from 100.100.100.100 icmp_seq=1 ttl=63 time=0.643 ms

84 bytes from 100.100.100.100 icmp_seq=2 ttl=63 time=0.992 ms

84 bytes from 100.100.100.100 icmp_seq=3 ttl=63 time=0.909 ms

84 bytes from 100.100.100.100 icmp_seq=4 ttl=63 time=0.792 ms

84 bytes from 100.100.100.100 icmp_seq=5 ttl=63 time=1.886 ms

*Dec 8 05:03:43.960: NAT*: s=192.168.1.12->100.100.100.12, d=100.100.100.100 [33839]

*Dec 8 05:03:43.960: NAT*: s=100.100.100.100, d=100.100.100.12->192.168.1.12 [33839]

*Dec 8 05:03:44.962: NAT*: s=192.168.1.12->100.100.100.12, d=100.100.100.100 [33840]

*Dec 8 05:03:44.963: NAT*: s=100.100.100.100, d=100.100.100.12->192.168.1.12 [33840]


分享到:


相關文章: