The midday sun pinned the Marine sentry's shadow beneath him. He stood guard at the gates of the Quantico Marine Corps Base, stopping outsiders' cars and casually waving on one of the 700 residents who lives in a town hidden inside.

Going through the tightly guarded sentry gates is a rite of passage, the only way to enter the town of Quantico. Past the gates, about two miles down the road, is the only town in the nation surrounded by a military reservation.

It's "Q Town" to the locals and Marines alike. A landlocked, nine-square-block town in the midst of 60,415 acres of the Quantico Marine Corps Base. Here is a town clearly on a bare-bones budget, where merchants seem to have little money for fancy signs or elaborate shop fixtures, and where many residents have been forced to live in deteriorating clapboard apartments. It is a town that relies on one industry--the Marines Corps--for everything from water and sewer service to fire protection.

"Yessir, you take away the Marines and you take away the town," says Quantico barbershop manager Ed King, resting in an empty barber's chair. "This is one of the few towns around that is recession-proof."

In 1917 the Marine Corps bought nearly 6,000 acres from an ailing shipbuilding firm, the Quantico Company. And Quantico Marine Corps Base was born. In those days, the town was a small collection of wooden shacks fronted by dirt roads that turned to knee-deep mud on rainy days.

Times have changed--the streets are paved, more than 50 businesses have replaced the wooden shacks, Washington is now a 45-minute drive up Rte. 1 or I-95--and the problems of the outside world have edged their way past the sentry posts.

Despite its isolation from the civilian world, Quantico has been shaken recently by problems that more often are seen in bigger cities: a bitter political feud, which came to a head in town elections this spring, the second shake-up in two years in the six-man police force, and the ambush and shooting early this month of a Marine guard.

And for the past several years, town leaders have been struggling with one of Quantico's most vexing problems: a severe housing shortage aggravated by a general deterioration of the town's residential areas over the years.

The political feud in Quantico began three years ago with the appointment of Theofilos Giannopoulos, an appliance store owner, as mayor. Almost from the start, Giannopoulos and the five-member Town Council locked horns.

Shortly after his appointment, Giannopoulos called for an outside audit of town financial records, the first in Quantico history. Despite some council opposition, the audit was performed and showed no financial problems.

Another major dispute, which also occurred in Giannopoulos' first year in office, concerned an attempt by the council to appoint Georgia Raftelis, wife of council member Mitchell Raftelis, as town clerk. Giannopoulos, contending the appointment was illegal, sought a ruling from the state attorney general's office, which advised that Georgia Raftelis could not hold the post.

"Always, the council they want me to carry out their orders, even if they were illegal," said Giannopoulos, referring to the Raftelis dispute.

This year, Giannopoulos decided to bow out of politics. "I call it quits," he said, "I get out because I'm getting zero cooperation."

In the May 4 town election Giannopoulos received 29 write-in votes, far short of the 88 cast for the only declared candidate for mayor, restaurant owner Lively C. Abel.

Abel had run for mayor once before, in 1980, when he lost to Giannopoulos by one vote.

"The biggest reason I ran this time," Abel said recently, "is the adverse publicity about this town. Seemed like every little thing that happened was all blown up. Everywhere I went it seemed that people kept asking, 'What's going on down there?' It got kind of embarrassing."

One of those embarrassments has been the town police force. The day before the mayoral election, Giannopoulos suspended the highest-ranking officer on the force, Sgt. Leo Rodriguez, pending Rodriguez's trial on charges of assault and battery. (The trial has been set for June 16.)

The charges stemmed from an incident in April, in which Rodriquez allegedly handcuffed a 15-year-old Woodbridge boy outside a Quantico restaurant. Giannapolous said at the time that Rodriquez, who was off duty, had responded to a report of a domestic dispute at the restaurant. The youth was not charged, and was later released.

Rodriquez's suspension came two years after the Town Council fired his predecessor, Richard A. Gabriel, and refused to rehire him despite a petition for his reinstatement signed by 65 percent of the townspeople. Gabriel later sued the town, seeking reinstatement, but lost the case in Prince William County Circuit Court, a decision he is now appealing.

The two controversies have prompted some residents to call the town sergeant's job "jinxed."

But perhaps the most serious problem Quantico faces is housing. One study predicts that by the year 2000, the population will drop by more than a third--to 464--unless the town is able to deal with its severe housing shortage.

Half the housing in Quantico consists of apartments, according to the town comprehensive plan, squeezed onto three of the town's 34 acres. Moreover, the comprehensive plan last year revealed that 44 percent of the housing was substandard and most was renter-occupied.

