Kenya has ordered all refugees living in urban areas to return to their camps in a bid to end attacks by armed groups carried out in retaliation for Kenya's intervention in neighbouring Somalia.

Kenyans were asked to report any refugees or illegal immigrants outside the overcrowded camps - Dadaab in the east and Kakuma in the northwest - to the police, the AFP news agency reported on Tuesday.

All refugees residing outside the designated refugee camps of Kakuma and Dadaab are hereby directed to return to their respective camps with immediate effect. Interior Minister Joseph Ole Lenki

"Any refugee found flouting this directive will be dealt with in accordance with the law," Interior Minister Joseph Ole Lenku said in a statement.

Lenku issued the order citing "emergency security challenges" in Kenyan towns, but the move is likely to be criticised by rights groups which have discouraged similar actions in the past.

Until now, refugees who could support themselves or were in need of specialised education or medical care had been allowed to live in urban areas.

Lenku said "all refugees residing outside the designated refugee camps of Kakuma and Dadaab are hereby directed to return to their respective camps with immediate effect."

The refugees are now required to be housed at Dadaab, close to the Somali border, and at Kakuma, near Kenya's frontier with South Sudan.

Al Jazeera's Mohammed Adow said that implenting the directive could prove a daunting task for the government.

"There are a huge chunk of those refugees who live in urban areas who have legal papers. What is the Kenyan government going to do with these people who have the proper papers?" he said.

"There are over four million indigenous Kenyan-Somalis ... who are Kenyan citizens. They have been complaining over the past decade that they have not been issued with the right papers. And the government, in its defence, has been saying it cannot identify who is from across the border or who is a Kenyan. Now what's going to happen to all those indigenous Kenyans who do not have the right papers?"

Police confirmed to Al Jazeera that two suspects were killed and 476 arrested in overnight raids in Eastleigh, a neighbourhood with a large Somali population.

"[Police] insist they were not only targeting the Somali community but petty crime across the city. Some of those in custody are refugees with no documentation," said Al Jazeera’s Nairobi producer Evelyn Kahungu.

Church assault

Kenyan security officials believe armed groups have used the refugee camps as bases to prepare attacks and then mingled with residents in urban areas to carry them out.

Al-Shabab and its sympathisers have carried out several attacks in Kenya, including at the Westgate shopping mall in Nairobi last year in which at least 67 people were killed.

On Sunday, gunmen killed six worshippers in a church near the coastal city of Mombasa. Last week, police said they had arrested two men found to have two large bombs in a car, which they intended to use in Mombasa.

Mohamed Ali Hassan, president of the Somali-American Peace Council, told Al Jazeera that there were many Somalis in Kenya who were providing for themselves and, through their business activities, boosting the Kenyan economy.

"This would be a very bad decision for them. We can understand [the Kenyan government's] concern of security but if someone wants to kill themselves in order to kill other people there's really little you can do. And this won't help."

In January last year, a similar move by the government to relocate an estimated 100,000 urban Somali refugees brought condemnation from the New York-based rights group Human Rights Watch.

In November 2012, prior to a plan to restrict Somali refugees to camps, street battles erupted between Kenyans and ethnic Somalis in Eastleigh, a part of Nairobi commonly dubbed "Little Mogadishu" because of its large Somali population, after a bomb on a minibus killed seven people in the area.

Al-Shabab has threatened to carry out further attacks if Kenyan troops do not withdraw from Somalia where they are battling the insurgents as part of an African Union peacekeeping force.