Tripoli, Libya - The Libyan Army, headed by General Khalifa Haftar, has edged closer to the small coastal town of Derna, 250km east of Benghazi. It is believed to be preparing for an attack to rid the area of fighters with the Islamic State of Iraq and the Levant (ISIL).

The army's move comes on the back of violent tit-for-tat attacks. The beheadings on a Libyan beach last month of 21 Coptic Christians by a group calling itself the Tripoli Province of the Islamic State was followed one day later by joint Egyptian and Libyan air strikes on Derna, killing seven civilians. Another group calling itself the Barqa Province for the Islamic State retaliated days later in al-Gubba, claiming responsibility for twin suicide blasts that killed 44 people and injured scores more.

Derna is home to the Islamic Youth Shura Council, which was among the first groups in Libya to declare allegiance to ISIL last fall. To mark the occasion, fighters paraded their vehicles through the town's centre in a show of strength. Judges and prosecutors have since been targeted and courts abolished, while the fighters serve up their own interpretation of Islamic law.

RELATED: ISIL claims responsibility for deadly Libya blasts

"Armed militias that control the eastern city of Derna are terrorising residents through summary executions, public floggings, and other violent abuse," Human Rights Watch reported at the time. "The abuses are taking place in the absence of state authorities and the rule of law."

Mohammed, a local government worker who did not provide a last name, told Al Jazeera that the government has a "bad relationship" with the fighters.

Libya: State of insecurity

"Many of them are foreigners, from countries like Tunisia, Algeria, Saudi Arabia, Yemen and Egypt. There is no justice, and they have closed most government offices," he said. "We hate them here."

In addition to ISIL fighters, the al-Qaeda-affiliated Abu Salim Martyrs' Brigade and Ansar al-Sharia - not connected to Ansar al-Sharia in Benghazi, allegedly responsible for the death of US Ambassador Christopher Stephens - have recently formed the Derna Mujahideen Shura Council to fight Haftar's military alliance. The council is also aiming to contain ISIL's expansion.

Last December, US Africa Command (AFRICOM) leader, General David Rodriguez, estimated there were a couple of hundred ISIL training camps in east Libya. "ISIL has begun its efforts over in the east out there to introduce some people over there," he said. "But we'll have to just continue to monitor and watch that carefully in the future to see what happens or whether it grows on unabated."

Today, Libya is bitterly split in two. It has two opposing governments, parliaments, and militias intent on seizing the country's power and assets. Tripoli-based Prime Minister Omar al-Hassi and the General National Congress is allied with the Libya Dawn military coalition. In the east, Prime Minister Abdullah al-Thinni and the House of Representatives are aligned with Haftar's Operation Dignity campaign.

Some of the most well-known intellectuals and fundamentalists were in Derna. Now it is completely under the control of fundamentalists. Local education ministry official

Libya Dawn and Dignity forces are fighting each other in Benghazi, the Sidra basin, the west and the south, severely damaging key infrastructure such as airports and oil installations, and prompting the National Oil Corporation (NOC) to threaten to stop all remaining oil operations.

Derna, with an estimated 100,000 residents, has a famously intellectual and pious history, and is known for its young men fighting abroad. In one infamous roundup in the 1990s, former leader Muammar Gaddafi sent his troops house-to-house to arrest suspected opposition.

"Many of the younger generation of militants in Derna, and in eastern Libya more generally, are the sons and nephews of those who were rounded up, tortured or killed by Gaddafi during his crackdown on Islamists in the 1990s," said Mary Fitzgerald, an analyst and author based in Libya. "[Now] what has happened in Derna is similar to what is happening in Sirte and Benghazi. [ISIL] is peeling away younger militants from other groups because it is seen as increasingly assertive and more powerful than the others."

Many men from Derna were part of the Libyan Islamic Fighting Group (LIFG), who went to Afghanistan to fight the Soviets in the 1980s, and comprised the majority of Libyan fighters in Iraq after the 2003 US invasion.

Following in this tradition, Derna residents flocked to northern Syria in 2011 to fight Bashar al-Assad's regime with their newly formed al-Batter brigade. But when infighting kicked off between the homegrown al-Qaeda affiliate, Jabhat Al-Nusra, and ISIL, some of these same Libyans grew disgusted and started trickling home.

The fall of Gaddafi's regime saw hundreds of Islamists released from places such as the notorious Abu Salim prison. Others returned to Libya from exile abroad, or later, from the fighting in Iraq and Syria.

RELATED: ISIL video shows Christian Egyptians beheaded in Libya

This combination has led to Derna's circumstances today.

"Some of the most well-known intellectuals and fundamentalists were in Derna," a local education ministry official told Al Jazeera on condition of anonymity. "Now it is completely under the control of fundamentalists."

He said ISIL mostly mans the checkpoints leading into town, on the lookout for Libyan army and government personnel allied with Haftar. They are also rationing gasoline and electricity to avoid shortages. In this deeply divisive and fearful atmosphere, women are pressured to wear the niqab, schools have been gender-segregated, tobacco shops have been banned and armed fighters mete out their own brutal justice.

"People are angry. We don't have a government, we don't have security, and we have allowed foreigners to enter our city," the education official said. "But they have the guns. And Daesh [ISIL] are now targeting our youth and giving them guns within their comfort zone."

Amira, a teacher who suffered two months of intense fighting in the hard-hit neighbourhood of Laithi in Benghazi, visited her relatives last month in Derna before leaving Libya. She said she was stopped at an ISIL checkpoint leading into town, but did not notice an armed presence inside the town.

"But most people tell me they are scared," Amira, who did not provide a last name, told Al Jazeera. "They know these fighters have weapons and can kill without feelings. Some families in Derna have escaped because they think the war will come there next, but others don't want to, because they think Daesh will take over their homes. So they go on, and pretend everything is normal."