Change DNS to Automatic DNS using script

8,542

DNS configuration can be changed to dynamic with netsh command line tool. Run this command as administrator:

netsh interface ip set dnsservers name="Ethernet" source=dhcp

the source=dhcp option changes DNS source to be set dynamically. Here details from netsh interface ip set dnsservers help command:

source - One of the following values:
       dhcp: Sets DHCP as the source for configuring DNS servers for the specific interface.
       static: Sets the source for configuring DNS servers to local static configuration.

Also you can revert DNS server from dynamic to static i.e. change DNS to a specific IP address (e.g. 10.0.0.1) using this command:

netsh interface ip set dnsservers "Ethernet" static 10.0.0.1 primary

Change the name=Ehternet option with the name of your default network interface name.

Further reading:

Share:
8,542

Related videos on Youtube

Swaglord1008
Author by

Swaglord1008

Updated on September 18, 2022

Comments

  • Swaglord1008
    Swaglord1008 over 1 year

    My computer has PureVPN which changes the DNS address every time I use this. This renders me unable to connect to the internet on my home and organizational networks, as they both use their own DNS servers. Is there a batch script that just automatically changes the IPv4 DNS settings to 'get automatically'? Because then I can just put it on my desktop and run it whenever it doesn't work. Thanks!