Sunan Ibn Majah, Book 28, Hadith 2 (Ibn Majah 3203)

It was narrated from ‘Abdullah bin Mughaffal that the Messenger of Allah (ﷺ) commanded that dogs be killed, then he said:

“What do they use dogs for?” Then he permitted them to keep farming dogs and dogs of ‘Ein. Bundar said: “The ‘Ein refers to the walls of Al-Madinah.”