The last time Hackerfall tried to access this page, it returned a not found error. A cached version of the page is below, or clickhereto continue anyway

GitHub - 0xl3vi/hostsctl: Control your /etc/hosts file easily, block ads, social networks, and more.

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.d 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.d/10-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.d/30-remote. Hosts that are explicitly blocked or unblocked via hostctl are stored at /etc/hostsctl.d/20-enabled-disabled.

The user is free to include other files in this directory as they see fit. 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.d directory.

Installation

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

Packages

Bash-completions

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

Configuration

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

remote_hosts

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

# Block adware and malware via StevenBlack's host file
remote_hosts='https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts'

ip

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

# Route blocked hosts to 0.0.0.0
ip='0.0.0.0'

Usage

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.d and output the results to /etc/hosts.

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 facebook.com # facebook.com 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 facebook.com # facebook.com now resolves to 0.0.0.0

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.d 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 /etc/hosts -
# After confirming the changes, save them to /etc/hosts
$ hostsctl merge

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

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

Example Hosts Files

Troubleshooting

First try to restore the /etc/hosts file.

If the problem persist please open new issue on Github.

Original

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

Contributing

Any collaboration is welcome!

Thanks

License

Continue reading on github.com