很多企业中,有2个路由器,一个有线的,一个无线的,有线跟无线且不在同一个网段。
如下图所示 PC2可以访问 PC1,而反向则不可以,此时我们可以在R1上面增加静态路由实现互通。
1、拓扑图如下
为了模拟真实的上网环境,我们先把网络部署一下。
1、R1路由器设置
<R1>sys
[R1]sys R1
[R1]un in en
[R1]dhcp enable
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip addr 192.168.137.10 24
[R1-GigabitEthernet0/0/0]quit
[R1]int g0/0/1
[R1-GigabitEthernet0/0/1]ip addr 192.168.10.1 24
[R1-GigabitEthernet0/0/1]dhcp select int
[R1-GigabitEthernet0/0/1]dhcp server dns-list 114.114.114.114
[R1-GigabitEthernet0/0/1]quit
# NAT设置实现在上网
[R1]acl 2000
[R1-acl-basic-2000]rule 5 permit source 192.168.10.0 0.0.0.255
[R1-acl-basic-2000]int g0/0/0
[R1-GigabitEthernet0/0/0]nat outbound 2000
[R1-GigabitEthernet0/0/0]quit
[R1]dns resolve
[R1]dns server 114.114.114.114
# 默认路由
[R1]ip route-static 0.0.0.0 0.0.0.0 192.168.137.1
2、R2路由器设置
<R2>sys
[R2]sys R2
[R2]un in en
[R2]dhcp enable
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip addr 192.168.10.2 24
[R2-GigabitEthernet0/0/0]quit
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]ip addr 10.0.10.254 24
[R2-GigabitEthernet0/0/1]dhcp select int
[R2-GigabitEthernet0/0/1]dhcp server dns-list 114.114.114.114
[R2-GigabitEthernet0/0/1]quit
# NAT设置实现上网
[R2]acl 2000
[R2-acl-basic-2000]rule 5 permit source 10.0.10.0 0.0.0.255
[R2-acl-basic-2000]int g0/0/0
[R2-GigabitEthernet0/0/0]nat outbound 2000
[R2-GigabitEthernet0/0/0]quit
[R2]dns resolve
[R2]dns server 114.114.114.114
# 默认路由
[R2]ip route-static 0.0.0.0 0.0.0.0 192.168.10.1
3、通过上面设置我们已实现
PC1可以上网
PC1>ping www.baidu.com
www.baidu.com -> www.a.shifen.com
Ping www.a.shifen.com [110.242.68.3]: 32 data bytes, Press Ctrl_C to break
From 110.242.68.3: bytes=32 seq=1 ttl=45 time=62 ms
From 110.242.68.3: bytes=32 seq=2 ttl=45 time=78 ms
From 110.242.68.3: bytes=32 seq=3 ttl=45 time=78 ms
From 110.242.68.3: bytes=32 seq=4 ttl=45 time=47 ms
From 110.242.68.3: bytes=32 seq=5 ttl=45 time=63 ms
--- 110.242.68.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/65/78 ms
PC2可以上网
PC2>ping www.baidu.com
www.baidu.com -> www.a.shifen.com
Ping www.a.shifen.com [110.242.68.3]: 32 data bytes, Press Ctrl_C to break
From 110.242.68.3: bytes=32 seq=1 ttl=44 time=78 ms
From 110.242.68.3: bytes=32 seq=2 ttl=44 time=62 ms
From 110.242.68.3: bytes=32 seq=3 ttl=44 time=63 ms
From 110.242.68.3: bytes=32 seq=4 ttl=44 time=78 ms
From 110.242.68.3: bytes=32 seq=5 ttl=44 time=94 ms
--- 110.242.68.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/75/94 ms
PC2访问PC1
PC2>ping 192.168.10.254
Ping 192.168.10.254: 32 data bytes, Press Ctrl_C to break
From 192.168.10.254: bytes=32 seq=1 ttl=127 time=32 ms
From 192.168.10.254: bytes=32 seq=2 ttl=127 time=31 ms
From 192.168.10.254: bytes=32 seq=3 ttl=127 time=47 ms
From 192.168.10.254: bytes=32 seq=4 ttl=127 time=31 ms
From 192.168.10.254: bytes=32 seq=5 ttl=127 time=47 ms
--- 192.168.10.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 31/37/47 ms
PC1不可以访问PC2
PC>ping 10.0.10.253
Ping 10.0.10.253: 32 data bytes, Press Ctrl_C to break
Request timeout!
Request timeout!
Request timeout!
Request timeout!
Request timeout!
--- 10.0.10.253 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
4、R1增加静态路由
# 增加静态路由,实现10.0.10.0网段访问192.168.10.0
[R1]ip route-static 10.0.10.0 24 192.168.10.2
PC1成功访问PC2
PC1>ping 10.0.10.253
Ping 10.0.10.253: 32 data bytes, Press Ctrl_C to break
From 10.0.10.253: bytes=32 seq=1 ttl=127 time=62 ms
From 10.0.10.253: bytes=32 seq=2 ttl=127 time=63 ms
From 10.0.10.253: bytes=32 seq=3 ttl=127 time=62 ms
From 10.0.10.253: bytes=32 seq=4 ttl=127 time=63 ms
From 10.0.10.253: bytes=32 seq=5 ttl=127 time=47 ms
--- 10.0.10.253 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 47/59/63 ms