The Reagan administration has decided to impose an across-the-board trade ban on Iran in response to increasing Iranian hostility toward U.S. interests in the Persian Gulf, U.S. officials said yesterday.

A senior official said President Reagan is poised to sign an order aimed chiefly at preventing imports of oil from Iran and restricting exports of machinery and other supplies. The ban is "nearly total," the official said, although some exports of medical supplies will be allowed for "humanitarian reasons."

"The order imposing the trade ban is on the president's desk and has been signed off on by all his advisers," the official said, adding that it could come any day.

The administration has been under intense congressional pressure to ban at least oil exports from Iran, despite skepticism among many U.S. policy-makers that an oil embargo can be enforced. Both the House and Senate earlier this month voted overwhelmingly in favor of a total ban on Iranian oil imports following reports Iran had become the second-largest supplier of crude oil to the United States last July.

In July, Iran exported 19.6 million barrels of crude oil worth $359 million to the United States, making Iran the second leading foreign supplier of oil to the United States. The report said Iran also was attempting to purchase $40 million of oil field equipment from U.S. companies to replace machinery damaged by Iraqi air attacks. These purchases would be prohibited by the prospective ban.

A senior official who confirmed the pending administration action said congressional pressure was an important element in the decision. He said "it was preferable to take such action by executive order" because it would give the administration "more flexibility" in lifting it if Iran softens its attitude toward the United States and toward United Nations efforts to bring about a cease-fire in the seven-year-old war between Iran and Iraq.

One such sign of a changed Iranian attitude would be acceptance of U.N. Resolution 598, which calls for a cease-fire and a negotiated political settlement to the war.

A trade ban on Iran has been under discussion within the administration for months, and a State Department official explained that Iran's recent missile attacks on a U.S.-flagged ship off Kuwait had hardened the administration's attitude.

"The {Iranian} escalation, that's changed the equation," he said.

Administration officials are particularly anxious to stop the export of "dual purpose" items like ship motors and speedboats that were intended for civilian purposes but have also been used by Iran in attacks on shipping in the Persian Gulf.

Since early spring, an administration interagency group has been debating whether to restrict trade with Iran but until recently was unable to reach agreement. The State and Commerce departments were reportedly the most reluctant to impose an embargo on Iranian imports or U.S. exports, hoping to avert actions that would further complicate U.S. efforts to keep some lines open to the Tehran government.

Officials from both departments have also had their doubts about the practicality of imposing an oil embargo because of the difficulties encountered in the one imposed early last year on Libya. Last May, the General Accounting Office published a report on the administration's economic and trade sanctions on Libya and concluded they had had "minimal" impact.

Secretary of Defense Caspar W. Weinberger nonetheless has been a strong proponent of imposing some sanctions on Iran, particularly an oil embargo. Yesterday, he reiterated his support for a ban on Iranian oil imports in testimony before the Senate Foreign Relations Committee.

An official familar with the State Department's current position said there is no longer opposition there to imposing such a ban after recent Iranian actions against U.S. interests in the gulf.

"State's in favor of it," the official said.