This Bash script automates the process of configuring DNS settings on Linux systems. It allows users to easily change the default DNS servers, install the necessary services, and ensure that the changes persist across reboots. The script is designed to be flexible and compatible with various Linux distributions, providing color-coded log messages for easy interpretation.
Changing DNS settings permanently can improve network performance, enhance security, and provide access to region-restricted or censored content. By setting custom DNS servers, users can bypass DNS hijacking, improve privacy, and mitigate risks associated with DNS-related attacks.
For users in regions with restricted internet access, such as Iran, changing DNS settings is crucial for accessing uncensored content and services. By using alternative DNS providers like Shecan(shecan.ir) or other DNS resolvers, users can circumvent government-imposed restrictions and access services that may be blocked under sanctions.
- Change default DNS settings in
/etc/resolv.conf
. - Install and manage the
resolvconf
service. - Set name servers for
resolvconf
. - Restart services to apply changes.
- Verify and ensure persistence of DNS settings.
To execute the script directly on your server, run the following command:
curl -sL https://raw.githubusercontent.com/Soroosh0098/permanent-dns/main/permanent_dns.sh | sudo bash
To download the script, you can use either curl
or wget
. Run one of the following commands in your terminal:
Using curl
:
curl -o permanent_dns.sh -L https://raw.githubusercontent.com/Soroosh0098/permanent-dns/main/permanent_dns.sh
Using wget
:
wget https://raw.githubusercontent.com/Soroosh0098/permanent-dns/main/permanent_dns.sh -O permanent_dns.sh
-
Make the script executable:
chmod +x permanent_dns.sh
-
Open the script in a text editor such as nano or vim:
nano permanent_dns.sh
-
Locate the
DNS_SERVERS
variable near the beginning of the script and modify it according to your needs. For example, to revert to the initial DNS setup, you can set it to127.0.0.53
. If you want to use custom DNS servers, replace the IP addresses with your desired DNS servers. -
Save the changes and exit the text editor.
-
Run the script with root privileges:
sudo ./permanent_dns.sh
If you need to revert to your initial system DNS setup, follow these steps:
-
Open a terminal on your Linux system.
-
Navigate to the directory where the script is located or download the script again using the instructions provided above.
-
Make the script executable:
chmod +x permanent_dns.sh
-
Open the script in a text editor:
nano permanent_dns.sh
-
Locate the
DNS_SERVERS
variable near the beginning of the script and set it to127.0.0.53
. -
Save the changes and exit the text editor.
-
Run the script with root privileges:
sudo ./permanent_dns.sh
Contributions, bug reports, and suggestions for improvements are welcome! Feel free to open an issue or create a pull request.
This project is licensed under the MIT License.