About 30 miles from the city of Irbil, Gwer offers a glimpse into how the fighting has intensified the ethnic divide in some communities. The town was a diverse community of roughly 10,000 before Islamic State gunmen seized it on Aug. 7. Arabs and Kurds had lived side by side despite tensions that lurked beneath the surface.
Now the desolate landscape of shuttered shops and toppled power lines is a military and ethnic fault line.
On Sunday, a battle between the Kurdish forces and Islamic State militants lasted for 24 hours, making it the longest continuous gunfight since Kurds took back Gwer earlier this month.
"The battle isn't over. They could attack us at any time," a Kurdish commander in Gwer who gave his name only as Maj. Barqi, said on Sunday.
As he spoke, his unit cranked out round after round of heavy-machine-gun fire from the single mounted weapon they use to defend the district, along with a handful of aging assault rifles. "It's like we are fighting a state," he said of the Sunni extremists just a mile away, who lobbed mortars at his troops in return. "A state with a very strong army."
The Islamic State militants seized the northern city of Mosul and a broad swath of northern and western Iraq in June, and followed up two months later by moving on Kurdish-controlled territory, threatening the capital of their semiautonomous zone, Irbil. That prompted the U.S. military to launch airstrikes and help push the militants back.
The U.S. government and several European nations have since pledged to arm the Kurds, but most of the weapons have yet to arrive. The Kurdish troops, known as pesh merga, are worried they don't have enough arms to keep the militants at bay.
But simmering ethnic discord between Arabs and Kurds, long an issue in northern Iraq, is also feeding the unrest in places like Gwer.
Over decades, a succession of Arab regimes in Baghdad repopulated Kurdish areas in the north with Arab families from elsewhere in the country.
When the Kurds gained more autonomy with the 2003 downfall of Saddam Hussein, they encouraged their brethren to return to those areas - but at the expense of Arab residents who in some cases were pushed out.
Now these rifts "will be hardened by the conflict," said Wladimir van Wilgenburg, an Irbil-based expert in Kurdish politics at the Jamestown Foundation, a think tank in Washington. "Of course, if there were these tensions before, it just makes the divisions stronger."
In recent weeks, many Sunnis across Iraq did pledge allegiance to the Islamic State, either out of support for their goal of an Islamic caliphate or because of long-standing grievances against the Shiite-led government in Baghdad. The national government led by outgoing Prime Minister Nouri al-Maliki, a Shiite politician, had grown increasingly sectarian, oppressing and angering Iraq's Sunni tribes.
But some displaced Sunni Arabs did not aid the Islamic State fighters and worry that their exile will be permanent.
Raed Ibrahim Abdullah is a resident of Gwer but now lives in a tent on the militant-ruled front line. He said he was not a supporter of Islamic State.
"I don't want electricity; I don't want water," he said in a telephone interview. "I just want to go home."
Just south of Gwer, in the mixed town of Makhmour, Kurdish residents claim their Arab neighbors either aided or joined Islamic State extremists when they took the town this month.
"My good friend, he disappeared after da'ash arrived to Mosul in June," said a Kurdish resident, Soran Saber, using an Arabic nickname for the Islamic State.
"Then we found him dead with their fighters in Makhmour," when Kurds reclaimed the town, he said. "I was glad to see him dead," he added. "He betrayed us."
Pesh merga fighters now have a tenuous hold on Makhmour, and some Kurdish families have returned.
The Arab residents, they say, fled to the militant-controlled villages on its outskirts. But, as in Gwer, Kurdish authorities have also prohibited Sunni Arab families from coming back.
"They can't return. This is Kurdish territory now," said another pesh merga commander in Makhmour, Sgt. Sitar Qahar Ibrahim.
The Kurds are fighting a fierce battle with Sunni militants just three miles from the edge of Makhmour.
Sgt. Muzaffer Khailani, a pesh merga fighter outside Makhmour, said his unit had entered the neighboring town of Baqart earlier in the week but was ambushed by Islamic State fighters.
"They fired mortars at us. We had to withdraw," Khailani said.
Part of the group retreated to a checkpoint in Makhmour, he said, but that still comes under fire from militants.
"It's in our hands now," Khailani said of Makhmour. "But nobody knows when it might fall into their hands again."