Skip to content

Commit

Permalink
fix: dns server
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Nov 27, 2023
1 parent 9ea42a6 commit 589f6e3
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
57 changes: 57 additions & 0 deletions common/change_dns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
import os
import sys
import yaml

# Check if the script is run with sudo privileges
if os.geteuid() != 0:
print("Please run this script with sudo or as root.")
sys.exit(1)

# Check for the correct number of arguments
if len(sys.argv) != 3:
print("Usage: {} <dns_server_1> <dns_server_2>".format(sys.argv[0]))
sys.exit(1)

dns_server_1 = sys.argv[1]
dns_server_2 = sys.argv[2]

# Function to update DNS settings in a Netplan configuration file


def update_dns_settings(config_file):
with open(config_file, 'r') as f:
data = yaml.safe_load(f)

for interface, config in data['network'].get('ethernets', {}).items():
if config.get('dhcp4', False):
# DHCP configuration
if 'nameservers' not in config:
config['nameservers'] = {}
config['nameservers']['addresses'] = [dns_server_1, dns_server_2]
elif 'addresses' in config:
# Static IP configuration
if 'nameservers' not in config:
config['nameservers'] = {}
config['nameservers']['addresses'] = [dns_server_1, dns_server_2]
else:
print("WTF")
with open(config_file, 'w') as f:
yaml.dump(data, f)
print(data)
print("DNS servers updated in", config_file)


# Iterate through all Netplan configurations
for config_file in os.listdir('/etc/netplan'):
if config_file.endswith('.yaml') or config_file.endswith('.yml'):
config_file = os.path.join('/etc/netplan', config_file)
update_dns_settings(config_file)

# Apply the changes
os.system('netplan apply')

# Restart systemd-resolved to apply changes
os.system('systemctl start systemd-resolved')

print(f"DNS servers set to {dns_server_1} and {dns_server_2}")
12 changes: 5 additions & 7 deletions common/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source utils.sh

remove_package apache2 needrestart needrestart-session
install_package at whiptail apt-transport-https dnsutils ca-certificates git curl wget gnupg-agent software-properties-common iptables locales lsof cron libssl-dev curl gnupg2 ca-certificates lsb-release ubuntu-keyring resolvconf less jq qrencode resolvconf
python3 -m pip config set global.index-url https://pypi.org/simple

if [[ $COUNTRY == 'cn' ]]; then
sudo timedatectl set-timezone Asia/Shanghai
Expand All @@ -12,22 +13,19 @@ else
sudo timedatectl set-timezone Asia/Tehran
fi

sudo systemctl stop --now systemd-resolved.service
sudo systemctl disable --now systemd-resolved.service
sudo systemctl mask --now systemd-resolved.service
rm /run/resolvconf/interface/*
# rm /run/resolvconf/interface/*
echo "nameserver 8.8.8.8" >/etc/resolv.conf
echo "nameserver 1.1.1.1" >>/etc/resolv.conf
echo "nameserver 8.8.8.8" >/etc/resolvconf/resolv.conf.d/base
echo "nameserver 1.1.1.1" >>/etc/resolvconf/resolv.conf.d/base
sudo systemctl restart systemd-networkd >/dev/null 2>&1
sudo systemctl restart NetworkManager >/dev/null 2>&1
resolvconf -u
sudo systemctl unmask --now systemd-resolved.service
systemctl enable --now systemd-resolved >/dev/null 2>&1
python3 change_dns.py 8.8.8.8 1.1.1.1

ln -sf $(pwd)/sysctl.conf /etc/sysctl.d/ss-opt.conf

sysctl --system
python3 -m pip config set global.index-url https://pypi.org/simple

if [[ "$ONLY_IPV4" != true ]]; then
sysctl -w net.ipv6.conf.all.disable_ipv6=0
Expand Down
2 changes: 1 addition & 1 deletion hiddify-panel/src
Submodule src updated from 6211a9 to 047f9b

0 comments on commit 589f6e3

Please sign in to comment.