If you notice your dog eating dirt it may be because he is suffering from mineral deficiencies and is trying to compensate for this by getting minerals from the dirt that he is eating. If you notice this behaviour you may have to change your dog's food. Your vet can advise you on the best food for your dog.
A wonderful little Beagle puppy tearing around on the garden
However your dog may be eating mud out of boredom. If this is the case you need to be very vigilant when your dog is outside and use discipline to teach your dog not to eat mud. If you see this behaviour, give him a spray on his nose with water. He will soon associate mud eating with a negative experience and should stop.