Skip to content
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

🚫 hostsctl

hostsctl allows you to block advertisements, trackers, and other malicious activity by manipulating /etc/hosts. By taking advantage of curated lists of known bad hosts and providing an interface to easily manipulate host definitions, you can save bandwidth and stay safer online.

How it Works

hostsctl gains flexibility by storing host definitions in different files in the /etc/hostsctl directory. When hostsctl is first run, it will create this directory and initiate the needed files. If /etc/hosts exists, it will be copied to /etc/hostsctl/orig.hosts, ensuring that no existing definitions are lost.

A file containing the list of hosts to be blocked, defined in the configuration, is downloaded and stored at /etc/hostsctl/remote.hosts. Hosts that are explicitly blocked or unblocked via hostctl are stored at /etc/hostsctl/disabled.hosts and /etc/hostsctl/enabled.hosts, respectively. hostsctl operates by merging these separate files together into /etc/hosts.

Note that after using hostsctl, the /etc/hosts file should not be edited directly. Any manual changes will be lost on the next run. Instead, edit the appropriate file in the /etc/hostsctl directory.


Installation can be performed by executing the provided script as root, or by copying bin/ to your path.

$ sudo ./



Bash completions are automatically installed by the script on Arch Linux systems. On other systems, copy the provided hostsctl.bash-completion file to the appropriate directory.


hostsctl is configured via /etc/hostsctl/hostsctl.conf. An example configuration is included, and automatically installed by the script.


This variable defines the source of the blocking hosts file. See below for example URLs.

# Block adware and malware via StevenBlack's host file


This variable defines the IP address that blocked hosts should point at. The default value of is recommended. For a discussion concerning this vs see StevenBlack's host project.

# Route blocked hosts to


The simplest usage is to run hostsctl update. This will download the latest version of the remote hosts file, merge it together with other entries in /etc/hostsctl and output the results to /etc/hosts.

$ sudo hostsctl update

Enabling and Disabling Hosts

hostsctl supports enabling hosts that would otherwise be blocked by the remote hosts file. Note that when a host is accessible, it is considered to be enabled.

$ sudo hostsctl enable # will now resolve correctly

If an unwanted host is not already blocked by the specified remote hosts file, hostctl can also disable it for you.

$ sudo hostsctl disable # now resolves to

To see which hosts are disabled, or to see a list of explicitly enabled hosts, run the appropriate command.

$ hostsctl list-enabled
$ hostsctl list-disabled

Advanced Usage

hostsctl is also able to update the remote hosts file and combine the various host definitions in /etc/hostsctl as separate steps. This may be useful if you wish to view what has changed in the latest version of your remote hosts file before applying those changes.

# Update the remote hosts file
$ sudo hostsctl fetch-updates
# Export the all entries to stdout and compare them against the current /etc/hosts
$ hostsctl export | diff -y --suppress-common-lines /etc/hosts - | less
# After confirming the changes, save them to /etc/hosts
$ sudo hostsctl merge

Similarly, this behaviour allows the host definitions to easily be stored elsewhere.

$ sudo hostsctl fetch-updates && hostsctl export > ~/myhosts

Example Hosts Files

file by
hosts StevenBlack/hosts
hosts AdAway
hosts add.2o7Net
hosts add.Spam
hosts SpotifyAds
hosts UncheckyAds


First try to restore the /etc/hosts file.

$ sudo hostsctl restore

If the problem persist please open new issue on Github.


The original version of this script is available in the original branch.


Any collaboration is welcome!





πŸ™ˆ Control your /etc/hosts file easily, block ads, soical networks, etc...




No packages published