How to Use Netsh Interface IP Set Address or DNS in CMD

Published by Nyau Wai Hoe - Updated on

Windows Command Prompt, also known as CMD, is a versatile and powerful tool that can be used to configure and manage network settings. Among its many features is the ability to set IP addresses and DNS settings for your network interfaces using the “netsh” command. In this article, we’ll explore how to use the “netsh interface ip set address” and “netsh interface ip set dns” commands in CMD or PowerShell to configure your network settings in Windows 11 or 10.

Also see: How to Check IP Address in Windows 11

Netsh Interface IP Set Address DNS Windows 11

Introduction to “Netsh Interface IP” command

Netsh, short for “network shell,” is a command-line utility available in Windows operating systems that allows you to configure and manage network settings. It provides a convenient way to interact with Windows networking components, including IP addresses and DNS settings. The netsh interface ip command can be used to manage IP addresses, while netsh interface ip set dns is used for DNS configuration.

Advantages of using command line

While graphical user interfaces are more user-friendly and can be accessed by clicking through the network adapter’s properties, using the command line to configure IP addresses and DNS settings offers several advantages:

  • Speed: Command-line operations are generally faster and more efficient than GUI operations, allowing you to make changes quickly without navigating through multiple windows and dialog boxes.
  • Automation: CMD commands can be scripted, making it easier to automate network configuration tasks and apply settings to multiple computers simultaneously.
  • Remote management: Using command-line tools enables you to remotely manage network settings on other machines within the network.
  • Troubleshooting: The command line provides more detailed output, which can be helpful in diagnosing and resolving network issues.

Pro tip: How to Find The IP Address of a Website in Windows 10 / 11

Setting a Static IP Address using “Netsh interface ip”

Configuring a static IP address can be useful when you need to assign a specific IP address to a device or when setting up a server. Here’s how to set a static IP address using CMD:

Step 1: Open Command Prompt as an administrator

Press Win key to open the Start menu and type cmd or Command Prompt in the search box. Right-click on the Command Prompt result and select Run as administrator from the context menu. You can also use Windows PowerShell to run Netsh commands.

Command Prompt Run as Administrator

Step 2: View the list of network interfaces

Run the following command to display the network interfaces on your computer:

netsh interface ipv4 show interfaces

Identify the network interface you want to configure (e.g., Local Area Connection, Wi-Fi) and note its index number.

Netsh interface ipv4 show interfaces Windows 11

Step 3: Set the static IP address, subnet mask, and gateway

Use the following command template, replacing <index>, <ip_address>, <subnet_mask>, and <gateway> with the appropriate values:

netsh interface ipv4 set address name=<index> source=static address=<ip_address> mask=<subnet_mask> gateway=<gateway>

For example, to set the IP address to 192.168.1.10, subnet mask to 255.255.255.0, and gateway to 192.168.1.1 for the interface with index number 3, use the command:

netsh interface ipv4 set address name=3 source=static address=192.168.1.10 mask=255.255.255.0 gateway=192.168.1.1

Netsh interface IP set address CMD

Step 4: Verify the changes

To verify that the static IP address has been successfully applied, run the ipconfig command:

ipconfig

IPConfig to check Netsh interface IP changes

Check the output to confirm that the IP address, subnet mask, and gateway match the values you provided.

Related issue: Windows 11 Ethernet “Unidentified Network” (How to Fix)

Setting a Dynamic IP Address

Dynamic IP addresses are assigned by a DHCP server and can change over time. This configuration is suitable for most home and office networks. Here’s how to configure a network interface to use DHCP:

Step 1: Open Command Prompt as an administrator

Follow the same procedure as mentioned earlier.

Step 2: View the list of network interfaces

Run the netsh interface ipv4 show interfaces command to display the network interfaces and note the index number of the interface you want to configure.

Step 3: Set the network interface to use DHCP

Use the following command template, replacing <index> with the appropriate value:

netsh interface ipv4 set address name=<index> source=dhcp

For example, to set the interface with index number 3 to use DHCP, use the command:

netsh interface ipv4 set address name=3 source=dhcp

Netsh Interface IP Set address DHCP CMD

Step 4: Verify the changes

Run the ipconfig command and check the output to ensure that the network interface is now configured to obtain an IP address automatically.

Additional resource: Find MAC Address on Windows 11/10 with or without CMD

Configuring DNS Settings using Netsh

DNS settings determine how your computer translates domain names into IP addresses. Here’s how to configure DNS settings for a network interface using CMD:

See also: Change DNS to Google or Cloudflare in Windows 11/10

Step 1: Open Command Prompt as an administrator

Follow the same procedure as mentioned earlier.

Step 2: View the list of network interfaces

Run the netsh interface ipv4 show interfaces command to display the network interfaces and note the index number of the interface you want to configure.

Step 3: Set the primary DNS server

Use the following command template, replacing <index> and <primary_dns> with the appropriate values:

netsh interface ipv4 set dns name=<index> static <primary_dns> primary

For example, to set the primary DNS server to 8.8.8.8 for the interface with index number 3, use the command:

netsh interface ipv4 set dns name=3 static 8.8.8.8 primary

Netsh interface IP set DNS using Command Prompt

Step 4: Set a secondary DNS server (optional)

To set a secondary DNS server, use the following command template, replacing <index> and <secondary_dns> with the appropriate values:

netsh interface ipv4 add dns name=<index> addr=<secondary_dns> index=2

For example, to set the secondary DNS server to 8.8.4.4 for the interface with index number 3, use the command:

netsh interface ipv4 add dns name=3 addr=8.8.4.4 index=2

Step 5: Verify the changes

Run the ipconfig /all command and check the output to ensure that the DNS servers are set correctly for the specified network interface.

Netsh interface IP set DNS to Google

Resetting DNS Settings to Default

To restore the default DNS settings, which allows your computer to obtain DNS server addresses automatically, follow these steps:

Step 1: Open Command Prompt as an administrator

Follow the same procedure as mentioned earlier.

Step 2: View the list of network interfaces

Run the netsh interface ipv4 show interfaces command to display the network interfaces and note the index number of the interface you want to reset.

Step 3: Reset the DNS settings

Use the following command template, replacing <index> with the appropriate value:

netsh interface ipv4 set dns name=<index> source=dhcp

For example, to reset the DNS settings for the interface with index number 3, use the command:

netsh interface ipv4 set dns name=3 source=dhcp

Restore DNS to default using Netsh in CMD Windows 11

Step 4: Verify the changes

Run the ipconfig /all command and check the output to ensure that the network interface is now configured to obtain DNS server addresses automatically.

Summary

In this article, we’ve covered how to use the “netsh interface ip set address” and “netsh interface ip set dns” commands in Command Prompt to change the IP addresses and DNS settings for your network interfaces in Windows 11/10. With these commands, you can easily manage your network settings and troubleshoot connectivity issues, while taking advantage of the speed, automation, and remote management capabilities offered by the command line.


Nyau Wai Hoe
Nyau Wai Hoe is the Founder and Chief Editor of WindowsDigitals.com. With a degree in software engineering and over 12 years of experience in the tech support industry, Nyau has established himself as an expert in the field, with a primary focus on the Microsoft Windows operating system. As a tech enthusiast, he loves exploring new technologies and leveraging them to solve real-life problems.

Share via
Copy link