Sunday, 23 October 2016

How to Change Your Computer’s IP Address From the Command Prompt ?

How to Change Your Computer’s IP Address From the Command Prompt ?


It’s easy enough to change an IP address on your PC using Control Panel, but did you know you can also do it from the Command Prompt?


Changing your IP address with the Control Panel interface isn’t difficult, but it does require clicking through a number of different windows and dialog boxes. If you’re a fan of the Command Prompt, though, you can get it done more quickly using the netsh command, which is just one of the great network utilities built into Windows.

The netsh command allows you to configure just about any aspect of your network connections in Windows. To work with it, you’ll need to open Command Prompt with administrative privileges. In Windows 10 or 8.1, right-click the Start menu (or press Windows+X on your keyboard) and choose “Command Prompt (Admin).” In previous versions of Windows, search Start for “command prompt” and then right-click the result and choose “Run as Administrator.”

View Your Network Information

Before you change your IP address and related information, you’ll need to find the full name of the network for the interface you want to change. To do this, type the following command:


netsh interface ipv4 show config


Scroll down until you see the interface you’re looking for. In our example, we’re going to modify the Wi-Fi interface, which on our machine is just named “Wi-Fi.” You’ll also see other default names that Windows assigns to interfaces, such as “Local Area Connection,” “Local Area Connection* 2,” and “Ethernet.” Just find the one you’re looking for and make note of the exact name. You can also copy and paste the name to Notepad and then back into Command Prompt later to make things easier.

Change Your IP Address, Subnet Mask, and Default Gateway

With the interface name in hand, you’re ready to change the IP Address, subnet mask, and gateway. To do this, you’ll issue a command using the following syntax:

4 set address name="YOUR INTERFACE NAME" static IP_ADDRESS SUBNET_MASK GATEWAY

So, for example, your command might look something like the following:
netsh interface ipv4 set address name="Wi-Fi" static 192.168.3.8 255.255.255.0 192.168.3.1

where the info is replaced by whatever you want to use. In our example, the command does the following:

Uses the interface name “Wi-Fi”

Sets the IP address to 192.168.3.1

Sets the subnet mask to 255.255.255.0

Sets the default gateway to 192.168.3.1

And if you’re using a static IP address but want to switch to using an IP address assigned automatically by a DHCP server–such as your router–you can use the following command instead:

netsh interface ip4 set address name=”YOUR INTERFACE NAME” source=dhcp


Change Your DNS Settings

You can also use the netsh command to change the DNS servers used by a network interface. Third-party DNS servers–like Google Public DNS and OpenDNS–can be faster and more reliable than the DNS servers provided by your ISP. Whatever your reason for changing your DNS server, you can do it either at the router so it affects all the devices that get their information from the router or at the individual device. If you want to change the DNS servers for just one PC, it’s easy to do with the netsh command.

You’ll need to use the command twice: once to set your primary DNS server and once to set your secondary, or backup, DNS server. To set your primary DNS server, use the following syntax:

netsh interface ipv4 set dns name="YOUR INTERFACE NAME" static DNS_SERVER

So, for example, your command might look something like the following (in which we set it to Google’s primary public DNS server, 8.8.8.8):

netsh interface ipv4 set dns name="Wi-Fi" static 8.8.8.8

To set your secondary DNS server, you’ll use a very similar command:

netsh interface ipv4 set dns name="YOUR INTERFACE NAME" static DNS_SERVER index=2

So, continuing our example, you might set your secondary DNS as the Google Public DNS secondary server, which is 8.8.4.4:

netsh interface ipv4 set dns name="Wi-Fi" static 8.8.4.4 index=2

And just like with the IP address, you can also change it so that the network interface grabs its DNS settings automatically from a DHCP server instead. Just use the following command:

netsh interface ipv4 set dnsservers name"YOUR INTERFACE NAME" source=dhcp

And there you have it. Whether you like typing at the command prompt better or just want to impress your coworkers, now you know all the command line magic you need for changing your IP address settings.









No comments:

Post a Comment