Boko Haram gunmen dressed in military uniform have killed 19 people near the Nigerian border with Cameroon in the restive northeast, residents and a survivor say.

The gunmen, armed with Kalashnikovs, blocked a highway on Sunday near the town of Logumani, 30km from the border around 5am local time, shooting and hacking to death 19 motorists and burning three trucks, residents said.

"We have recovered 19 dead bodies from the scene of the attack by Boko Haram gunmen," Musa Abur, leader of a civilian vigilante group in the area, told the AFP news agency.

"Five of the victims, who included two truck drivers and their assistants, were shot dead while the rest were slaughtered," he said.

He said the gunmen had attacked the border town of Gamboru near Logumani late on Friday but were repelled by soldiers and local vigilantes.

A similar account was given by another passenger. "We were asked to get out of our vehicles and lie face down by nine men dressed as soldiers who blocked the road around 5:00am," the man who gave his name as Buba told AFP.

"They shot dead five people and went about slaughtering 14 others before someone called them on the phone that soldiers were heading their way," he said.

"They abandoned the rest of us and sped into the bush on their motorcycles," added Buba who was shot in the leg.

He said the attack had the hallmarks of Boko Haram.

"We knew they were Boko Haram from their appearance. Soldiers don't wear beards but some of the gunmen were bearded," he said. "Everyone in this area knows Boko Haram is on the prowl, raiding villages and attacking vehicles. It has become a common occurrence."

Boko Haram, whose name translates as "Western education is sinful", has had a long history of violence and has stepped up deadly attacks on civilians and schools in repraisal against vigilantes co-operating with the military.

The group says it is fighting to create an Islamic state in Nigeria's mainly Muslim north, but it is believed to be made up of different factions with varying aims.