HO CHI MINH CITY — When I returned to this city from the United States last year, I paid $25 a month to live in a single room among several that lined a fetid, often flooded alley. The row of low-slung rentals with their squat toilets and rotting walls lay on the industrial outskirts of town. But I put up with it to live near a relative who’d come down from central Vietnam. I joined his circle of friends in the alley, most of whom had bonded together over their shared status as out-of-towners looking for jobs.

Vietnam is one of the few countries in the world whose citizens must live where they’re registered or ask the government’s permission to relocate.

What I didn’t realize at the time was that some of them had entered the city illegally, in violation of a policy left over from the days before economic liberalization in the 1980s.

Vietnam is one of the few countries in the world whose citizens must live where they’re registered or ask the government’s permission to relocate. This ho khau system borrows heavily from China’s hukou, which was developed in the years after the Communists took power in 1949. Similarly, starting in the 1950s the Communist rulers in Vietnam required people to list members of their households in their ho khau booklets, including age, occupation and ethnic group, in order to track people’s movements.

At first the main objective of the policy was to control “counter revolutionaries and criminals,” writes Andrew Hardy in the academic journal Sojourn. Restricting movement was especially important to the authorities in Vietnam after the 1954 Communist victory against France in the north triggered an exodus of anti-Communists toward the south.

After the war, once Vietnam was reunified in 1975, ho khau laws were expanded to cover the entire country. Many citizens stayed put during the postwar period, from 1975 to 1986. It was a planned economy then, and the state doled out food and allocated jobs on the basis of ho khau.

Although the country no longer rations food, it has kept ho khau in place, in the hopes of staving off a population explosion in the cities. Not only has the policy failed to accomplish that, but it has created, in a country that professes classlessness, a group of second-class citizens.

In the controlled free market that has now largely supplanted the subsidy system, Vietnamese rely less on the state for basic goods and services and so have much more incentive to go where the jobs are. Many private businesses don’t ask for ho khau when hiring.

There are no statistics on the number of undocumented migrants, according to Nguyen Thi Hong-Xoan, dean of sociology at the University of Social Sciences and Humanities in Ho Chi Minh City. But Hong-Xoan, who wrote her doctoral thesis on ho khau, told me that most people don’t change their paperwork when they move. And according to the 2009 census net migration from the countryside to the cities was 1.4 million people between 2004 and 2008. The figure was 770,000 people for the five years leading up to the 1999 census.

This demographic shift is especially affecting Hanoi. Some 6.5 million people lived in the capital in 2009, compared with just 2.7 million a decade earlier — a 140 percent increase. During the same period, the total population of Vietnam rose by 12 percent.

But many migrants find more challenges in the cities than they’d expected. While the cities’ recognized residents have property rights and access to public schools and health services, newcomers don’t. Outsiders pay double the cost for water and electricity because they’re excluded from the few government subsidies that remain, which require ho khau. They face discrimination, and local officials often blame them for rising crime rates and worsening sanitation.

To help close this growing gap, a 2010 U.N. report recommended “decoupling access to services from residency status.” But policy makers have interpreted the continuing rural exodus to mean that they must clamp down harder on migrants and reinforce ho khau. From this month on, Hanoi’s residents will be allowed permanent residence status only if they have lived there for three years, have state jobs, buy property or move in with relatives who have permanent residence.

In the rest of the country, for now, migrants need to prove they have lived somewhere for just one year in order to apply for permanent residency. But some fear that the crackdown in the capital could inspire Ho Chi Minh City and others to follow suit.

Critics say that the registry system won’t curb mobility any more than it has in the past. Meanwhile, the system is separating insiders from outsiders and creating a form of urban apartheid.