Depending on the level of the party versus the dragon, it is probably appropriate for the party to 'gang up' on the party however I understand that what you don't want is for the party to mob the dragon, taking it down too quickly and leading to an unsatisfying encounter.
Based on this, there are a number of tactics that you can utilise to make sure the encounter is challenging.
Flying and Breath Weapon
One of the great strengths of dragons is their fly speed. Keeping the dragon in the air while its breath weapon recharges and then hitting the party with fly-by attacks will make it hard for the party to swarm the dragon. Remember that the dragon is a highly intelligent enemy, they will keep to the air if they see an advantage in it.
Lair Actions
If you have an Adult or Ancient dragon then they will have lair actions.
If the players are fighting a dragon in their layer (something the dragon will want to arrange) then there are a number of lair actions that they can use to increase the challenge for players.
The key ones here to avoid being mobbed will be using effects which restrict the movement of your players (e.g the green dragon’s grasping roots, which can restrain them) or which debilitate them in another way (e.g. the green dragon's enchanting fog)
Frightening Presence
Again, if you have an Adult or Ancient dragon then they will have the Frightening Presence action where each creature of the dragon's choice that is within 120 feet of the dragon and aware of it must succeed on a DC 16 Wisdom saving throw or become Frightened for 1 minute.
This can effectively take players or NPCs out of the fight until they can make their save and will do a great job of thinning the party.
Legendary Actions
The legendary actions of Adult and Ancient dragons offer more options for the dragon to deal damage between its turns. The key action here to avoid being mobbed by the PCs is the Wing Attack action:
Wing Attack (Costs 2 Actions). The dragon beats its wings. Each creature within 10 feet of the dragon must succeed on a DC 22 Dexterity saving throw or take 15 (2d6 + 8) bludgeoning damage and be knocked prone. The dragon can then fly up to half its flying speed.
This allows the dragon to hit all nearby enemies and escape from tricky situations and as a Legendary Action it can be done at the end of a players turn.
Legendary Resistance
The final tool in an Adult or Ancient Dragon's arsenal is that the have 3 Legendary Resistances, allowing them to automatically succeed on a failed save.
These should be saved to protect the dragon from any effects which would effectively take them out of the battle. Don't waste these to just reduce the damage to the dragon, unless the damage would mean the dragon dies!
Useful Reading
For further information, I would recommend this set of articles for tactics on how to play a dragon effectively: Dragon Tactics, Part 1.