Several reasons could be the culprit to your animal’s anxiety. It could be that your dog experienced something traumatic that happened to him at the same time as the noise, thus he may associate that sound with the traumatic event he experienced.
Another possible reason is that dogs have much more sensitive ears than humans do. It could very likely be that it is physically painful for your dog to endure these noises and when he hides from them he is really just seeking refuge from the pain.
It could also be possible that your dog is learning from you that loud noises should be reacted to with fear. Do fireworks bother you as well? Do you get anxious or fearful during thunderstorms? Dogs are very empathetic animals. If you are communicating to him (verbally or non-verbally) that a certain sound is something to be feared, then he may be taking your cue and reacting by being afraid.
The most likely cause for your dog’s fear of loud noises, however, is how you treated him as a puppy. A young puppy is easily frightened by big or intimidating things, noises included. A human reaction to a child being frightened is to coddle it: to hold it or otherwise show affection to assure that things are alright and to comfort it. While this reaction may be appropriate in humans, dogs are pack animals and you are sending the signal that this booming noise is something the pack should huddle together for. Huddling together, in a pack mentality, is something that is done when there is genuinely something to be afraid of. Thus by petting and holding your puppy when you feel it is afraid you are reinforcing his fear and telling him “Yes, this is worthy of your anxiety”.
Once you have set this precedent in a puppy, you have cemented this anxiety into your adult dog’s mentality. While it sounds bad, there is a way to reverse this.
Desensitization is an exercise used to make a dog comfortable and unconcerned with these fear triggers. To desensitize your animal to the noises it is afraid of, you need to first get a recording of these noises. Find a recording of fireworks or thunder or trains or make one yourself. Everyday, you should take your dog into a quiet room with the recording and play it, at first at a very low (barely audible) level. Have treats to reward your dog with and pet him and praise him while doing this. Each day, you should slightly increase the volume of the recording that you play while praising and rewarding him. Eventually, you should get to the point where you can play the recording of the startling noise at full volume without your dog being afraid. Your dog will by now associate the noise with calmness, affection and treats and should no longer be concerned with it.