The source said one policeman was killed and three wounded in an initial shootout and that another four were killed when additional troops sent to combat the militants came under attack.
"At about 14:00 Moscow time (10:00 GMT) a column of riot police was hit by an explosion, and unknown attackers then opened fire at it from a nearby wood. As a result of the attack, four servicemen died at the scene, while six sustained serious injuries and were taken to a local hospital," the source said.
He also said an operation had been launched to find the gunmen.
The incident took place some 30 km (19 miles) southwest of Makhachkala.
Militant attacks are common in Russia's North Caucasus republics. Neighboring Ingushetia has seen a marked rise in militant activity of late.