Trong bài lab này chúng ta sẽ thực hiện vài cấu hình cơ bản và cùng xem qua chế độ dòng lệnh trên thiết bị router Cisco.
1. Đầu tiên, bạn cho một router bất kỳ, kéo thả vào màn hình, click đôi vào nó để mở router ra, chuyển qua tab CLI. Đây là màn hình làm việc của router.
Bạn có thể nhìn thấy những dấu # đang chạy, và cuối cùng là câu hỏi Continue with configuration dialog? [yes/no]: Bạn chọn no, vì câu hỏi này là “bạn có muốn khởi động chế độ cấu hình tự động hay không. Nếu chọn yes, có nghĩa là chương trình sẽ bắt đầu cấu hình. Điều này không nên khi chúng ta đang làm lab, và chúng ta muốn cấu hình bằng tay. Sau khi chọn no, bạn sẽ thấy dấu nhắc lệnh.
Router>
2. Dấu lớn hơn này cho chúng ta biết rằng ta đang ở chế độ user mode. Nhập ? để xem danh sách các lệnh mà chế độ này có thể dùng.
Router>?
Exec commands:
<1-99> Session number to resume
connect Open a terminal connection
disable Turn off privileged commands
disconnect Disconnect an existing network connection
enable Turn on privileged commands
exit Exit from the EXEC
logout Exit from the EXEC
ping Send echo messages
resume Resume an active network connection
show Show running system information
ssh Open a secure shell client connection
telnet Open a telnet connection
terminal Set terminal line parameters
traceroute Trace route to destination
3. Gõ enable để vào chế độ privileged mode. Chế độ này dành cho việc cấu hình. Bạn có thể thấy dấu lớn hơn đả chuyển thành dấu thăng #.
Router>enable
Router#
4. Nhập dấu chấm hỏi để xem những câu lệnh mà chế độ privileged mode có thể sử dụng.
Router#?
Exec commands:
<1-99> Session number to resume
auto Exec level Automation
clear Reset functions
clock Manage the system clock
configure Enter configuration mode
connect Open a terminal connection
copy Copy from one file to another
debug Debugging functions (see also ‘undebug’)
delete Delete a file
dir List files on a filesystem
disable Turn off privileged commands
disconnect Disconnect an existing network connection
enable Turn on privileged commands
erase Erase a filesystem
exit Exit from the EXEC
logout Exit from the EXEC
mkdir Create new directory
more Display the contents of a file
5. Nếu muốn thoát khỏi đễ chộ privileged bạn gõ lệnh disable
Router#disable
Router>
6. Bây giờ thì quay trở lại chế độ privileged nào, và sau đó gõ lệnh confirure terminal.Có thể thấy chương trình có một nhắc nhở rằng bạn đang ở chệ độ cấu hình dòng lệnh, nếu đang cấu hình bạn muốn thoát ra thì bấm phím Ctrl-Z.
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#
7. Bây giờ câu lệnh đầu tiên mà bạn có thể thử là đặt lại tên router, bằng lệnh hostname theo sau là tên của router mà bạn muốn đặt.
Router(config)#hostname Router1
Router1(config)#
8. Trong chế độ global configuration trên Router1,gõ dấu chấm hỏi ?. Bạn sẽ thấy được những lệnh mà chúng ta có thể sử dụng trong chế độ cấu hình. Các bạn có thể thấy lợi hại của dấu chấm hỏi, nó sẽ cho chúng ta những câu trả lời về lệnh mà chúng ta đã quên.
Router1(config)#?
Configure commands:
aaa Authentication, Authorization and Accounting.
access-list Add an access list entry
banner Define a login banner
boot Modify system boot parameters
cdp Global CDP configuration subcommands
class-map Configure Class Map
clock Configure time-of-day clock
config-register Define the configuration register
crypto Encryption module
do To run exec commands in config mode
enable Modify enable password parameters
end Exit from configure mode
exit Exit from configure mode
hostname Set system’s network name
interface Select an interface to configure
ip Global IP configuration subcommands
line Configure a terminal line
logging Modify message logging facilities
no Negate a command or set its defaults
ntp Configure NTP
policy-map Configure QoS Policy Map
9. Công việc tiếp theo là chúng ta cấu hình password cho router. Bạn gõ lệnh enable password theo sau là password mà bạn cần đặt. Ví dụ ở đây chúng ta đặt password là ccnalab
Router1(config)#enable password ccnalab
Hãy thử lệnh show run để xem file cấu hình của router.
Router1#show run
Building configuration…
Current configuration : 634 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router1
!
!
!
enable password ccnalab
Bạn có thể thấy password mà bạn đặt hiển thị một cách tường mình.
10. Password mà bạn cấu hình lúc nãy dùng cho chế độ user, và nó không được mã hóa. Bây giờ thì làm cách nào để cấu hình password bảo mật hơn, không thể thấy như vậy nữa, dùng cho chế độ privileged. Bạn dùng lệnh enable sercet, theo sau cũng là password chúng ta muốn.
Router1(config)#enable secret admin
Thử lại lệnh show run, bạn thấy thêm một password nữa đã bị mã hóa.
Router1#show run
Building configuration…
Current configuration : 681 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router1
!
!
!
enable secret 5 $1$mERr$vTbHul1N28cEp8lkLqr0f/
enable password ccnalab
11. Tiếp theo chúng ta cùng xem qua các card mạng có trên router của bạn, bằng lệnhshow ip interface.
Router1#sh ip int
FastEthernet0/0 is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
FastEthernet1/0 is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
Serial2/0 is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
Serial3/0 is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
FastEthernet4/0 is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
FastEthernet5/0 is administratively down, line protocol is down (disabled)
Internet protocol processing disabled
Tuy nhiên ở đây tôi chỉ gõ sh ip int đó là điểm thú vị của router cisco, chúng cho phép bạn gõ tắt một lệnh. Thay vì phải gõ hết toàn bộ câu lệnh.
12. Thực hành tiếp theo là đặt địa chỉ ip cho các giao tiếp (interface). Ví dụ chúng ta đặt cho FastEthernet0/0. Bạn chuyển vào chế độ cấu hình, gõ lệnh như sau:
Router1#conf t
Router1(config)#int<tab>
Router1(config)#interface FastEthernet 0/0
Router1(config-if)#ip address 192.168.100.1 255.255.255.0
Router1(config-if)#no shutdown
Có thể thấy tôi có ký hiệu <tab> bạn đừng gõ nó vào đấy, ký hiệu này có nghĩa là bạn bấm phím TAB, để router tự điền phần còn thiếu của câu lệnh. Chúng ta cùng tìm hiểu nhanh qua các lệnh. Lệnh interface FastEthernet 0/0 sẽ chuyển chế độ cấu hình trên interface có tên là FastEthernet 0/0. Lệnh ip address sẽ đặt ip cho interface, theo sau lệnh này là địa chỉ ip và subnermask. Cuối cùng là lệnh no shutdown cho phép interface đi vào trạng thái sẵn sàng hoạt động.
13. Gõ lệnh show ip interface brief để xem cấu hình đã đặt.
Router1#sh ip int brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.100.1 YES manual up down
FastEthernet1/0 unassigned YES unset administratively down down
Serial2/0 unassigned YES unset administratively down down
Serial3/0 unassigned YES unset administratively down down
FastEthernet4/0 unassigned YES unset administratively down down
FastEthernet5/0 unassigned YES unset administratively down down
Tuy nhiên, ở đây chúng ta chỉ mới có đặt password, chưa tính đến chuyện giao tiếp giữa các router, các bạn đừng bận tâm về trạng thái của router.
14. Sau đây chúng ta sẽ test thử các password mà chúng ta đã đặt. Bạn logout khỏi router bằng lệnh exit. Sau đó gõ enable để vào lại, lần này bạn được yêu cầu password, đây là mật khẩu thường ở chể độ config, bạn gõ vào admin. Lưu ý là lúc gõ pass bạn không thấy các ký tự xuất hiện, hãy cứ yên tâm gõ tiếp vì lúc này router vẫn đang ghi nhận các ký tự.
Router1>enable
Password:
Router1#
15. Để xem các thông số cấu hình của interface một cách chi tiết bạn dùng lệnh show interface
Router1#show interfaces
FastEthernet0/0 is up, line protocol is down (disabled)
Hardware is Lance, address is 0030.f2d8.64c6 (bia 0030.f2d8.64c6)
Internet address is 192.168.100.1/24
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
ARP type: ARPA, ARP Timeout 04:00:00,
Last input 00:00:08, output 00:00:05, output hang never
Last clearing of “show interface” counters never
Input queue: 0/75/0 (size/max/drops); Total output drops: 0
Queueing strategy: fifo
Output queue :0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes, 0 no buffer
Received 0 broadcasts, 0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
0 input packets with dribble condition detected
0 packets output, 0 bytes, 0 underruns
0 output errors, 0 collisions, 1 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier
–More–
16. Để xem các cấu hình đã lưu trong DRam, bạn dùng lệnh show running-config, viết ngắn là show run
Router1#show running-config
Building configuration…
Current configuration : 696 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router1
!
!
!
enable secret 5 $1$mERr$vTbHul1N28cEp8lkLqr0f/
enable password ccnalab
!
!
!
!
!
!
!
–More–
17. Để xem các cấu hình lưu trong NVRam, bạn dùng lệnh show startup-config
Router1#show startup-config
startup-config is not present
18. Chúng ta cần giải thích một chút về bộ nhớ DRam và NVRam. Những gì mà bạn cấu hình lúc router đang chạy sẽ lưu vào bộ nhớ DRam, khi khởi động lại thì cấu hình đó sẽ mất. Để giữ lại cấu hình đó bạn lưu chúng vào bộ nhớ NVRam. Khi router khởi động lần hai thì sẽ load cấu hình trong NVRam nạp vào DRam để xử lý. Lúc trước chưa lưu nên khi gõ lệnh show ở bước 18 bạn thấy thông báo là không có gì. Để lưu DRam vào NVRam bạn dùng lệnh copy running-config startup-config, sau đó gõ lại lệnh show startup để xem.
Router1#copy running-config startup-config
Destination filename [startup-config]?
Building configuration…
[OK]
Router1#show startup-config
Using 696 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Router1
!
!
!
enable secret 5 $1$mERr$vTbHul1N28cEp8lkLqr0f/
enable password ccnalab
!
!
!
!
!
!
!
!
!
–More—
19. Vấn đề tiếp theo chúng ta sẽ bàn luận là hệ điều hành của router. Bản thân router cũng là một máy tính nên nó cũng có hệ điều hành. Chẳng những là hệ điều hành mà nó còn có thanh ghi nữa. Để xem hệ điều hành bạn dùng lệnh show version. Những dòng tô đậm dưới đây bạn sẽ gặp lại.
Router1#show version
Cisco Internetwork Operating System Software
IOS ™ PT1000 Software (PT1000-I-M), Version 12.2(28), RELEASE SOFTWARE (fc5)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2005 by cisco Systems, Inc.
Compiled Wed 27-Apr-04 19:01 by miwang
Image text-base: 0x8000808C, data-base: 0x80A1FECC
ROM: System Bootstrap, Version 12.1(3r)T2, RELEASE SOFTWARE (fc1)
Copyright (c) 2000 by cisco Systems, Inc.
ROM: PT1000 Software (PT1000-I-M), Version 12.2(28), RELEASE SOFTWARE (fc5)
System returned to ROM by reload
System image file is “flash:pt1000-i-mz.122-28.bin“
PT 1001 (PTSC2005) processor (revision 0×200) with 60416K/5120K bytes of memory
.
Processor board ID PT0123 (0123)
PT2005 processor: part number 0, mask 01
Bridging software.
X.25 software, Version 3.0.0.
4 FastEthernet/IEEE 802.3 interface(s)
2 Low-speed serial(sync/async) network interface(s)
32K bytes of non-volatile configuration memory.
–More–
20. Bạn có thể muốn biết giao thức ở tầng 3 nào đang được sử dụng. Dùng lệnhshow protocols
Router1#show protocols
Global values:
Internet Protocol routing is enabled
FastEthernet0/0 is up, line protocol is down
Internet address is 192.168.100.1/24
FastEthernet1/0 is administratively down, line protocol is down
Serial2/0 is administratively down, line protocol is down
–More—
22. Tiếp theo bạn hãy thực hiện theo các bước sau đây để cấu hình hai router giao tiếp với nhau thử. Đầu tiên bạn lấy thêm một router nữa, rồi nối hai router này bằng cáp chéo, với Router1 dùng Fa0/0 và Router2 dùng Fa0/0 luôn.
Sau đó thì cấu hình ip trên interface Fa0/0 cho Router2.
Router>en
Router#conf t
Router(config)#int f0/0
Router(config-if)#ip add
Router(config-if)#ip address 192.168.100.2 255.255.255.0
Router(config-if)#no sh
Cuối cùng là thử ping từ Router1 đến Router2
Router1#ping 192.168.100.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.100.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 3/4/6 ms
Bạn thấy chúng ta đã ping thành công. Lưu ý là trong lúc cấu hình tôi đã viết tắt các lệnh, tôi nghĩ là bạn có thể hiểu nó.