I agree with Lulucheung that you should ignore your baby when he does that. Because the baby feels funny with your reaction to stop him, so he will repeat the behavior. But if he bangs his head to the wall or do something to hurt himself, you have to stop him immediately. Take him to another room, let him sit and you hold his shoudler firmly with your hands, don't let him move. You remain silent, after a few minutes, you tell him if he does that again, you will do the same thing to him. This is a good way to discipline baby, I learn it from the book "Raising a happy, unspoiled child".