A Queens judge has set $2 million bail for the late John Gotti’s namesake grandson, who has been behind bars since his August arrest on drug charges.

John Gotti, 23, can thank Queens Supreme Court Justice Charles LoPresto for the chance at freedom, but will still have to wait for a bail sufficiency hearing before the dough can be posted.

A date for the not-so-Teflon grandson’s hearing has yet to be set.

If he is freed, the accused prescription-drug peddler will be forced to wear an ankle bracelet and surrender his passport, the judge said.

The beefy Gotti’s dad is Peter Gotti, the son of the Dapper Don who ruled the Gambino crime family — and evaded successful prosecution — until he was finally put away for life in 1992 when his right-hand man, Sammy “The Bull” Gravano, ratted him out to federal prosecutors.

The elder Gotti died of cancer in a federal prison in 1992.

The namesake was arrested after cops raided his grandpa’s Howard Beach home and discovered him with a veritable trove of drugs and cash.

The bust came just two months after Gotti was stopped with some 200 oxycodone pills and various other drugs stuffed inside his car console.

Gotti has been in drug treatment while at Rikers, according to his attorney Gerard Marrone.