First open the hosts file:
sudo vim /etc/hosts
Then add the websites you want to be blocked. Make sure to keep the spacing between the ip and the website you want to be bocked. For it to work also with safari we need to add not noly the ipv4 address but also the ipv6 address.
127.0.0.1 twitter.com
::1/128 twitter.com
127.0.0.1 facebook.com
::1/128 facebook.com
sudo dscacheutil -flushcache