Category Archives: Quick Hacks

Playing around with OSPF

I did some fooling around with OSPF priorities and here’s what I learned:

If you have multiple routers on an Ethernet segment,  and all routers have priority 0 – there will be no DR, no BDR, and only 2way connectivity between all of them.

If you have just one router has with priority >0, then that router will be the DR, but there will still be no bdr, and the only full connection would be, obviously, between the DR and the others.

With P2P links, OSPF doesn’t care about priority, but does care about area mismatches:

An area mismatch, for example (r1:normal)-(r2:stub) would tear down neighborship due to the mismatch, and it’s possible it won’t even show up on the error logs. Fun fun 🙂

Advertisements

Cisco Command Prompt Tricks and Gotchas part 2

Shall you ever be unfortunate enough to come across a device with a setup similar to

exec-timeout 0 1

or maybe you’re just doing a CCIE exam, then you’ll need a little bit of practical trickstery to overcome the one second timeout – just use notepad or whatever text editor you have to type something like

enable
conf t
line vty 0 4/line con 0
exec-timeout 10

and then quickly paste it in the window of 1 second. Done! 🙂

Permanently delete files on HP/H3C devices

It has come to my attention that a lot of users are visiting this site looking for info on how to permanently delete files on an HP/H3C router or switch.

This is a very easy task, though it may not be as obvious as it seems.

The delete file command moves a file to the recycle bin. To restore the file, use the undelete command. If you delete two files with the same file name in different directories, only the last one is retained in the recycle bin.

The dir /all command displays the files moved to the recycle bin. These files are enclosed in pairs of square brackets [ ]. To permanently delete these files, use the reset recycle-bin command.

To permanently delete a file and (finally) free some space for that dreaded firmware upgrade, use the delete /unreserved file command. Of course, it goes without saying that the deleted file cannot be restored.

Cisco Command Prompt Tricks and Gotchas

I guess most of you are familiar with the usual CLI prompt, be it on a Linux system, Cisco device, or whatever. On a standard *nix machine, you can modify your prompt appearance, and its configuration is specific to the shell you’re using – BASH, KSH, ZSH, etc.

Recently, I was surprised to figure out that you can also modify the standard Cisco prompt. I owe this knowledge to my friend and mentor Vladi – thanks! 🙂 Interestingly, the only place I could find more info on the matter was the Cisco IOS in a Nutshell book.

Back on topic. A regular prompt would read

[hostname]>
or
[hostname]#

You can modify the prompt directly with prompt command, and use any of the following escaped variables with it:

%% - the percent character itself
%h - hostname
%n - tty command counter number
%p - prompt character (> or #)
%s - white space character
%t - tab character

For example:

Router#config t
Router (config)# prompt %h:%n%p
Router:1# show ver
[output omitted]
Router:2#

So now you can either modify your prompt, or play a trick on a fellow colleague 😀

Unequal Load-Balancing on Cisco IOS

I just wanted to share a neat trick that a fellow CCIE colleague showed me.

In case of being connected to two ISPs, there is a way of doing unequal load-balancing with the help of static routes. For example, ISP X provides you with 25Mbps, and ISP Y with 50Mbps – a 2:1 ratio.

In order to achieve any kind of load-balancing on the Cisco IOS, we need multiple entries in the routing table, pointing to the same specific destination. As we would like to load-balance our uplink traffic towards the internet, we would need multiple entries towards our default gateways.

We are all familiar with the concept that there can be only one default route for a specific gateway – you can’t have multiple routing entries pointing to the same default gateway. That means that if we have multiple ISPs and multiple default gateways, our load-balance ratio will always be 1:1, as there is just a single entry in the routing table for each default gateway.

However, we can install multiple routing entries for seemingly different default gateways. That way, we can fool the device and have the same default gateway listed multiple times in the routing table. Ok, it sounds confusing, but just take a look at the configuration and it’ll become clear.

ip route 10.0.1.1 255.255.255.255 192.168.1.2  #(ISP X)
ip route 10.0.2.1 255.255.255.255 172.16.1.2  #(ISP Y)
ip route 10.0.2.2 255.255.255.255 172.16.1.2  #(ISP Y)

ip route 0.0.0.0 0.0.0.0 10.0.1.1
ip route 0.0.0.0 0.0.0.0 10.0.2.1
ip route 0.0.0.0 0.0.0.0 10.0.2.2

First, we define static routes for a couple of fake default gateways. Those IPs do not exist, and will only be used for the current load-ballancing trick, so be careful when setting up those and try not to assign some IPs in use.

After that, we define these fake IPs as default gateways. Having in mind that the ratio of the link bandwidth is 2:1, we created two routes towards the faster ISP and a single route towards the slower ISP.

What happens is the IOS uses all three of these default gateways, because the destination is seemingly different during the first look up in the routing table. The second look up will reveal that the fake default gateway’s IP is reachable only by either ISP X or ISP Y’s next-hop router. This is quite the ingenious way of tricking the device into installing multiple entries in its routing table.

Remove GPT and go back to MBR

Note: if you would like to perform this action from within Windows, take a look at the comments section for a guide.

First of all, I assume you have an empty harddrive, or you don’t care about your data on it. It would be foolish to rewrite MBR and partition information on a drive with something even remotely usable on it. You’re going to lose it!

With that out of the way, and assuming you have backed up your data, let’s start – we’re gonna do this labeling DOS-style!

First, if you have no idea what GPT is, take a look at this.

Unlike MBR, GPT resides both at the beginning and the end of a drive, thus providing redundancy in case you wipe the beginning of your drive. If you write MBR to the beginning drive, or even zero it out, it doesn’t remove GPT recognition from fdisk and other tools that detect GPT at the end. You have to zero out the end of the drive as well.

In order not to zero out the whole drive, we’ll just clear the  blocks used by GPT. Here’s the rundown:

  1. Get the blocksize of the device. fdisk -s /dev/[HDDNAME]
  2. Round the last five digits of the size to zeros. For example, with block size 156290904, you get 156200000
  3. Zero out the last 1 000 000 blocks. dd if=/dev/zero of=/dev/[HDDNAME] bs=1k seek=[ROUNDEDSIZE]
  4. Zer0 out the first 20 000 blocks. dd if=/dev/zero of=/dev/[HDDNAME] bs=1k count=20

GPT layout table

 

To make more sense of what we just did, here’s the GPT layout image, courtesy of Wikipedia.

Each LBA entry on the diagram represents 512 bytes.

The third command zeroes out the last million blocks from your drive, just to be safe. That means that 1 000 000 * 512 bytes = approximately 480MB are zeroed out.

Looking at the diagram, zeroing out the last 17408 bytes (34 LBA * 512 bytes) could also work, if you’re in a hurry.

The fourth command zeroes out the first 20000 bytes. Unlike MBR which uses only the first 512k, you can see that GPT is spread on 4 LBAs, each one is 512k size. That means you can also delete only the first 17408 bytes (34 LBA * 512bytes).

Note:

On newer drives, the block size could be as high as 4096 bytes. Adjust the bs parameter in the dd command accordingly.

Edit (Apr/13): Corrected drivers -> drives; Added comments info