All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah and that Muhammad is His slave and Messenger.
It is Islamically permissible for a child to be traced back to his grandfather or great-grandfather, or directly to his family name, on condition that one does not intend by this to exclude being traced to his father (i.e. to deny being traced back to his father).
Ibn Battaal, when interpreting the hadeeth reported by al-Bukhari, said, “The Prophet said, ‘I am the son of Abdul-Muttalib,’ while he was the son of his son [i.e. ‘Abdullaah while Abdul-Muttalib was his grandfather], and the scholars agreed in consensus that the ruling of the grandfather is the same as the ruling of the father in many contexts.”
Shaykh Ibn Uthaymeen while interpreting Riyadh As-Saaliheen, said:
“If a person is traced back to his grandfather or to his great-grandfather who is famous and well-known without intending by this to exclude being traced to his father, then there is nothing wrong with this; indeed, the Prophet said, ‘I am the Prophet in truth, I am the son of 'Abdul-Muttalib,’ while he is Muhammad ibn ‘Abdullaah ibn 'Abdul-Muttalib; 'Abdul-Muttalib was his grandfather, but the Prophet said that in the Battle of Hunayn because 'Abdul-Muttalib was more well-known than his father ‘Abdullaah, and he ['Abdul-Muttalib] held a position of prestige with Quraysh; it is for this reason that he said, ‘I am the son of 'Abdul-Muttalib,’ but it is known that he is Muhammed ibn ‘Abdullaah, and he did not intend to exclude being traced to his father.”
Allaah knows best.