Mastodon offers an option called Limited Federation Mode that disables public access and federation.
Like it says in the documentation: "This mode is intended for private use only, such as in academic institutions or internal company networks, as it effectively creates a data silo, which is contrary to Mastodon’s mission of decentralization."
Another thing to note is that most third-party software does not support Limited Federation Mode. For example, many mobile apps do not work when Limited Federation Mode is enabled.
If you want to enable Limited Federation Mode, please email info@masto.host to request that change in your server configuration.