Leading U.S. stock indexes opened largely flat on Wednesday as investors shrugged off concerns about an escalation in hostilities between the U.S. and Iran.

The S&P 500, Dow and Nasdaq all rose after the U.S. markets opened on Wednesday morning, reversing a sharp decline during overnight trading following an Iranian missile attack on two military bases in Iraq that house U.S troops.

Stocks gained further ground after President Donald Trump addressed the nation, with the Dow adding 178 points, or 0.6%, to 28,762, and the S&P 500 and Nasdaq both gaining more than 0.6%.

Get Breaking News Delivered to Your Inbox

Investors have been on edge since a surprise U.S. airstrike last week that killed leading Iranian general Qassem Soleimani. But with no reported U.S. casualties in the hours following the Iranian attack on Tuesday, "expectations for a de-escalation have risen sharply," TD Securities analysts told investors in a research note.

U.S. Department of Defense officials said Iran fired more than a dozen missiles at the bases. Iran's foreign minister described the strike as "proportionate measures in self-defense."

In a tweet after the attack, President Donald Trump said that"All is well!" and that casualty and damage assessments were ongoing, adding "So far, so good!"

Tom Holland, an analyst with investor advisory firm Gavekal Research, noted that global oil prices surged immediately after the Iranian missile strike but receded in later hours. Gold — a safe haven when risk flares — also dipped after an initial jump.

"It has been clear in recent days that Iran had to retaliate in some form for Soleimani's killing, if only for domestic political reasons. So Wednesday's missile strikes were no surprise," he said in a note to clients. "However, by the standard of the bloodcurdling threats from Tehran, the retaliation so far has been relatively moderate."

Investors historically have largely ignored geopolitical turmoil. An analysis by brokerage firm LPL Financial found the Dow fell an average of only 2% during 16 recent major conflicts, including the 1990 Gulf war, the 2003 Iraq war and the September 11 attacks, and then usually rose in subsequent months.

That trend suggests investors are more likely to focus on factors including the solid U.S. economic growth of late and what looks like an easing of trade tensions between the U.S. and China.

One set of publicly listed companies that are benefiting from U.S.-Iran tensions: defense stocks. Shares of major defense industry players such as General Dynamics, Lockheed Martin and Northrop Grumman have risen an average of 6% this year as the conflict has heated up, according to UBS.

The market's mild reaction to flaring tension in the Middle East could change quickly if the U.S.-Iran conflict escalates. A move by the Iranian government to block the Strait of Hormuz, a key supply route for oil tankers, would likely send crude prices soaring into triple digits and dent global economic growth, analysts warn.

Airlines skirt Middle East

Caution prevailed at many commercial airlines Tuesday and Wednesday as the companies rerouted flights throughout the Middle East to avoid potential danger during the heightened tensions between the U.S. and Iran and the latter's factions in Iraq and Syria, among other places in the region.

The jumbled schedules could effect as many as 15,000 passengers per day, lengthen flight times by an average of 30 to 90 minutes, and severely bruise the bottom line for airlines, industry analysts said.

"In a war situation, the first casualty is always air transport," said Dubai-based aviation consult Mark Martin, pointing to airline bankruptcies during the Persian Gulf and Yugoslav wars.

At least 500 commercial flights travel through Iranian and Iraqi airspace daily, Martin said.

The Associated Press contributed to this report.