How to Set or Change IP Addresses, Gateways, Subnet Masks, and DNS Servers Remotely in Windows
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:
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 220.127.116.11
To set a secondary or additional DNS server:
netsh interface ip add dns "Local Area Connection" 18.104.22.168
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.