The Department of War was its original name. I’ve always thought it to be a more honest name than the Department of Defence.
Afghanistan is arguable, but it was primarily to prevent terrorism.
The war on Afghanistan was in response to Saudi Arabia attacking the US on 9/11. As Obama’s released documents showed, the US government knew that it was Saudi Arabia, but likely due to business reasons, Bush/Cheney decided to attack other Middle Eastern countries for their oil instead and call it a War on Terror ™.

primarily

Ostensibly.

Well they didn’t go over Afghanistan for the oil.
Opium production in Afghanistan - Wikipedia

Attacks on heroin production were primarily to hit the Taliban’s source of funding. Fentanyl is synthetic, and almost none of the US heroin comes form Afghanistan.

www.bbc.com/news/world-us-canada-47861444

The Afghanistan was really was about terrorism (even though the hijackers were Saudis).

How the US military's opium war in Afghanistan was lost

The US has spent $1.5m a day fighting the opium war in Afghanistan. Why is business still booming?

Just like people swat beehives to get rid of bees.

We’ve known for quite some time that our adventurism in the Middle East (and elsewhere) is among the biggest drivers of terrorism.

Our troops were guarding opium poppy fields. Then we had the opium epidemic.
Right…“terrorism”. And Iraq had WMD’s too.
Iraq and Afghanistan were very different. I protested against the Iraq war.

it was primarily to prevent terrorism.

Boy do I have a terrific bridge to sell you