Aggravating that shortage are housing problems at the Marine base itself. Thirteen percent of the 1,790 family base housing units--many built before World War II--were classified in 1980 as inadequate, according to the comprehensive plan. "Demand for housing in Quantico comes primarily from the Marine Corps base where adequate housing is in short supply," the plan states.

"All the apartments ought to be condemned," says 22-year-old Kristin Schockmel, who works as a waitress in Quantico. "One building was condemned nine years ago and there are still people living there. I know a girl who is constantly worried about rats in her apartment getting after her child. I felt lucky myself to find a one-bedroom apartment with private bath for $260 a month--most apartments don't have baths around here. They are really rooms."

Two years ago, Quantico was awarded $185,000 in federal funds to rehabilitate low- and moderate-income housing and to demolish deteriorated buildings. Of those funds, $100,000 has gone into rehabilitation loans or grants to owners of apartments and single-family homes. Another $30,000 was earmarked to raze deteriorated buildings. So far, two apartment buildings, three houses and a trailer have been demolished. The other $55,000 was used to rehabilitate a community center and for administrative costs of the program.

"That demolition money is probably the best thing that could have happened to Quantico," says former mayor Giannopoulos. "We want to clean up these eyesores so that investors will come in and build on vacant lots. We have got a real housing need here."

Quantico still has about $18,000 left in demolition money, which which must be spent by July 30 or returned to the federal government. The Town Council has not yet decided how to use the money and is expected to seek a year's extension to avoid losing it.

Despite the town's internal problems, the incident that seemed to strike hardest at the heart of Quantico was the May 1 ambush and shooting of a Marine guard.

The guard, Lance. Cpl. James C. Jaeger, 20, was on duty at a sentry box early the morning of May 1 when he was struck in the chest by shotgun fire.

Within hours after the shooting, the Marine Corps had set up a tight security ring around the base and had called in the FBI, the Naval Investigative Service, Prince William County and Quantico police, state troopers and Stafford County sheriff's deputies.

The next day, Marine Cpl. Carl L. Bendler, 22, stationed at the base, and his brother David L. Bendler, 30, of the town of Quantico, were arrested and charged with attempted murder on a government reservation.

The townspeople's concern over the shooting is not surprising.

"(The Marines) are just like family," says Joyce King, wife of barbership manager Ed King.

The Corps also is the only industry in town.

Oh, there have been occasional disgreements between town residents and the Corps, over issues such as the Marines' random searches of visitors' cars, started last fall in an effort to stem drug traffic (a town resident was inadvertently stopped during the first week).

But for the most part, the 5,800 Marines and their 7,200 dependents are welcome customers in Quantico.

It is difficult to find a business that in some way doesn't cater to the needs of a Marine. What other town of 700 boasts a tattoo parlor, a tailor shop filled with piles of uniforms, a half-dozen dry cleaners specializing in the sharpest of creases, a dozen restaurants and The Marine Shop, where 28 employes are kept busy making sure every customer's measurements are recorded in a computer system.

"The best customers in the world," says Charles Taylor of the Marines. Taylor, a retired Marine master sergeant, owns three businesses in Quantico: the Command Post and Last Chance restaurants, and the Command Post Ltd. Tee-Shirts & Gifts.

The importance of the Corps to the town was illustrated last summer when the Corps banned camouflage combat fatigues except in the field. Business dropped off 20 percent, shopkeepers recall, until Marines understood that the "dress-up" policy also applied on base. Now the Marines are back in town, in their tailored uniforms.

If there is a command center in the business district, it is The Marine Shop, owned, quite naturally, by a retired Marine major, Harry D. Elms. Display cases in the shop are lined with officer-priced trinkets: embossed stationery, gleaming swords, books on service etiquette, portraits of officers in elaborately braided dress uniform. The store is in a Williamsburg-style, two-story brick building that seems more in keeping with Old Town Alexandria than Quantico.

"I've had people asked me, 'Why in the hell did you build a building like this in Quantico?' " Elms says. "Well, I wanted something the Marines could be proud of--a place with a fireplace and a sitting area right by the door, an atmosphere like home."

Despite the steady influx of Marine dollars, Elms and other shopkeepers are aware that Quantico has a long way to go.

"I ask myself why this town didn't mature, and I guess it's because people don't want to spend money on it," Elms said. "I thought when I finished this building in 1979 that others would follow. And there has been some fixing up. It will come, it will come."