Navy frigates, cruisers and destroyers all are equipped with naval rifles, also referred to as "guns." "Guns" are what the Army and landlubbers refer to as "cannons." Since the retirement of the last of the WW2 8" gun cruisers in the 1970s, and until the introduction of the Perry Class FFGs, FFs, DDs and CGs all carried 5" guns. Now FFGs have 76mm guns and 5" guns are on DDGs and CGs.
Those guns are "dual-purpose" guns, which means that they can shoot at targets both on the sea and in the air. Dual-purpose guns were developed after WWI when it became clear that ships might need to shoot at airplanes. That avoided having to add large guns solely for anti-aircraft uses, which helped to reduce the growth in topside weight. The more weight added above the main deck (actually, above the center of gravity), the less stable a ship is.
Besides shooting at other ships and at airplanes and now missiles, the guns are also used to provide supporting fire to Marines on the beach. That is the naval gunfire support mission, or "NGFS."
NGFS is primarily indirect fire, in that the ship does not spot and direct its own fire. Naval gunfire spotters do that and they were often naval officers (but not always). Being sent to duty as a gunfire spotter, at least in the post-Vietnam peacetime era, was a clear sign that one had royallly screwed the pooch, that one's career was over. Back then, the Navy was not going to send an up-and-coming young surface warfare officer to go play with the Marines and live in the dirt and eat bugs. But if you were a fuckup and you were either too dumb or too stubborn to submit your resignation towards the end of your first sea tour, off you went to play jarhead.
So let's think about how you actually do spotting. If you are the observer, what you have is a land map, a compass, a pair of binoculars and a radio. You would radio the ship, give your grid position (it was in your best interests to be particularly accurate), give the range and magnetic bearing to the target, describe the target, tell the ship what type of shell to fire and then tell them when to shoot.
So it would be something like "Ship, observer target line zero-six-six, range one two zero zero, target: trucks in open, VT frag, over.". The radio talker in the ship's Combat Information Center would read that back to the spotter. If it was correct, the spotter would say: "Fire when ready." The NGFS team in CIC would plot the observer's position and determine the range and bearing to the target. The range and bearing would be called down to Gun Plot, read back to CIC, and then a round would be fired. When the round was fired, the R/T talker would call out "Shot" and then, five seconds before impact, would follow that with "splash, out."
The spotter would then call back corrections from his point of view, with all distances in meters: "Left five zero, add two zero zero, fire when ready." That had to be corrected by what probably should have been called a "gunfire plotting board," but which everyone referred to as a "Comanche Board." These were two coaxial bearing rings, each with a clear plexiglas surface inside the ring, so that the inner ring's surface was on top of the outer ring. The surfaces were marked in a grid pattern, with each line representing ten meters. The outer ring would be turned so that its grid were aligned on the observer-target line, the inner ring was turned so that its grid were aligned on the ship-target line. The grids were different color, often black and red. The center point was the aiming spot for that round.
The CIC plotters would plot "left 50, add 200" on the observer grid, note what that correction was on the ship's grid and call that down to Gun Plot for another spotting round. Ideally, the third round would be close enough and then the ship would commence area fire. The two common rounds used were VT frag, against troops, tanks and trucks, and White Phosphorus, against troops. VT frag would not do much damage to tanks, but what it did was force the tank commanders to drop inside and "button up," where it is harder for the tank commanders to see what is going on. You might get really lucky and blast off a radio antenna from a tank, break a tank's tread or smash a vision block.
Until a few years ago, most Atlantic Fleet ships did their NGFS training at Vieques, Puerto Rico. Bloodsworth Island in Chesapeake Bay was also used, but infrequently, due to the prevalence of civilian boats in the Bay. If I remember correctly, it was not permitted to shoot anything other than inert shells at Bloodsworth, while live ordnance was permitted at Vieques. NGFS is no longer done at Vieques, I have no idea where live NGFS training is done, if it is indeed done at all anymore.