Skip to content

Instantly share code, notes, and snippets.

@majidalaeinia
Last active February 5, 2025 11:24
Show Gist options
  • Select an option

  • Save majidalaeinia/fb6faea96c12d4ccf73749608189de89 to your computer and use it in GitHub Desktop.

Select an option

Save majidalaeinia/fb6faea96c12d4ccf73749608189de89 to your computer and use it in GitHub Desktop.
Swap to shecan.ir DNS easier in one command

Usage

Set shecan DNS:

setsh

Set your normal DNS:

setn

Steps

  1. Create a set_shecan.sh file in your /home/majid directory with such content:
#!/bin/bash

# Define the new content
NEW_CONTENT="# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run \"resolvectl status\" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

#nameserver 127.0.0.53
#options edns0 trust-ad
#search .

nameserver 178.22.122.100
nameserver 185.51.200.2"

# Backup the current resolv.conf
sudo cp /etc/resolv.conf /etc/resolv.conf.bak

# Replace the resolv.conf content
echo "$NEW_CONTENT" | sudo tee /etc/resolv.conf > /dev/null

echo "DNS settings updated to SHECAN"
  1. Make the file executable:
sudo chmod +x set_shecan.sh
  1. Create a set_normal.sh file in your /home/majid directory with such content:
#!/bin/bash

# Define the new content
NEW_CONTENT="# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run \"resolvectl status\" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0 trust-ad
search ."

echo "$NEW_CONTENT" | sudo tee /etc/resolv.conf > /dev/null

echo "DNS settings updated to NORMAL"
  1. Make the file executable:
sudo chmod +x set_normal.sh
  1. Make alias for those commands:
sudo vim ~/.zshrc

Add these lines to your aliases:

alias setn="/home/majid/set_normal.sh"
alias setsh="/home/majid/set_shecan.sh"
  1. Update the .zshrc file:
source ~/.zshrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment