Want to force a domain to point to your machine for debugging, block a site without spiritual counseling, or override DNS for a staging server That is what the hosts file does and it is stubbornly simple and brutally effective
Mistakes here lead to sad networking and mild regret. Make a safe backup so you can undo your ambitions in one command
sudo cp /etc/hosts /etc/hosts.bak
Pick your weapon nano or vim. The file lives in a protected path so use sudo
sudo nano /etc/hosts
In nano press Control O to write and Control X to exit. If you prefer vim then use standard vim save and quit commands
Do not overwrite the real localhost entry unless you enjoy subtle breakage. Add your custom names on new lines and use clearly unique domains for testing like app.localtest or mysite.devtest
Some Ubuntu setups cache DNS or use local resolvers. If your change does not appear try flushing caches or restarting network services
sudo systemd-resolve --flush-caches
sudo systemctl restart NetworkManager
Ping is fast and truthful when it comes to name to IP checks
ping -c 1 example.local
You can also test with a browser or curl for HTTP checks
Backing up the file editing with sudo adding your hostname to IP mappings saving the file and flushing caches will get you where you want to be most of the time. The hosts file is small but mighty for local development and lightweight domain rerouting
Pro tip use test only domains that cannot collide with real public names to avoid accidental chaos
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.