Last active
August 9, 2024 08:09
-
-
Save hashfii/2fb1b6d39d178f35c536f54ca52eee6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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