MADRID (Reuters) - U.S. President Barack Obama has warned that attacks on police over racial bias would hurt the anti-racism Black Lives Matter movement, days after a sniper killed five police officers in Dallas in apparent revenge for police shootings of black people.

Obama said although most activists from the Black Lives Matter movement wanted to see better relations between communities and law enforcement, violence and overly broad criticism against police undermined the protest movement.

“I want to say to say to everyone concerned about ... racial bias in the criminal justice system that maintaining a truthful, serious and respectful tone is going to help mobilize American society to bring about real change,” Obama said.

“Whenever those of us who are concerned about failures of the criminal justice system attack police, you are doing a disservice to the cause,” he told a news conference in Madrid where he is on a one-day visit.

Micah Johnson, a black U.S. military veteran of the Afghan war, opened fire on police officers on Thursday during a protest in Dallas against the fatal shootings of two black men by police in Louisiana and Minnesota the previous day.

Johnson wanted to “kill white people, especially white officers,” Dallas Police Chief David Brown said after the attack on Thursday night.

The Black Lives Matter group said on Friday it advocated dignity, not murder, in response to the shooting that also left seven other police officers and two civilians wounded.

Obama said there was legitimate criticism to be made of the criminal justice system and that citizens should continue to protest against it.

“I would hope that police organizations are also respectful of the frustrations that people in these communities feel and not just dismiss these protests as political correctness or politics or attacks on police,” he said.