You appear to be describing lice. Here's a synopsis on how lice are addressed:
1. Affected and all in-contact same-species animals should be treated.
2. Matted hairs should be clipped away.
3. Traditional therapy is to topically treat your dog's entire body with over the counter 2% lime sulfur, pyrethroids, carbaryl, or organophosphate shampoo, powder, spray, or dip twice 2 weeks apart. Just about any flea insecticide kills lice.
4. Alternative treatments include the following:
Injectable ivermectin given at 0.2 mg/kg orally or subcutaneously 2 weeks apart. Ivermectin is available over the counter in pet/feed stores. Please let me know if you need help figuring the dose for your dog.
Selamectin (Revolution) spot-on (as per label), topically twice 2 weeks apart. Treatment administered every 2 weeks at least four times may be more effective. This is a prescription drug available through your vet.
Injectable doramectin given at 0.2-0.4 mg/kg orally every week for 3-4 weeks. This is a prescription drug available through your vet.
0.25% fipronil pump spray (over the counter Frontline, e.g.) 6ml/kg, topically, twice, 2 weeks apart.
10% fipronil spot-on (over the counter Frontline, PetArmor, Fiproguard, e.g.) topically, twice 2 weeks apart.
5. Bedding, grooming tools, and environment should be cleaned at least once. A professional fumigator is suggested if you've struggled with this problem for quite some time.
6. Prophylactic use of insecticidal flea collars may protect exposed animals from infestation, but avoidance of infected animals is ideal.
The prognosis is good. Lice are highly contagious from dog to dog and from cat to cat, but they aren't considered contagious from dogs or cats to humans. Please respond with further questions or concerns if you wish.