It's used to determine whether the other end is there or not.
If you start with a switch with nothing plugged into it. And look at "show interface status", you'll see things are not-connected. Even though ports on a switch aren't shutdown by default, they are still not UP because nothing's plugged in.
When you plug something in that changes.
If you were to do "no keepalive" the ports would all show as "up/up" since you lost your ability to determine whether it was REALLY functional or not.
On virtual interfaces like GRE tunnel u can turn off keepalives.
Scenarios like if you are running any IGP lets say OSPF between GRE tunnels; keepalive can be turned off safely.
Some times during troubleshooting/testing its required that physical interface should stay up in that case no keepalive is used.
For a switched environment specifically, I would rather *NOT* have it disabled. Take a look at this:
People generally tend to use the no keepalive error command on an interface to stop this from happening.
You might, in a switched network, also see the following logs:
3w0d: %ETHCNTR-3-LOOP_BACK_DETECTED: Keepalive packet loop-back detected on Fast Ethernet0/10.
3w0d: %PM-4-ERR_DISABLE: loopback error detected on Fa0/10, putting Fa0/10 in err-disable state
3w0d: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/10, changed state to down
3w0d: %LINK-3-UPDOWN: Interface FastEthernet0/10, changed state to down
Keepalives are sent on the Catalyst 2940, 2950, 2950-LRE, 2955, 2970, 3550, 3560 or 3750 switch to prevent loops in the network. The primary reason for
the keepalives is to prevent loops as a result of Type 2 cabling. The problem occurs because the keepalive packet is looped back to the port that sent the keepalive. There is a loop in the network. Although disabling the keepalive will prevent the interface from being errdisabled, it will not remove the loop.
Keeping the above in mind, makes it a little bit necessary to have this in place. Obviously there are other methods in which we can troubleshoot or detect STP loops, however this is quite a reliable method.