Islam considers cleanliness very important, and keeping some kind of pets can sometimes be a burden in terms of cleanliness. This looks like a contradiction to me.
Is there a law about keeping pets? Did Rasulallah (S) keep any pet?
You can keep permissible animals as pets as long as you treat and feed them properly. And the permissible animals are many like fish, birds, cats. Impermissible from what I know are only dogs because Islam has forbidden keeping dogs except guard dogs and hunting dogs.
Abu Hurairah (May Allah be pleased with him) said: The Messenger of Allah (PBUH) said,
He who keeps a dog, will lose out of his good deeds equal to one Qirat every day, except one who keeps it for guarding the fields or the herd.
[Al-Bukhari and Muslim].
In a narration of Muslim, the Messenger of Allah (PBUH) is reported to have said:
He who keeps a dog for any reason other than to guard his property (lands) or his flock of sheep, his good deeds equal to two Qirat will be deducted every day.
and Narrated by al-Bukhaari (3225) and Muslim (2106) that
“The angels do not enter a house in which there is a dog.”
Abu Hurayrah was so called because of a cat which used to accompany him.
Al-Bukhaari (6203) and Muslim (2150) narrated that Anas (may Allaah be pleased with him) said: The Prophet (peace and blessings of Allaah be upon him) was the best of people in attitude. I had a brother who was called Abu ‘Umayr. He (the narrator) said: I think he said: He was a weanling. When the Messenger of Allaah (peace and blessings of Allaah be upon him) came and saw him, he said: “Abu ‘Umayr, what happened to the nughayr (nightingale)?” He used to play with it.
The above hadeeth shows it is also permissible to keep birds as pets and children can play with them.
It is also known that the saliva of cats is not impure (naajis):
Because of the report narrated in Sunan Abi Dawood and elsewhere, which says that a woman brought some hareesah (a kind of food) to ‘Aa’ishah (may Allaah be pleased with her) and found her praying. (‘Aa’ishah) gestured to her that she should put it down. Then a cat came and ate some of it. When ‘Aa’ishah had finished praying, she ate from where the cat had eaten and said, “The Messenger of Allaah (peace and blessings of Allaah be upon him) said: ‘They (cats) are not naajis (impure), rather they are among those who go around among you (al-tawwaafeena ‘alaykum).’ I saw the Messenger of Allaah (peace and blessings of Allaah be upon him) doing wudoo’ with water from which a cat had drunk.”
What is impermissible is showing extravagance with animals i.e. spending lot of money on beautifying them and such.
According to Jafari Fiqh Pets are all allowed, except that one must be careful about such pets which are NAJIS. Secondly Islam enjoins upon us to look after them well. If we cannot, then they must be released.
Islamically there is no problem in keeping a guard dog on your premises. Since dogs (and pigs) are from Najisul `ayn (inherently impure) animals, you will have to make sure that they do not lick the areas which are always supposed to remain tahir, such as place of prayers, place where sacred things like the Holy Qur'an and sajdagha (turbah) are kept. Also, do not eat or drink from the utensils which have been licked by the dog, unless you have cleansed it by rubbing with wet clean earth and then washing it with water. Sometimes your dog will cling to your clothes (say, pants) then such clothes should not be worn for salat.