So, you're a king/nobleman and your mistress has given birth to a child. Historically, rich and powerful men fathering bastards was more an issue in monogamous societies like medieval Christian Europe - in polygamous societies, rich men could exhaust themselves with as many concubines/wives as they wanted.
(Note: in much of Europe, surnames did not emerge until post-medieval times, which would make your question moot; I'll broaden your question.)
The less wealthy often got rid of their bastards (and unwanted legitimate children) by dropping them off at a church or foundling hospital and leaving the priests and nuns to name the baby (like Oliver Twist in Dickens' novel; the great mathematician Jean-Baptiste le Rond d'Alembert was named after the patron saint of the church his mother left him at). Disease and mistreatment were common in foundling hospitals, and leaving a baby there was often a virtual death sentence.
Wealthy nobles, otoh, had the resources to support their bastards. Sometimes the bastard would be officially recognised by the father at birth. In this case, the child would bear the father's surname, e.g. Francisco Pizarro, the conqueror of Peru. Sometimes the nobleman found a man who could be induced to marry the mistress and accept the child as his own, or, even better, the mistress was already married to a complaisant or ignorant husband. Sometimes the mother's surname was used.
Royal bastards were often given surnames, fortunes and titles by the king. FitzRoy (son of the king), FitzWilliam (son of William), etc, etc was a frequent pattern used by English monarchs. Here's one famous anecdote.
The actress Nell Gwynn presented her son to Charles II:
"Come hither you little Bastard and speak to your father!"
"Nay, Nellie, do not call the child such a name," said the king.
"Your majesty has given me no other name by which I may call him."
Charles got the point, and gave the child the surname "Beauclerk" and made him Earl of Burford. https://books.google.com/books?id=0p1GymO7KvYC&pg=PA111
German bastards sometimes used the name of their father, but without the noble particle 'von'. https://books.google.com/books?id=YdYdCgAAQBAJ&pg=PA234
There was a unique Russian custom of shortening the father's surname and using it as the child's surname - Ivan Pnin was the bastard of Prince Nicholas Repnin, and his surname was later used by Nabokov for the title character of his famous novel.