How to stop assignment of numbers to hostnames?
This seems like a problem with your router. Try forcing your hostname with scutil:

scutil --set HostName yourhostname


Why the number?

The bracketed numbers appear because the same Bonjour/ZeroConf name is being used multiple times on the network. If Bonjour detects a duplicate name, a number is appended to ensure uniqueness.

This does not indicate a serious problem. Resetting network caches and devices should help clear out the now superseded name.

Apple's Bonjour Frequently Asked Questions page discusses this behaviour:


  12. What should happen when two devices on the network both use the same service name?
  
  In the rare case where a name collision occurs, your device should add
  a digit to the end of the name, for example:
  
  "Apple Mac mini (2)"