A Shimano derailleur can't really bang against the cogs. Most likely it is banging against the bottom of your chainstay when it swings forward from bouncing across rocks. You can fix it by picking a bigger cog so that it doesn't hit, or by putting some padding (piece of inner tube, etc) on the chainstay or derailleur. Wrapping the whole chainstay with an old inner tube will also help quiet things down when the chain slaps the chainstay.