Juba (AFP) - Fighting at a UN peacekeeping base sheltering civilians in South Sudan has left at least 18 people dead, the medical charity MSF said on Thursday.

Two of the fatalities were local staff members who were attacked in their own homes, it said.

"This attack on civilians is outrageous and we demand that armed groups stop these actions," Marcus Bachmann, coordinator of MSF projects in South Sudan, said in a statement.

"People came to the... site looking for protection and this should be a sanctuary respected by all parties."

Earlier, the United Nations reported that violence between ethnic Dinka and Shilluk communities broke out overnight Wednesday at the base, located in the northeast town of Malakal, and continued into the day. It gave a toll of seven dead and 40 injured.

UN Secretary-General Ban Ki-moon condemned the fighting and expressed concerns about the rise of ethnic violence in the more than two-year conflict, according to a statement from his spokesman.

Over 47,700 people live inside the Malakal base, many of whom came from areas where no aid or shelter had been available for months.

It is one of eight UN bases providing a haven since a civil war began in late 2013. The bases, sheltered around 200,000 people, are protected by razor wire and no weapons are allowed in them.

The UN Mission in South Sudan (UNMISS) said "violence involving the use of small arms, machetes and other weapons broke out."

Peacekeepers fired tear gas to break up crowds, it said.

MSF said an initial surge of violence lasted around three hours, forcing around 600 people, mostly women and children, to gather inside the organisation's hospital.

"More casualties are currently arriving," it said.

Resident Jack Nhial, speaking from inside the base, said the assailants "used Kalashnikovs and machine guns... the situation is still tense."

Peacekeepers were now patrolling the base in tanks, he said.

The UN mission has more than 12,000 peacekeepers, with half of them deployed solely to protect the civilians in their bases.

Story continues

Malakal is in government control, but frontlines with rebel areas are close by.

- Conflict and hunger -

South Sudan's civil war erupted in December 2013 when President Salva Kiir accused his former deputy Riek Machar of planning a coup, setting off a cycle of retaliatory killings that have split the poverty-stricken, landlocked country along ethnic lines.

Tens of thousands of people have been killed and over two million forced from their homes, pushing the world's youngest nation to the brink of famine.

Over 2.8 million people -- almost a quarter of the population -- need aid, while in war zone northern areas 40,00 are being starved to death with aid blocked amid violence.

Both the government and rebel sides have been accused of perpetrating ethnic massacres, recruiting and killing children and carrying out widespread rape, torture and forced displacement of populations to "cleanse" areas of their opponents.

Earlier this month Kiir named exiled rebel chief Machar as vice-president, as part of a repeatedly broken August peace deal.

Machar has yet to return to take up the post and fighting continues, with the conflict now involving multiple militia forces driven by local agendas or revenge, who pay little heed to paper peace deals.

The UN has previously said attacks on its bases in South Sudan may constitute a war crime.

In April 2014, gunmen killed at least 48 civilians when they opened fire on terrified civilians inside a UN base in the town of Bor. At least 10 attackers were also killed when UN troops fought back.