Your dog could have thunderstorm or noise phobia, a fairly common condition. The first thing you need to understand is that your dog is actually scared of these noises. To help him feel more secure, try creating a dark, sound-proof enclosure for your dog inside the house. This could be a dog crate wrapped in egg-carton-type mattress foam to make it sound proof. You will probably need to train your dog to accept this new confinement area by throwing food treats inside and giving him rewards for going inside. Also, give your dog long massaging pats to try and sooth him.
Alternatively, make sure your dog is in a room that is as dark and as sound proof as possible whenever there is thunder or fireworks. Play a radio or music to disguise or drown-out the noise. Even 'white noise' (TV or radio static) can assist. Sometimes a CD of thunderstorm noises can assist some dogs in getting used to these strange sounds. Do something fun with your dog whilst thunderstorm noises so you desensitize them, so by associating thunderstorms with a fun and exciting and non-threatening activity.
If your dog still seems to need help there are medications and pheromones that can assist. Some are short-term medications and some work for longer. These are only available from your vet or a veterinary behaviourist.