Oh gosh! I had almost forgotten the head-banging phase! My dd was doing this at your ds's age. As long as she wasn't seriously hurting herself (she never did), we tended to let her express her frustration that way. It didn't last long...and as you see, I'd already forgotten about it! Hang in there! Maybe offer him a pillow to hit (model that for him so he sees what to do) and explain in words that he can hit the pillow if he is angry. Talk about normal emotions (frustration, anger, etc.). Say, "I see you're angry, do you want to hit this pillow?" or something like that. Let him know that you acknowledge his feelings and that you think they're normal (OK).
Be firm about the hurting. Talk about how you feel when he does that. Offer an alternative. Remove him from the situation if he continues. No use sitting there, leaving him the chance to continue and then scolding him (not saying you're doing this). Just get up and do something else.