Stunned by allegations that members of the Walker family passed its top secrets to the Soviet Union, the Navy has beefed up its counterespionage and security apparatus.

Last week, Navy Secretary John F. Lehman Jr. bestowed independent flag command status on the Naval Investigative Services (NIS) and significantly extended its powers to prevent the kind of serious espionage allegedly committed by retired Navy officer John A. Walker Jr., his brother, his son and a friend.

NIS had previously been a subsidiary to the office of director of naval intelligence, with a mandate to root out corruption and waste. Its powers were severely limited by a requirement that investigations be approved by a local commanding officer.

Under Lehman's reorganization, NIS will have authority to begin and execute investigations on its own initiative, reporting directly to the chief of naval operations and the secretary of the Navy. It will have three separate directorates, covering its original target area plus counterintelligence and security matters.

Commodore Cathal L. Flynn has been chosen to head NIS, becoming the first Navy SEAL (sea, air and land special forces) to assume a command. He will have a Marine Corps deputy.

NIS gained its autonomy because of the strong recommendation of Pentagon Inspector General Joseph H. Sherick, who had criticized the Navy for a "completely inadequate" investigation of the Grenada gun-smuggling charges involving Vice Adm. Joseph Metcalf III.

Metcalf, who commanded the U.S. invasion of Grenada in October 1983, returned home in a plane carrying 24 captured Soviet-made rifles, despite federal and military rules prohibiting such imports.

Sherick found Metcalf "generally responsible" for the incident but cleared him of specific wrongdoing. But the inspector general was sharply critical of Adm. Wesley L. McDonald, the Atlantic Fleet commander, for failing to direct a full NIS investigation. McDonald was accused of being "remiss" in indicating to NIS that Metcalf was responsible for determining whether an inquiry was needed.

NIS, which was required to obtain McDonald's approval before launching the probe, would be free under Lehman's reorganization to pick and pursue its investigative targets.

McDonald's name has recently come up in a less controversial connection. His three-year tour ends Sept. 30, opening one of the Navy's highest commands. In addition to being fleet commander, he is commander-in-chief of all NATO and U.S. forces in the Atlantic.

McDonald is expected to retire, and, according to Navy scuttlebutt, two men are in the running to be his successor: Vice Adm. James A. (Ace) Lyons Jr., deputy chief of naval operations for plans, policy and operations, and Vice Adm. Carl A.H. Trost, director of Navy program planning.

Both admirals also have been named as likely candidates for Pacific Fleet commander, replacing Adm. Sylvester R. Foley, who is scheduled to retire Oct. 1.

Another major Navy post opened when President Reagan selected Adm. William J. Crowe Jr., Pacific commander, to become chairman of the Joint Chiefs of Staff. Crowe, who commanded Pacific and Indian Ocean forces, replaces Army Gen. John W. Vessey Jr.

Adm. Ronald J. Hays, vice chief of naval operations, is expected to be assigned the command, which is responsible for Army, Navy, Air Force and Marine activities in an area covering about half the globe.