Autocommand
概述
有时,当客户的网络出现故障时,需要远程工程师协助或指导客户解决故障,这时就需要远程工程师?telnet?到客户的网络设备上,但是却并不希望远程工程师去直接更改用户设备的配置,在这种情况下,就可以在用户的设备上为远程工程师配置一个用户,通过这样的用户登陆设备之后,可以自动执行远程工程师想要执行的命令,从而达到了远程工程师查看设备配置的目的,又不违反修改配置的规矩。
网络工程师http://www.runtimeedu.com/skpx/10.html
要实现这样的功能,就可以在设备上配置?Autocommand?的功能,这样,当相应的用户?telnet?到设备时,就可以自动执行其想要的命令。
这样的?Autocommand?可以配置为所有?VTY?连上来的人执行,即配置在?VTY?接口下,也可以单独为某个用户执行,即配置在用户名之后。但这样的命令都只能执行一条。
1.在?VTY?下为所有用户配置自动执行命令
(1)在?R2?上配置用户名和密码
r2(config)#username?ccie?password?cisco
(2)??配置为所有?VTY?用户自动执行命令
说明:要为所有?VTY?用户执行命令,就配置在?VTY?接口下,这里配置自动执行命令为?show?ip?interface?brief
r2(config)#line?vty?0?935
r2(config-line)#login?local
r2(config-line)#autocommand?show?ip?interface?brief
(3)测试结果
说明:从?R1?telnet?到?R2,输入正确用户名和密码,即可看到命令执行后的输出
r1#telnet?12.1.1.2
Trying?12.1.1.2?...? Open
User?Access?Verification
Username:?ccie
Password:
Interface IP-Address OK??Method?Status Protocol
FastEthernet0/0 12.1.1.2 YES?manual?up up
FastEthernet0/1 unassigned YES?unset administratively?down?down
Serial1/0 unassigned YES?unset administratively?down?down
Serial1/1 unassigned YES?unset administratively?down?down
Serial1/2 unassigned YES?unset administratively?down?down
Serial1/3 unassigned YES?unset administratively?down?down
[Connection?to?12.1.1.2?closed?by?foreign?host]
r1#
说明:从结果中可以看出,R1?telnet?到?R2?后,并不需要输入命令,就弹出之前
命令的自动执行命令的输出结果,这样即达到了查看配置的目的,又不违反更改配置的规矩。
2.为单个用户配置自动执行命令
(1)配置用户名
r2(config)#username?test?password?test
(2)为单个用户配置自动执行命令
说明:这里配置自动执行命令:show?ip?route
r2(config)#username?test?autocommand?show?ip?route
(3)从?R1?上?telnet?到?R2?做测试
r1#telnet?12.1.1.2
Trying?12.1.1.2?...? Open
User?Access?Verification
Username:?test
Password:
Codes:?C?-?connected,?S?-?static,?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
i?-?IS-IS,?su?-?IS-IS?summary,?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
12.0.0.0/24?is?subnetted,?1?subnets
C 12.1.1.0?is?directly?connected,?FastEthernet0/0
[Connection?to?12.1.1.2?closed?by?foreign?host]
r1#
说明:可以看到??R1??从??VTY??连上??R2??时,输入相应的??用户名和密码后,便自动
执行了相应的命令,并且证明用户的命令优先于接口的命令。
金信润天:www.runtimeedu.com
|
|