Sunan Ibn Majah, Volume 4, Book 23, Hadith 2745 (DarusSalam)

It was narrated from ‘Amr bin Shu’aib, from his father, from his grandfather that the Messenger of Allah said: “Whoever commits adultery with a slave woman or a free woman, his child is illegitimate, and he cannot inherit from him or be inherited from (i.e., this child cannot inherit from him).”

حَدَّثَنَا أَبُو كُرَيْبٍ، حَدَّثَنَا يَحْيَى بْنُ الْيَمَانِ، عَنِ الْمُثَنَّى بْنِ الصَّبَّاحِ، عَنْ عَمْرِو بْنِ شُعَيْبٍ، عَنْ أَبِيهِ، عَنْ جَدِّهِ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ مَنْ عَاهَرَ أَمَةً أَوْ حُرَّةً فَوَلَدُهُ وَلَدُ زِنًا لاَ يَرِثُ وَلاَ يُورَثُ ‏" ‏ ‏.‏

sunnah.com