路由器簡單配置實例ide
以下圖所示,主機0和主機1要經過路由器0和路由器1實現互相通訊,那麼咱們要進行什麼樣的設置呢?
實驗前:spa
首先,咱們須要配置路由器0(設定路由器0/0接口的IP地址爲192.168.1.1,接口0/1的IP地址爲192.168.2.1,子網掩碼均爲255.255.255.0),配置代碼以下:
第一步:配置路由器接口0/0的IP地址,子網掩碼。
Router>enable /*從用戶模式進入特權模式*/
Router#config terminal /*從特權模式進入全局模式*/
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface fastethernet 0/0 /*從全局模式進入接口模式,並指定對接口0/0進行配置*/
Router(config-if)#ip address 192.168.1.1 255.255.255.0 /*在指定接口的接口模式下,對接口0/0設置IP地址,子網掩碼 */
Router(config-if)#no shutdown /*開啓路由器的指定接口*/
第二步,配置路由器接口0/1的IP地址,子網掩碼。
Router#config terminal /*從特權模式進入全局模式*/
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface fastethernet 0/1 /*從全局模式進入接口模式,並指定對接口0/1進行配置*/
Router(config-if)#ip address 192.168.2.1 255.255.255.0 /*在指定接口的接口模式下,對接口0/1設置IP地址,子網掩碼 */
Router(config-if)#no shutdown /*開啓路由器的指定接口*/
第三步,配置主機0的IP地址,子網掩碼,網關(192.168.1.2,255.255.255.0,192.168.1.1)。
再次,咱們須要配置路由器1(設定路由器0/0接口的IP地址爲192.168.3.1,接口0/1的IP地址爲192.168.2.2,子網掩碼均爲255.255.255.0),配置代碼以下:
第一步:配置路由器接口0/0的IP地址,子網掩碼。
Router>enable /*從用戶模式進入特權模式*/
Router#config terminal /*從特權模式進入全局模式*/
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface fastethernet 0/0 /*從全局模式進入接口模式,並指定對接口0/0進行配置*/
Router(config-if)#ip address 192.168.3.1 255.255.255.0 /*在指定接口的接口模式下,對接口0/0設置IP地址,子網掩碼 */
Router(config-if)#no shutdown /*開啓路由器的指定接口*/
第二步,配置路由器接口0/1的IP地址,子網掩碼。
Router(config-if)#exit /*從上一指定接口模式下退出,進入下一指定接口的接口模式 */
Router(config)#interface fastethernet 0/1 /*從全局模式進入接口模式,並指定對接口0/1進行配置*/
Router(config-if)#ip address 192.168.2.2 255.255.255.0 /*在指定接口的接口模式下,對接口0/1設置IP地址,子網掩碼 */
Router(config-if)#no shutdown /*開啓路由器的指定接口*/
第三步,配置主機1的IP地址,子網掩碼,網關(192.168.3.2,255.255.255.0,192.168.3.1)。
而後,咱們須要設置路由器0和路由器1的靜態路由和下一跳地址。
第一步,設置路由器0的靜態路由和下一跳地址。
Router(config)#interface fastethernet 0/0 /*從全局模式進入接口模式,並指定對接口0/0進行配置*/
Router(config-if)#ip route 192.168.3.0 255.255.255.0 192.168.2.2 /*設定路由器0的目標地址和子網掩碼以及其下一跳地址*/
第二步,設置路由器1的靜態路由和下一跳地址。
Router(config)#interface fastethernet 0/0 /*從全局模式進入接口模式,並指定對接口0/0進行配置*/
Router(config-if)#ip route 192.168.1.0 255.255.255.0 192.168.2.1 /*設定路由器0的目標地址和子網掩碼以及其下一跳地址*/
最後,進行測試,主機0和主機1是否能正常通訊呢。
第一步,先從主機0開始,代碼以下:
Packet Tracer PC Command Line 1.0
PC>ping 127.0.0.1 /*ping下主機0的TCP/IP是否安裝正確*/
Pinging 127.0.0.1 with 32 bytes of data:
Reply from 127.0.0.1: bytes=32 time=10ms TTL=128
Reply from 127.0.0.1: bytes=32 time=10ms TTL=128
Reply from 127.0.0.1: bytes=32 time=2ms TTL=128
Reply from 127.0.0.1: bytes=32 time=0ms TTL=128
Ping statistics for 127.0.0.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), /*今後處能夠看出丟包率是0,說明ping通了,主機0的TCP/IP安裝正確*/
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 10ms, Average = 5ms
PC>ping 192.168.1.2 /*ping下主機0的IP,子網掩碼是否設置正確*/
Pinging 192.168.1.2 with 32 bytes of data:
Reply from 192.168.1.2: bytes=32 time=10ms TTL=128
Reply from 192.168.1.2: bytes=32 time=10ms TTL=128
Reply from 192.168.1.2: bytes=32 time=10ms TTL=128
Reply from 192.168.1.2: bytes=32 time=0ms TTL=128
Ping statistics for 192.168.1.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), /*今後處能夠看出丟包率是0,說明ping通了,主機0的IP,子網掩碼設置正確*/
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 10ms, Average = 7ms
PC>ping 192.168.1.1 /*ping下路由器接口0/0的IP,子網掩碼是否設置正確*/
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=40ms TTL=255
Reply from 192.168.1.1: bytes=32 time=20ms TTL=255
Reply from 192.168.1.1: bytes=32 time=20ms TTL=255
Reply from 192.168.1.1: bytes=32 time=20ms TTL=255
Ping statistics for 192.168.1.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), /*今後處能夠看出丟包率是0,說明ping通了,路由器的接口0/0設置正確*/
Approximate round trip times in milli-seconds:
Minimum = 20ms, Maximum = 40ms, Average = 25ms
PC>ping 192.168.2.1 /*ping下路由器0接口0/1的IP,子網掩碼是否設置正確*/
Pinging 192.168.2.1 with 32 bytes of data:
Reply from 192.168.2.1: bytes=32 time=20ms TTL=255
Reply from 192.168.2.1: bytes=32 time=20ms TTL=255
Reply from 192.168.2.1: bytes=32 time=20ms TTL=255
Reply from 192.168.2.1: bytes=32 time=20ms TTL=255
Ping statistics for 192.168.2.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), /*今後處能夠看出丟包率是0,說明ping通了,路由器0的接口0/1設置正確*/
Approximate round trip times in milli-seconds:
Minimum = 20ms, Maximum = 20ms, Average = 20ms
PC>ping 192.168.2.2 /*ping下路由器1接口0/1的IP,子網掩碼是否設置正確*/
Pinging 192.168.2.2 with 32 bytes of data:
Reply from 192.168.2.2: bytes=32 time=40ms TTL=254
Reply from 192.168.2.2: bytes=32 time=40ms TTL=254
Reply from 192.168.2.2: bytes=32 time=40ms TTL=254
Reply from 192.168.2.2: bytes=32 time=40ms TTL=254
Ping statistics for 192.168.2.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), /*今後處能夠看出丟包率是0,說明ping通了,路由器1的接口0/1設置正確*/
Approximate round trip times in milli-seconds:
Minimum = 40ms, Maximum = 40ms, Average = 40ms
PC>ping 192.168.3.1 /*ping下路由器1接口0/0的IP,子網掩碼是否設置正確*/
Pinging 192.168.3.1 with 32 bytes of data:
Reply from 192.168.3.1: bytes=32 time=40ms TTL=254
Reply from 192.168.3.1: bytes=32 time=30ms TTL=254
Reply from 192.168.3.1: bytes=32 time=40ms TTL=254
Reply from 192.168.3.1: bytes=32 time=31ms TTL=254
Ping statistics for 192.168.3.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), /*今後處能夠看出丟包率是0,說明ping通了,路由器1的接口0/1設置正確*/
Approximate round trip times in milli-seconds:
Minimum = 30ms, Maximum = 40ms, Average = 35ms
PC>ping 192.168.3.2 /*ping下主機1的IP,子網掩碼是否設置正確*/
Pinging 192.168.3.2 with 32 bytes of data:
Reply from 192.168.3.2: bytes=32 time=60ms TTL=126
Reply from 192.168.3.2: bytes=32 time=60ms TTL=126
Reply from 192.168.3.2: bytes=32 time=60ms TTL=126
Reply from 192.168.3.2: bytes=32 time=60ms TTL=126
Ping statistics for 192.168.3.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), /*今後處能夠看出丟包率是0,說明ping通了,主機設置正確*/
Approximate round trip times in milli-seconds:
Minimum = 60ms, Maximum = 60ms, Average = 60ms
第二步,主機1到主機0。/*解釋說明和主機0到主機1是同樣的,下面就不在詳細闡述了,請諒解!*/
實驗後:
路由器0:經過「show ip route」命令來查看路由表。
Router>show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet0/1
S 192.168.3.0/24 [1/0] via 192.168.2.2
路由器1:經過「show ip route」命令來查看路由表。
Router>
Router>show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
S 192.168.1.0/24 [1/0] via 192.168.2.1
C 192.168.2.0/24 is directly connected, FastEthernet0/1
C192.168.3.0/24 is directly connected, FastEthernet0/0