I recently read something about the longest train travel possible. The rules are simple. You can change but you should always travel by train. (Getting a train to somewhere, making a couple of km by bus to a connecting station is not an option). Doing diversions to increase the route is not a possibility either. Else you could just travel in circles around Europe (or anywhere else) and travel forever.
Unfortunately this was only a tweet, that mention that the longest train travel was from Portugal to Vietnam.
Does anyone know about this route? is it really possible? is it actually the longest?
According to the author the largest travel train possible stretches from Portugal to Vietnam. 17.000Km by train.
Unfortunatly the post is from 2011 so the prices might not be updated The total journey would take around 14 days and cost around 2000 USD.
In terms of the Great Circle distance, it is about 1000 miles shorter than the journey related in the previous answer from Oporto to Saigon, so I concede it falls someway short of being the longest, but his story is entertaining enough to deserve a plug.
While the pair Lagos, Portugal and Saigon/Ho Chi Minh City, Vietnam might be the right one, it looks like above suggested route is a diversion. Originally I hoped to find a shorter route in the far south but this didn't work out, but following the silk route one should be able to find a shorter route.
Unfortunately it is hard to give an optimal answer. It might be doable to find the fastest connection between these two cities (if you know which cities you will pass definitely), but it is harder to find the shortest such route in terms of distance.
I'll here give an outline of the fastest journey along the silk road. This however is far from the shortest such route. Just note that it would be much shorter to go from France to Switzerland, Austria, Hungary and via Ukraine to Russia without going up to Moscow (but going via Voronezh to Samara).
It should be clear that in Europe this is not short but fast. The main difference to above answer is going from Moscow to Astana and onwards to Urumqi and Nanning (via, for example Chongqing).
Comparing just the time spent on trains (without times needed to change; I think a few of the trains involved in my answer don't run daily, so figuring out this would add some more difficulty), with nsn's answer it takes around 190 hours (not counting the subway ride in Beijing) to get from Moscow to Hanoi. Using my answer, one spends around 177 hours on trains from Moscow to Hanoi. I'm pretty sure though it will take more time to take this route since there are more changes involved.
Unfortunately I don't know of any way to calculate the distance of this route, but I'm quite certain it is shorter.