1 | % Cisco Config Elements |
---|
2 | % |
---|
3 | % Network Monitoring and Management |
---|
4 | |
---|
5 | # Introduction |
---|
6 | |
---|
7 | ## Goals |
---|
8 | |
---|
9 | * Learn the basic set of IOS commands required to enable SSH on your Cisco |
---|
10 | Switch or Router |
---|
11 | |
---|
12 | ## Notes |
---|
13 | |
---|
14 | * Commands preceded with "$" imply that you should execute the command as |
---|
15 | a general user - not as root. |
---|
16 | * Commands preceded with "#" imply that you should be working as root. |
---|
17 | * Commands with more specific command lines (e.g. "rtrX>" or "mysql>") |
---|
18 | imply that you are executing commands on remote equipment, or within |
---|
19 | another program. |
---|
20 | * If a command line ends with "\" this indicates that the command continues |
---|
21 | on the next line and you should treat this as a single line. |
---|
22 | |
---|
23 | # Exercises Part I |
---|
24 | |
---|
25 | ## Work in a group |
---|
26 | |
---|
27 | For this exercise you need to work in groups. Assign one person to type on |
---|
28 | the keyboard. There should be 4 people in group. For instance, members of |
---|
29 | Group 1 are those on pc1-pc4, Group 2 use pc5-pc8, Group 3 use pc9-12, etc⊠|
---|
30 | |
---|
31 | If you are unsure of what group you are in refer to the Network Diagram on the |
---|
32 | classroom wiki by going to http://noc.ws.nsrc.org/ and clicking on the Network |
---|
33 | Diagram link. |
---|
34 | |
---|
35 | ## Connect to your router |
---|
36 | |
---|
37 | Log in to your vm/pc image and install Telnet: |
---|
38 | |
---|
39 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
40 | $ sudo apt-get install telnet |
---|
41 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
42 | |
---|
43 | If it is already installed that is fine. |
---|
44 | |
---|
45 | Now connect to the router in your group: |
---|
46 | |
---|
47 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
48 | $ telnet 10.10.N.254 |
---|
49 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
50 | |
---|
51 | username: cisco |
---|
52 | password: cisco |
---|
53 | |
---|
54 | Display information about your router |
---|
55 | |
---|
56 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
57 | routerN>enable |
---|
58 | Password: (default pw "cisco") |
---|
59 | RouterN#show run (space to continue) |
---|
60 | RouterN#show int FastEthernet0/0 |
---|
61 | RouterN#show ? (lists all options) |
---|
62 | RouterN#exit (log off router) |
---|
63 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
64 | |
---|
65 | |
---|
66 | ## Configure your router to only use SSH |
---|
67 | |
---|
68 | These steps will do the following: |
---|
69 | |
---|
70 | * Create an ssh key for your router |
---|
71 | * Create an encrypted password for the user cisco |
---|
72 | * Encrypt the enable password (cisco) |
---|
73 | * Turn off telnet (unencrypted) access to your router |
---|
74 | * Turn on SSH (version 2) access to your router |
---|
75 | |
---|
76 | You need to work in groups of 4. Get together with the members of your router |
---|
77 | group and assign one person to enter commands. To start connect to one of the |
---|
78 | PCs in use by your group. From that PC image telnet to your router: |
---|
79 | |
---|
80 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
81 | $ telnet rtrN.ws.nsrc.org (or "telnet 10.10.N.254") |
---|
82 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
83 | |
---|
84 | username: cisco |
---|
85 | password: cisco |
---|
86 | |
---|
87 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
88 | rtrN> enable (en) |
---|
89 | password: cisco |
---|
90 | rtrN# configure terminal (conf t) |
---|
91 | rtrN(config)# aaa new-model |
---|
92 | rtrN(config)# ip domain-name ws.nsrc.org |
---|
93 | rtrN(config)# crypto key generate rsa |
---|
94 | |
---|
95 | How many bits in the modulus [512]: 2048 |
---|
96 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
97 | |
---|
98 | Wait for the key to generate. You can now specify passwords and they will be |
---|
99 | encrypted. First let's remove our cisco user temporarily, then we'll recreate |
---|
100 | the user: |
---|
101 | |
---|
102 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
103 | rtrN(config)# no username cisco |
---|
104 | rtrN(config)# username cisco secret 0 <CLASS PASSWORD> |
---|
105 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
106 | |
---|
107 | Now the cisco user's password (of <CLASS PASSWORD>) is encrypted. Next let's encrypt |
---|
108 | the enable password as well: |
---|
109 | |
---|
110 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
111 | rtrN(config)# enable secret 0 <CLASS PASSWORD> |
---|
112 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
113 | |
---|
114 | Now we'll tell our router to only allow SSH connections on the 5 defined |
---|
115 | consoles (vty 0 through 4): |
---|
116 | |
---|
117 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
118 | rtrN(config)# line vty 0 4 |
---|
119 | rtrN(config-line)# transport input ssh |
---|
120 | rtrN(config-line)# exit |
---|
121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
122 | |
---|
123 | This drops us out of the "line" configuration mode and back in to the general |
---|
124 | configuration mode. Now we'll tell the router to log SSH-related events and to |
---|
125 | only allow SSH version 2 connections: |
---|
126 | |
---|
127 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
128 | rtrN(config)# ip ssh logging events |
---|
129 | rtrN(config)# ip ssh version 2 |
---|
130 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
131 | |
---|
132 | Now exit from configuration mode: |
---|
133 | |
---|
134 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
135 | rtrN(config)# exit |
---|
136 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
137 | |
---|
138 | And, write these changes to the routers permament configuration: |
---|
139 | |
---|
140 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
141 | rtrN# write memory (wr mem) |
---|
142 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
143 | |
---|
144 | Ok. That's it. You can no longer use telnet to connect to your |
---|
145 | router. You must connect using SSH with the user "cisco" and |
---|
146 | password <CLASS PASSWORD>. The enable password is, also, <CLASS |
---|
147 | PASSWORD> - Naturally in a real-world situation you would use much |
---|
148 | more secure passwords. |
---|
149 | |
---|
150 | Before you exit your Telnet session be sure to test ssh connectivity |
---|
151 | from another PC in your group (or, open another terminal window). |
---|
152 | Do this in case you made a mistake to avoid locking yourself out |
---|
153 | of your router. |
---|
154 | |
---|
155 | First, try connection again with telnet: |
---|
156 | |
---|
157 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
158 | $ telnet rtrN.ws.nsrc.org |
---|
159 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
160 | |
---|
161 | What happens? You should see something like: |
---|
162 | |
---|
163 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
164 | Trying 10.10.N.254... |
---|
165 | telnet: Unable to connect to remote host: Connection refused |
---|
166 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
167 | |
---|
168 | Now try connecting with SSH: |
---|
169 | |
---|
170 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
171 | $ ssh cisco@rtrN.ws.nsrc.org |
---|
172 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
173 | |
---|
174 | You should see something looks similar to this: |
---|
175 | |
---|
176 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
177 | The authenticity of host 'rtr2.ws.nsrc.org (10.10.2.254)' can't be |
---|
178 | established. RSA key fingerprint is 93:4c:eb:ad:5c:4a:a6:3e:8b:9e: |
---|
179 | 4f:e4:e2:eb:e4:7f. Are you sure you want to continue connecting |
---|
180 | (yes/no)? |
---|
181 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
182 | |
---|
183 | Enter in "yes" and press ENTER to continue... |
---|
184 | |
---|
185 | Now you'll see the follwoing: |
---|
186 | |
---|
187 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
188 | Password: <CLASSS PASSWORD> |
---|
189 | rtrN> |
---|
190 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
191 | |
---|
192 | Type "enable" to allow us to execute privileged commands: |
---|
193 | |
---|
194 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
195 | rtrN> enable |
---|
196 | Password: <CLASS PASSWORD> |
---|
197 | rtrN# |
---|
198 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
199 | |
---|
200 | Now let's view the current router configuration: |
---|
201 | |
---|
202 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
203 | rtrN# show running (sh run) |
---|
204 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
205 | |
---|
206 | Press the space bar to continue. Note some of the entries like: |
---|
207 | |
---|
208 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
209 | enable secret 5 $1$p4/E$PnPk6VaF8QoZMhJx56oXs. |
---|
210 | . |
---|
211 | . |
---|
212 | . |
---|
213 | username cisco secret 5 $1$uNg1$M1yscHhYs..upaPP4p8gX1 |
---|
214 | . |
---|
215 | . |
---|
216 | . |
---|
217 | line vty 0 4 |
---|
218 | exec-timeout 0 0 |
---|
219 | transport input ssh |
---|
220 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
221 | |
---|
222 | You can see that both the enable password and the password for the user cisco |
---|
223 | have been encrypted. This is a good thing. |
---|
224 | |
---|
225 | Now you should exit the router interface to complete this exercise: |
---|
226 | |
---|
227 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
228 | rtrN# exit |
---|
229 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
230 | |
---|
231 | And, if you still have your older Telnet session in another window |
---|
232 | be sure to exit from that as well. |
---|
233 | |
---|
234 | # NOTES |
---|
235 | |
---|
236 | 1. If you are locked out of your router after this exercise let your |
---|
237 | instructor know and they can reset your router's configuration back to its |
---|
238 | original state. |
---|
239 | 2. Please only do this exercise once. If multiple people do this exercise |
---|
240 | it's very likely that access to the router will be broken. |
---|
241 | 3. During the week you will configure items such as SNMP, Netflow and more on |
---|
242 | your group's router. From now on you can simply connect to the router |
---|
243 | directly from your laptop or desktop machine using SSH. |
---|