You can edit the hosts file using terminal, although I'd not recommend it if you're unsure what you're doing. But doing so you can block outgoing access to specified IP addresses or websites.
If you simply want to stop your mac connecting out, why do you not simply turn off your wifi so you're not connected to the internet?
Alternatively a GUI firewall like Little Snitch would be a better option as it gives you very granular options for blocking incoming/outgoing traffic and is fairly easy to use and set up.