Blog Posts in May 2007
Catching all syslog messages
Note: this issue does not occur when using TCP as the syslog transport mechanism.
The DNS configuration "challenges"
Let's start with the DNS resolvers (the DNS name servers the router itself uses when it needs to change a name into an IP address or vice versa):
- You can configure the DNS resolvers with the ip name-server global configuration command or the domain name-server configuration command within the ip dns view default.
- Both lists are merged and combined with the IP addresses acquired from the DHCP reply messages to get the final list of the DNS resolvers. You can inspect the final list with the show ip dns view default command.
- The DNS name servers from the DHCP replies never appear in the router configuration.
- If the same IP address is specified with the ip name-server and domain name-server command, only the global (ip name-server) command will appear in the router configuration.
The rules for DNS forwarders (the DNS servers the router uses to answer incoming DNS queries) are a bit different:
- The DNS view the current DNS query should use is determined based on view-list assigned to incoming interface (with the ip dns view-group interface configuration command) or the global view-list (specified with the ip dns server view-group global configuration command).
- The incoming query is (sequentially) sent to the IP addresses configured as dns forwarders in the selected view. No other DNS servers are used.
- If the selected view has no dns forwarders, but contains domain name-servers, they are used as forwarders.
- If the selected view has no dns forwarders or domain name-servers, the query is forwarded as IP broadcast ... unless the selected view is the default view, in which case the first DNS server computed according to the the previous bullet list is used (only one DNS server is used in this case, even if you have configured multiple DNS servers with the ip name-server configuration command).
Warm upgrade
Apart from the downtime reduction, the warm upgrade (requested with the reload warm file url command) has a number of other benefits:
- The new image does not have to be stored in flash
- You don't have to change the boot image with the boot system command
- If the new image crashes, the router will revert to the original IOS image stored in flash
Reload EEM Tcl policy with help of Tcl shell
- Source file is usually edited on a general-purpose workstation.
- The file has to be downloaded to router's local storage (EEM does not register non-local policies).
- The new version of the EEM policy has to be registered with EEM with event manager policy configuration command
- After all these steps, the new policy can be tested.
set policy [lindex $argv 0]To use the script, follow these steps:
set source "tftp://10.0.0.10/tcl/" # replace with your host and directory
set destination "nvram:" # replace with local storage device
if {[string equal $policy ""]} {
return -code error "expected policy name"
}
puts "replacing policy: $policy"
ios_config "file prompt quiet"
ios_config "no event manager policy $policy" ""
exec "copy $source$policy $destination$policy"
ios_config "event manager policy $policy"
ios_config "no file prompt quiet"
- Save the script in a .tcl file (for example, changePolicy.tcl)
- Change the script parameters (remote host and local storage)
- Save the .tcl file to your router's local storage (you can also run it from a remote server)
- Configure a command alias, for example alias exec eem tclsh flash:changePolicy.tcl testPolicy.tcl
Alternatively, if you define alias exec eem tclsh flash:changePolicy.tcl, you can specify policy name as an argument to the eem command, for example eem testPolicy.tcl.
Unbundle DNS settings from DHCP client
To stop the router's DHCP client from overwriting the static name-server settings, use the no ip dhcp client request dns-nameserver interface configuration command (you can also exclude a few other DHCP options).
Change the Telnet font color from a Cisco router
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 tWhen you look at the running configuration, the router transforms the control characters into ^x sequences, so your banner will look like this:
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)#
router#show run | begin bannerNotes:
banner motd ^C
^[[33;1mThis is a yellow router^C
...
- 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.
DNS resolver in Cisco IOS is auto-configured with parameters from a DHCP reply
To avoid total confusion, you thus have these options:
- Do not use DHCP to acquire IP interface addresses
- Make sure the DHCP server does not send DNS-related parameters (a bit hard if you're using DHCP with your ISP)
- Rely exclusively on DHCP to provide your router with the DNS name server addresses
Periodic execution of IOS show commands
event manager applet SaveInterfaceStatusNotes:
event timer watchdog name SaveIfStat time 60
action 1.0 cli command "show ip interface brief | redirect ftp://username@password:host/path"
action 2.0 syslog msg "Interface status saved"
- The timer watchdog EEM event defines a recurring event triggered every X seconds.
- Output of a show command can be redirected only to a TFTP or FTP server, redirection to a web (HTTP) server does not work yet.
- The syslog action is configured for debugging purposes only and can be removed in production environment.
- More complex functionality (for example, sending show command output in an email) can be implemented with help of Tcl EEM policies
Protecting the primary DNS server on your router
Apart from having too many valid DNS requests for the zone the router is responsible for, the observed behavior could be spam-related. Just a few days ago when I've discussed the router-based DNS server with my security engineers, they've pointed out that a lot of spammers perform regular DNS attacks trying to poison the DNS cache of unpatched open caching DNS servers.
Obviously, a router is no match in raw CPU power to a high-end server, so even when running the authoritative server on the router, it might not be a bad idea to use a DNS server of your ISP as the secondary DNS and list only the ISP's DNS server in the NS records for your zone. This would deflect most of the traffic (as nobody would know your router is acting as a DNS server), but I would still apply an inbound access-list allowing only DNS queries from the secondary name server on the Internet-facing interface.
Alternatively, you could protect the router with Control Plane Policing and drop excessive DNS request packets, but that would affect the queries you should respond to as well.
Unicode IPS vulnerability: more details
Within an URI (web address), the ASCII characters can be encoded in one of three ways:
- Unless they are reserved, they can be included in the URI directly (for example, you can always use the letter a in an URI).
- You can always escape a character using its hexadecimal value. Letter a can thus be written as %61.
- Unicode character set includes full-width form of ASCII characters, where letter a can be encoded as a two-byte value 0xFF61 (or %ff%61 in an URI)
The vulnerability by itself does not open new attack routes, unless you use the IPS as the only means of protection of a vulnerable system (which is a bad practice anyway).
DNS views are broken in release 12.4(11)T
Command Authorization Fails with EEM applet or Tcl policy
One of my readers asked an interesting question: „why do the commands executed within a EEM Tcl policy fail with Command authorization fails message?“ The short answer is simple: If you use AAA command authorization (which you can only do if you're using a TACACS+ server), you have to specify the username under which the EEM will execute its CLI commands with the event manager session cli username user configuration command.
Background Continuous Ping from a Router
ip sla 100To start the ping, use the ip sla schedule 100 life forever start-time now configuration command, to stop it, no ip sla schedule 100 command. When using IP SLA ping, you can trigger Embedded Event Manager applets to report ping failure (similar to the technique described in this post) or read the ping results from SLA MIB with SNMP.
icmp-echo 172.16.1.2
timeout 500
frequency 3
Note: In IOS release 12.3(14)T, the ip sla command replaced the rtr command. To use this technique in IOS release 12.3 or lower, use the rtr configuration command.
What is a cached CEF adjacency?
Whenever a router running CEF switching has LAN interfaces (or any other multi-access interfaces), you'll find cached adjacencies for active directly attached IP neighbors in its CEF table. These adjacencies ensure the smooth traffic flow toward the LAN-attached next-hops (preventing the initial packet drop symptom once the next-hop becomes active).
The self zone in zone-based firewall configuration
The rules are simple:
- Whenever you filter traffic transiting the router, you control it with a zone-pair specifying an inside and an ouside zone.
- The self zone controls traffic sent to the router itself or originated by the router.
- Unless you specify a zone-pair combining self zone with another zone, all traffic from that zone sent to the router itself is allowed (the router is not protected)
- To control traffic that the router can send into a zone use a zone-pair from self to another zone. Use inspect in the service-policy to allow the return traffic.
- To filter the traffic that the router can accept, use a zone-pair from another zone to self. Only the packets accepted by this zone-pair's service-policy will be accepted by the router.
Use Tcl script to change the interface status
- Enter configuration mode;
- Select the appropriate interface with the interface loopback x command;
- Try to remember whether you need to disable or enable it;
- Issue the shutdown or no shutdown command;
- Exit the configuration mode and continue your debugging/testing process.
After a particularly boring testing session I decided to write a Tcl script to automate the job. To use it, download it and store it into ifchange.tcl. Download the Tcl file to your router (Flash or NVRAM) and define an alias: alias exec ifchange tclsh flash:ifchange.tcl. Now you can use the new ifchange command to change interface status.
IOS Tclsh resources
- Running Tcl procedures from IOS command line
- Tclsh command line parameters
- Where does Tcl output go
- Executing IOS commands from Tcl shell
- IOS scripting with Tcl (IOS 12.3T documentation)
- TCL'ing your Cisco router
And last but not least, if you want to store Tcl procedures on your router and don't want to write into the router's Flash memory (I hate that the router prompts me whether I want to erase the flash every time I store something into it), you can store them in NVRAM.