Dial Plan to manage which extenstion can be dialed and which not

Use the commercial COS module to restrict certain extensions to only use certain trunks.

To restrict internal extension to extension calls you can use custom contexts.
There are many threads on this in this forum, such as this one: