Skip to content

Instantly share code, notes, and snippets.

@hashfii
Last active August 9, 2024 08:09
Show Gist options
  • Save hashfii/2fb1b6d39d178f35c536f54ca52eee6f to your computer and use it in GitHub Desktop.
Save hashfii/2fb1b6d39d178f35c536f54ca52eee6f to your computer and use it in GitHub Desktop.
#!/bin/bash
# Hapus atribut read-only dari /etc/resolv.conf
sudo chattr -i /etc/resolv.conf
# Dapatkan IP gateway dari interface internet yang dipakai
GATEWAY_IP=$(ip route | grep default | awk '{print $3}')
# Cek apakah GATEWAY_IP berhasil didapatkan
if [ -z "$GATEWAY_IP" ]; then
echo "Tidak dapat menemukan IP gateway."
exit 1
fi
# Hapus semua isi /etc/resolv.conf
sudo bash -c 'echo "" > /etc/resolv.conf'
# Isi file /etc/resolv.conf dengan konfigurasi baru
sudo bash -c "cat <<EOL > /etc/resolv.conf
search google.com
nameserver $GATEWAY_IP
#nameserver 8.8.8.8
nameserver 127.0.0.1
EOL"
# Set atribut read-only kembali ke /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
echo "Konfigurasi /etc/resolv.conf telah diperbarui."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment