Two of the Baby Bell telephone companies, seeking solid investments and chafing over rules that bar them from key businesses in the United States, have decided to spend $2.4 billion to set up in a place that has the freedom they want: New Zealand.

Bell Atlantic Corp. and Ameritech Corp. will buy virtually the entire telephone system of the Pacific island country, Telecom Corp. of New Zealand, thereby speeding up a worldwide trend in which governments are selling off phone systems in hopes that private owners, domestic or foreign, will bring new dynamism, services and technology.

Analysts said the deal is the world's first in recent times of a large local phone company being bought by foreign interests. It will give a major boost to the limited success of Baby Bells in expanding overseas, they said.

"Our industry is rapidly globalizing," said William L. Weiss, chairman of Chicago-based Ameritech. "Political boundaries have little meaning to technology today. {But} they still have a great deal of meaning in terms of government policy and regulatory control."

With the deal, New Zealand joins Britain and Japan, which have moved vast government-owned telephone systems to the private sector. Mozambique and Angola have also sold their national telephone companies.

France and West Germany have kept their systems in state hands, but they have opened part of their operations to competition. Mexico's is on the market, Hungary is talking of privatizing and Portugal's main system is to be sold by July 1991.

In many cases, government hunger for cash is part of the motivation.

The court order that spun off the seven Baby Bells from the monopoly Bell Telephone System in 1984 bars them from three lines of business: long distance, manufacturing and "information services" -- supplying computer data over telephone lines.

With growth limited in their core business of providing local telephone service, the companies have been fighting in Congress and the courts for permission to enter the restricted operations, where prospects are more robust. In the meantime, they have been going overseas, where new markets await and the U.S. rules generally do not apply.

Various Baby Bells are now major players in running cable TV systems in Britain. US West Inc. of Denver has led an international consortium that wants to build a fiber-optic, long-distance line across the Soviet Union, but it has been blocked on national security grounds. Pacific Telesis Group of San Francisco has invested in a Japanese company that owns half of a transpacific fiber-optic cable.

New Zealand's Telecom had net income of $148 million on revenues of $1.3 billion in the fiscal year that ended March 31. "We believe the company represents very solid value for its new American owners and potential investors," said Peter Troughton, Telecom's managing director.

It was not clear that the two American companies' stockholders agreed, however. Bell Atlantic shares were down 62 1/2 cents to $51.75 in trading yesterday, while Ameritech was down $1 to $64.

The New Zealand company provides local telephone service on 1.4 million telephone lines in communities throughout the country. In addition, it provides domestic and international long-distance links and, in limited quantities, information services -- fields barred to the Bells in this country.

Deregulation of U.S. telecommunications began timidly in the 1960s, picking up steam that culminated with the Bell System breakup in 1984. Around the world, many countries have followed suit, injecting competition and private control into a business traditionally run as a state-owned monopoly.

"They've seen what has happened in our industry in terms of the technology and the multiplicity of telecom services," said Konnie Schaefer, who heads telecommunications consulting firm K. Schaefer & Associates in Washington.

Not all phone companies are as attractive to foreign capital, however. Various Bell companies have been looking at Mexico's troubled system, for instance, but with great caution. "In terms of investment risk," said Schaefer, "it's substantially different from New Zealand's. It's also a whole bunch larger."

In any case, most countries do not give foreigners free rein, believing that the national telephone system is a strategic asset. Japanese law bars the sale of even a single share of Nippon Telegraph & Telephone Corp. to foreign citizens. In the United States, foreign ownership of local phone companies is limited to 20 percent or 25 percent, depending on how they are set up.

New Zealand has similar concerns. Bell Atlantic and Ameritech will initially buy 100 percent of the company but they will have to reduce their stakes to a combined total of 49.9 percent over the next several years. Two New Zealand companies are to hold 5 percent each, with the remaining 40.1 percent to be sold on the New Zealand stock exchange and foreign equity markets.

The deal calls for New Zealand citizens to hold a majority of the board seats and to manage the company. The new owners have made commitments that rate increases will not exceed inflation.