The Messenger of Allah ﷺ ordered that dogs be killed, then he said, "What is the matter with them and with dogs?" Then he gave permission to keep dogs for hunting and for guarding sheep.
أمر رسول الله ﷺ بقتل الكلاب، ثم قال: ما بالهم، وبال الكلاب؟ ثم رخص في كلب الصيد والغنم.
Muslim reported it in Musaqat (1573), from Ubaydullah bin Muaz, who said, "Our father narrated to us, Shubah narrated to us, from Abu Tayah, who heard Mutarrif bin Abdullah, from Ibn Mughaffal," and he related it.