The Soviet Union has stationed the flagship of its Mediterranean fleet in Tripoli to help Libyan leader Muammar Qaddafi keep track of U.S. military movements and to deter an American attack by standing close to one prospective target, Pentagon officials said yesterday.

The flagship, a submarine tender packed with radio gear, is part of an expanding electronic eavesdropping and warning net that the Soviets have been placing in the Mediterranean off the Libyan coast, administration officials said, at the same time that President Reagan is strengthening U.S. naval forces in the region.

Defense Department spokesman Robert B. Sims volunteered some details yesterday on changes in Soviet deployment of its ships off Libya, starting early this month. But he declined to link the changes to administration hints of military retaliation against Libya after the terrorist attacks at the Rome and Vienna airports on Dec. 27.

White House and State Department spokesmen at the time tied the terrorist acts to Libya and held out the possibility of a retaliatory strike. Military leaders, following routine contingency planning, mapped elaborate plans for bombing Libya in case Reagan opted for military action, with a terrorist training camp outside Tripoli near the top of the list of potential targets.

"You can make whatever connections you wish," said Sims when asked if administration suggestions of military retaliation might have prompted the Soviet naval response. "I'm just giving you the facts. I'm not trying to make a connection between what somebody said we might be doing . . . . I don't allow for that."

The Soviets have 26 naval ships in the Mediterranean, mostly noncombatants but including a Kashin-class destroyer and two Krivak-class frigates armed with antiaircraft missiles, according to Pentagon officials. The picket line of ships stretching from off Tripoli to a point near the coast of Syria includes the Kashin and two Krivaks, officials said.

The Soviets also have an electronic eavesdropping trawler trailing the aircraft carrier USS Coral Sea and escorting warships, which were in the Ionian Sea between Greece and Sicily yesterday. In hopes of locating U.S. submarines off Libya, officials said, the Soviets have been flying over the area with Il38 May planes equipped with detection devices, Sims said.

The Soviet submarine tender in Tripoli and ships in the Mediterranean are linked to each other and shore stations in Libya and the Soviet Union, officials said. It is standard practice for such ships to intercept and record U.S. military communications, and to keep command centers informed of American ship and aircraft activity.

"We have to assume this is an integrated effort to obtain detailed information about our fleet operations and provide it to the Libyans," Sims said. The Soviet effort is of "concern" to the Pentagon, he added, because it might help the Libyans if they attacked American forces, as Qaddafi has publicly threatened to do on several occasions.

Administration officials said the Soviets may have seen a triple dividend in deploying a picket line of ships off Libya and berthing a flagship in the port of Tripoli, the Libyan capital: the ships would provide intelligence on American activities in the Mediterranean for both Moscow and Tripoli; their presence might inhibit Reagan if he were planning a military strike against Libya, and the Soviet Union would be helping an Arab client state in a highly visible way.

Extensive electronic eavesdropping and jamming is already well under way off Libya by both the United States and Soviet Union, military officials said. The U.S. Navy has EA6B Prowler electronic eavesdropping and jamming aircraft at Sigonella, Italy, which could be used against Soviet SA5 antiaircraft missiles recently sent to Libya.

As of yesterday, the United States had spotted 12 launchers for the SA5s but not the missiles themselves at Sirte on the Libyan coast, officials said, and two Soviet ships have been unloading SA5 components at Bengasi. One theory is that the Soviets will put in place a string of missile sites along the coast, with the westward anchor near Tripoli and the eastward one near Bengasi.

Although U.S. fighters and bombers could evade the SA5s by staying below 1,000 feet, the missiles would threaten the high-flying, unarmed Navy E2C Hawkeye aircraft based on the Coral Sea and another carrier, the USS Saratoga. These planes stay high so their radars can see for hundreds of miles around.

On Monday, two Libyan MiG25 fighter planes intercepted an E2C as it flew over the Gulf of Sidra but took no hostile action before breaking off, U.S. officials said. The Coral Sea launched F/A18s but no confrontation occurred, they added.