Change the Telnet font color from a Cisco router

I've recently got an excellent question: how can I change the color of the terminal emulator font from the CLI by sending the telnet program an escape sequence?

For those of you that haven't worked with escape sequences before - you can control a lot of parameters in you terminal emulation program by sending it a special sequence starting with <ESC>[ (<ESC> begin character code 27). These sequences work even in the simplest telnet clients on Windows and Linux thanks to built-in operating system support or ANSI.SYS driver (on Windows); you can get an in-depth description and the list of all supported escape sequences from Wikipedia.

With the list of escape sequences in hand, the only remaining problem is how to send them from the router. Tcl shell was the immediate answer, but then I remembered the various banners provided by the Cisco IOS. As I wanted to change the font color as soon as possible, the login banner (or the message-of-the-day banner) seemed the right one to use.

To insert the ESC character in a banner from the configuration prompt, you have to use the Ctrl-V/Esc sequence. For example, to change the font color to bright yellow, do the following:
router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
router(config)#banner motd #
Enter TEXT message. End with the character '#'.
<Ctrl-V><ESC>[33;1mThis is a yellow router#
router(config)#
When you look at the running configuration, the router transforms the control characters into ^x sequences, so your banner will look like this:
router#show run | begin banner
banner motd ^C
^[[33;1mThis is a yellow router^C
...
Notes:
  • Saving router configurations on (T)FTP server and reloading them from a server does not pose a problem, as the control characters are preserved throughout the process, but you cannot use cut-and-paste with banners, as the terminal emulator does not transform ^x sequence into a control character.
  • With this technique, you can color-code your routers. For example, internal routers could use green font, publicly accessible ones red font and the firewall routers yellow font, so all the operators would know immediately what to expect on each device.
  • This article is part of You've asked for it series.

6 comments:

  1. Great tip ;)

    Will set all my friends cli in pink LOL
  2. So is there an easy way to push this out to large numbers of switches.
  3. Hi ivan,

    ur articles are gr8. i would like to ask u is there a way with just one comd may be an eventmanager applet or a login-string can we loginto all the routers from a terminal server or reload all servers.

    another question is there any way we can send a bunch of commands to all routers on a com server using a send * cmd

    would really appritate it .

    regards
    Deepak
    [email protected]
  4. hi this is not working for me i tried on dynamips pls help deepak
  5. This appears not to work after IOS v 12.4(20) and above
  6. Hi there, I found I also had to set the international flag on the VTYs before I could make this work:

    R1# conf t
    Enter configuration commands, one per line. End with CNTL/Z.
    R1(config)# line vty 0 15
    R1(config-line)# international
    R1(config-line)# end
    R1# wr

    Another note - if you just want a colourful banner, use [0m to reset your changes.
Add comment
Sidebar