How to Set or Change IP Addresses, Gateways, Subnet Masks, and DNS Servers Remotely in Windows

Printer-friendly versionPDF version

If you are a systems administrator, there will probably be a time when you will need to change a users IP adddress, gateway, subnet mask, or DNS servers without actually logging into their computer. This method requires no end user interaction and is designed to work in a domain environment. We will be using two tools in this example: Netsh and PsExec (part of PsTools).

Download PsTools and extract it to C:\pstools on your system. Then open a command prompt and change to that directory:

cd C:\pstools

PsExec is a light-weight telnet replacement that lets you execute processes on remote systems. You can use IP addresses or hostnames with PsExec. To launch an interactive command prompt on a remote computer, run the following command (you should run theses commands as domain admin):

psexec.exe \\ip_or_hostname cmd

If you are unable to connect to the remote system, it may have something to do with a firewall or antivirus on the remote system. You can check here for tips on how to connect.

Now that you have an interactive command prompt open on the remote system, we will be using the netsh command to change all the IP info. To find the name of the interface you would like to change, run this command:

netsh interface ip show config

Here are the commands to set or change an IP address, gateway, subnet mask, and DNS servers:

Set IP address, gateway, and subnet mask statically:

 

netsh interface ip set address name="Local Area Connection" static 192.168.1.34 255.255.255.0 192.168.1.254 1

Set IP address, gateway, and subnet mask to be received by DHCP (This will attempt to renew the IP info immediately after running this command):

netsh interface ip set address name="Local Area Connection" source=dhcp

To set a primary DNS server (if there are multiple DNS servers set prior, this will remove them):

netsh interface ip set dns "Local Area Connection" static 4.2.2.1

To set a secondary or additional DNS server:

netsh interface ip add dns "Local Area Connection" 8.8.8.8

To set the DNS servers to be received by DHCP (This will attempt to renew the DNS info immediately after running this command):

netsh interface ip set dns "Local Area Connection" source=dhcp

Hope this helps some of you. If you have any questions, feel free to leave a comment.

 

I want to connect to remoste PCs, a host and a client, through the DNS IP/server, example, I'm running an OpenVPN server in PC A with address: 192.168.100.2 port 53, AND, I want to connect there using the DNS of my local connection. How Can I do that with netsh?

I don't understand what you are asking. Could you rephrase it in easy to follow format? If you simply want to open an interactive command prompt on a remote system, you can do that with psexec.

Hi,

I am trying to change a DNS server and add a secondary dns server to multiple computers, how can I do this using the above to run on multiple servers and to also output a log file listing each server name and either a yes or no if it has worked or not.

Thanks

You could use psexec with a list of hostnames, like this:

psexec.exe @C:\host-list.txt netsh interface ip set dns "Local Area Connection" static 4.2.2.1

Is there a way to change just the mask without entering the rest of the IP values? Hundreds of windows 2008 r2 servers we need to update.

Just what I needed.
Thanks !!

Thanks for the info, worked great!

Can this be used for static ip address assignments as well? I noticed you mentioned "dhcp" above.

Depending on how you're connected to the Internet, you may have to reset different device.

This works great with 1 exception. The pc needs to be rebooted afterwards. Is there a way to throw the reboot command at the end of this code?

C:\pstools>psexec \\10.52.116.12 netsh interface ip set address name="Local Area Connection 4" static 10.52.124.12 255.255.252.0 10.52.124.1 1

Shouldn't have to reboot for this, but if you need to, you can use psexec to reboot a remote computer also:

psexec.exe \\REMOTEPC shutdown -t 0 -r -f

Post new comment