The first thing would be to have the Qin drop their harsh legalist policies as soon as they get their empire in order. And I mean at once. Qin Shi Huangdi himself is going to have to reform his policies to make them less draconic. His failure to do so led to far too much opposition. So one generation later is already too late. If this can be achieved, a lot of reasons for OTL opposition to Qin rule will largely disappear. The Han dynasty never emerges, and the Qin empire continues. This is needed just to get to a place where "lasting Qin dynasty" is even possible.
Now, given that premise, how realistic is it for a an imperial dynasty originating in 221 BC to keep existing for 2238 years? Well, it's not the most likely course of events! But then again, considering that the imperial family of Japan has been there for at least the past 1500 years, a very long-existing dynasty cannot be ruled out as ASB. On the other hand, China is not Japan. The latter one had the advantage of relative isolation, whereas the former was far more 'in the thick of it' when it came to invasions etc. -- And also, China was a vast empire, and those are just very likely to break up from time to time. In fact, keeping China together without any periods of division seems much harder to me than 'simply' preserving a dynasty.
The trick would be to keep the inevitable periods of division more like the Spring and Autumn Period (or, perhaps more fittingly, like the Tokugawa era of Japan). That is: the ruling dynasty stays in charge formally, but has little to no actual power. The emperor is a chiefly ceremonial figure, and removing him would actually be detrimental to the legitimacy of whoever is really in charge at any given time. If you can achieve that situation, you can maintain an unbroken dynasty of emperors, even through periods of near-complete division.