Wednesday, February 26, 2025

Script otomatis buat reset DNS di ubuntu 22.0.4

 If FortiClient forces its DNS every time you connect, you can create a script that resets the DNS automatically after the VPN starts.

  1. Open the NetworkManager dispatcher directory:
    bash
    sudo nano /etc/NetworkManager/dispatcher.d/99-reset-dns
  2. Add the following script:
    bash
    #!/bin/bash if [ "$2" = "up" ]; then nmcli con mod "WiFi-Connection-1" ipv4.dns "8.8.8.8 8.8.4.4" nmcli con up "WiFi-Connection-1" fi
  3. Save the file (CTRL + X, then Y and Enter).
  4. Make it executable:
    bash
    sudo chmod +x /etc/NetworkManager/dispatcher.d/99-reset-dns
  5. Restart NetworkManager:
    bash
    sudo systemctl restart NetworkManager

Now, every time you connect, this script will automatically override FortiClient’s DNS settings.

After making these changes, run:

bash
nmcli con show "WiFi-Connection-1" | grep ipv4.dns

and

bash
cat /etc/resolv.conf

to make sure your DNS settings are correctly applied.


Try:

bash
nslookup google.com

or

bash
ping -c 4 google.com

to confirm if DNS is working.