A Queens teacher was sentenced yesterday to only six months in prison for having sex with a student, but he’s a sex offender for life — a label that could keep him from raising his own daughter.

Daniel Reilly, 36, formerly of IS237, landed the deal in May when he pleaded guilty to second-degree rape for having a yearlong affair with a 13-year-old girl in his family’s Forest Hills home.

The deal was designed in part to spare the student the burden of testifying at a trial.He had considered rescinding the plea when he learned the sex-offender tag could bar him from his 15-month-old girl. But he gambled that probation officials wouldn’t order that.