Windows, Windows 10, Windows 7, Windows 8, Windows Server, Windows Vista, Windows XP
- 04.03.2020
- 74 101
- 6
- 28.02.2023
- 92
- 91
- 1
- Содержание статьи
- Описание
- Комментарии к статье ( 6 шт )
- Добавить комментарий
В процессе работы в ОС семейства Windows иногда бывает необходимо изменить IP адрес компьютера не через графический интерфейс, а с помощью пакетного файла (bat) или же с помощью командной строки (cmd). В данной статье мы расскажем о том, как это можно сделать.
Описание
Смена IP адреса компьютера осуществляется с помощью утилиты netsh, которая входит в состав Windows начиная с самых старых версий этой ОС. Чтобы правильно сменить IP адрес, сначала надо выяснить текущую конфигурацию. Сделать это можно в командной строке при помощи команды
netsh interface ip show address
Результат работы этой команды — отображение текущей конфигурации всех сетевых интерфейсов, настроенных в ОС. Из всех, нам необходимо найти и запомнить название того интерфейса, для которого мы хотим поменять адрес. В нашем примере видно, что интерфейс называется Ethernet. Текущий IP адрес 192.168.100.136
, маска подсети 255.255.255.0
, а основной шлюз 192.168.100.1
.
Предположим, что нужно сменить наш IP адрес на 192.168.100.10
, адресация в сети статическая, без использования DHCP, шлюз остается прежним 192.168.100.1, маска тоже не меняется 255.255.255.0
В этом случае, команда, которая должна быть выполнена из пакетного файла или командой строки принимает следующий вид:
netsh interface ip set address name="Ethernet" static 192.168.100.10 255.255.255.0 192.168.100.1
После выполнения этой команды у интерфейса Ethernet сменится IP адрес на 192.168.100.10
, как на скриншоте ниже.
В том случае, если вы укажите неверное название интерфейса, то получите ошибку следующего содержания: «Синтаксическая ошибка в имени файла, имени папки или метке тома.«. Проверьте внимательно, что нигде не ошиблись при написании.
Также вы можете столкнуться со следующей ошибкой: «Для запрошенной операции требуется повышение прав (запустите с правами администратора)«. Как видно из текста ошибки, необходимо запустить командную строку (или bat-файл) с правами администратора, как это сделать на разных версиях Windows, можно прочитать в этой статье.
Команда netsh предоставляет широкие возможности по управлению сетевыми настройками из командной строки. Для ознакомления с другими ее функциональными возможностями пользуйтесь справкой при помощи netsh /?
Любой системный администратор сталкивается с настройкой сетевых интерфейсов. Большинство для этой цели используют графический интерфейс Windows, что не всегда удобно. В этой статье я расскажу, как настроить сеть с помошью интерфейса командной строки cmd, используя встроенную утилиту netsh.
В операционных системах Windows есть специальная утилита netsh для настройки сетевого адаптера из командной строки cmd.
netsh.exe (network shell) — сетевая оболочка (программа) для ОС Windows, которая позволяет настраивать сетевые параметры, в том числе и удаленно. Данная утилита доступна на всех версиях Windows, начиная с Windows 2000.
Запуск командной строки:
Пуск —> Выполнить —> в строку вводим cmd.exe
Откроется черное окно с мигающим курсором. Тут мы и будем вводить перечисленные ниже команды (ну это для тех, кто никогда не работал с командной строкой).
Конфигурирование сетевых параметров (ip-адреса, сетевой маски и шлюза)
Уснановка ip-адреса, маски и шлюза.
netsh interface ip set address name="Local Area Connection" static 192.168.1.15 255.255.255.0 192.168.1.1
где
Local Area Connection — название вашего сетевого интерфейса.
192.168.1.15 — сетевой адрес (ip address).
255.255.255.0 — сетевая маска (network mask).
192.168.1.1 — шлюз (default gateway).
Установка дополнительного ip-адреса.
netsh interface ip add address name="Local Area Connection" 192.168.1.20 255.255.255.0
Включение автоматического получения ip-адреса, сетевой маски и шлюза от DHCP-сервера.
netsh interface ip set address "Local Area Connection" dhcp
Конфигурирование DNS и WINS серверов
Добавить предпочитаемый DNS сервер.
netsh interface ip set dns "Local Area Connection" static 8.8.8.8
Добавить альтернативный DNS сервер.
netsh interface ip add dns "Local Area Connection" 8.8.4.4
Добавить 3-й DNS сервер.
netsh interface ip add dns "Local Area Connection" 192.168.1.30 index=3
Установка автоматического получения предпочитаемого и альтернативного dns-сервера от DHCP-сервера.
netsh interface ip set dns "Local Area Connection" dhcp
Установка WINS.
netsh interface ip set wins "Local Area Connection" static 192.168.1.240
Включение и отключение сетевых интерфейсов
Отключение интерфеса
netsh interface set interface name="Local Area Connection" admin=DISABLED
Включение интерфеса
netsh interface set interface name="Local Area Connection" admin=ENABLED
Просмотр сетевых настроек
Расширеный вывод конфигурации сетевых интерфейсов.
netsh interface ip show config
Просмотр состояния интерфейсов (connected/disconnected).
C:\Windows\System32>netsh interface ip show interface Инд Мет MTU Состояние Имя --- ---------- ---------- ------------ --------------------------- 1 50 4294967295 connected Loopback Pseudo-Interface 1 12 10 1300 disconnected Local Area Connection
Просмотр таблицы маршрутизации.
netsh interface ip show route
Просмотр конфигурации IP-адресов.
netsh interface ip show addresses
Просмотр адресов DNS-сервера.
netsh interface ip show dnsservers
Просмотр адресов WINS-сервера.
netsh interface ip show winsservers
Сохранение и восстановление конфигурации сетевых интерфейсов
Ну а теперь самое интересное. Поговорим о том, как сохранить сетевые настройки в виде файла конфигурации и восстановить из файла конфигурации. Это может пригодиться тем, кто постоянно меняет сетевые настройки.
Сохранить сетевые настройки в виде файла.
C:\Windows\System32>netsh -c interface dump > C:\my-config.txt
Восстановить сетевые настройки из файла конфигурации.
C:\Windows\System32>netsh -f C:\my-config.txt
Вот и все. Мы рассмотрели далеко не все возможности утилиты Netsh.exe, а лишь самые часто используемые. Используя коммандную строку Windows и утилиту netsh можно намного облегчить себе жизнь.
Windows Command Prompt, or CMD, can be a handy tool for tweaking network settings. It lets you change IP addresses and DNS settings with commands like “netsh interface ip set address” and “netsh interface ip set dns“. This guide will show you how to do just that in Windows 11 or 10 using either CMD or PowerShell.
Also see: How to Check IP Address in Windows 11
Getting to know the “Netsh Interface IP” command
Netsh, or “network shell,” is a command-line tool in Windows that helps you manage network settings. It’s great for working with IP addresses and DNS settings. You can use netsh interface ip
to handle IP addresses and netsh interface ip set dns
for DNS configuration.
Related concern: What is Netsh.exe & its Popup and Crashing issues in Windows 11
Why use the command line?
Although many would argue that it would be more convenient to just adjust things through the GUI available like the network adapter’s properties to configure things like IP addresses and DNS, using command line, particularly the Netsh tool, will give you more freedom and some benefits:
- It’s quick. Commands run faster than navigating through menus.
- Great for automation. You can script these commands to set up many computers at once.
- Handy for remote management. Manage settings on computers across your network from anywhere.
- Helpful for troubleshooting. Get detailed info that can help fix network problems.
Pro tip: How to Find The IP Address of a Website in Windows 10 / 11
How to assign a Static IP Address
Setting a static IP address is useful for devices that need a constant address, like servers. Here’s how to do it with CMD:
First up, open Command Prompt as an admin
Hit the Win
key, search for cmd
or Command Prompt
, right-click the result, and pick Run as administrator
. PowerShell works too.
Next, see your network interfaces
Type this to list them:
netsh interface ipv4 show interfaces
Find the one you’re working with and remember its index number.
Now, set your IP, subnet mask, and gateway
Use this template, swapping in your own values:
netsh interface ipv4 set address name=<index> source=static address=<ip_address> mask=<subnet_mask> gateway=<gateway>
For instance, to assign 192.168.1.10
to interface number 3
, you’d type:
netsh interface ipv4 set address name=3 source=static address=192.168.1.10 mask=255.255.255.0 gateway=192.168.1.1
Lastly, make sure it worked
Type ipconfig
to see if your new settings are listed.
Related issue: Windows 11 Ethernet “Unidentified Network” (How to Fix)
Switching to a Dynamic IP Address
Dynamic IP addresses, given out by a DHCP server, are the go-to for most networks. Here’s how to set one up:
Step 1: Open Command Prompt as an administrator
Just like before.
Step 2: View the list of network interfaces
Run netsh interface ipv4 show interfaces
to see your options and pick one.
Step 3: Switch to DHCP
Here’s the command, don’t forget to use your interface’s index:
netsh interface ipv4 set address name=<index> source=dhcp
For example, for interface 3
, it’s:
netsh interface ipv4 set address name=3 source=dhcp
Step 4: Verify the changes
Run ipconfig
to see if it’s set to get an IP address by itself.
Additional resource: Find MAC Address on Windows 11/10 with or without CMD
Setting up DNS Settings
DNS settings are what turn website names into IP addresses. Here’s how to tweak them:
See also: Change DNS to Google or Cloudflare in Windows 11/10
Step 1: Open Command Prompt as an administrator
As mentioned earlier.
Step 2: View the list of network interfaces
Use netsh interface ipv4 show interfaces
to find the one to configure.
Step 3: Pick a primary DNS server
Replace the placeholders with your actual details:
netsh interface ipv4 set dns name=<index> static <primary_dns> primary
To use 8.8.8.8
as your primary DNS on interface 3
:
netsh interface ipv4 set dns name=3 static 8.8.8.8 primary
Step 4: Add a backup DNS server (if you want)
Here’s how, just change <index>
and <secondary_dns>
to fit your setup:
netsh interface ipv4 add dns name=<index> addr=<secondary_dns> index=2
To set 8.8.4.4
as a backup for interface 3
:
netsh interface ipv4 add dns name=3 addr=8.8.4.4 index=2
Step 5: Double-check everything
Run ipconfig /all
to make sure your DNS settings are spot on.
Going back to default DNS Settings
If you want your DNS settings to go back to automatic, here’s what to do:
Step 1: Open Command Prompt as an administrator
Same process as before.
Step 2: View the list of network interfaces
Check your interfaces again with netsh interface ipv4 show interfaces
.
Step 3: Reset your DNS settings
Here’s how, remember to swap in your interface index:
netsh interface ipv4 set dns name=<index> source=dhcp
To reset interface 3
‘s DNS:
netsh interface ipv4 set dns name=3 source=dhcp
Step 4: Make sure it’s all set
Run ipconfig /all
to see if your computer is back to getting DNS settings on its own.
My two cents
Using the “netsh interface ip set address” and “netsh interface ip set dns” in CMD to adjust IP and DNS settings on Windows is especially useful when you need to manage a big network. If you are looking to automate stuffs like setting IP and DNS for a lot of computers in the network, this will certainly be one of the best ways.
Configuring IP address in a Windows with CMD performed using netsh command line utility. The network shell (netsh) is a set of commands that help you configure any Windows operating system IP address, Network Interfaces, and Windows Firewall. The usage of the command line is for pro level Windows users. Those who are playing the network infrastructure configuration. But using the command line as normal Windows user indicate your expertise to Windows environment. If you are new to Windows command line, this article “configure IP address with command prompt in Windows 10” will help you begin using command line interface.
Configuring Windows IPv4 Networking with Netsh or Network Shell. Netsh is a command-line utility included in Microsoft’s Windows NT line of operating systems beginning with Windows 2000. It allows local or remote configuration of network devices such as the NICs.
Configure IP Address with Command Prompt in Windows 10
Before setting IP address with cmd in Windows 10, you need to know how to find your IP address on Windows 10. So before everything, you must know the network IP address configuration on your system.
Let’s learn the process of IP configuration step by step. I am going to explain it with an easy pictorial guide. If you don’t understand some part, just kindly comment us and ask your questions.
The process of Changing Windows 10 IP Address with Command Prompt:
- Find your IP address in Windows 10.
- View network interfaces card.
- Change IP address on Windows 10.
- Change DNS IP address with the command line.
- Reset IP address with Command Prompt.
How to Find your IP Address on Windows 10?
There are many options for finding IP address on Windows 10. The easy one is “ipconfig” command. To find your IP address on Windows 10, just type “ipconfig” in command prompt. To do this process:
- Press Windows+R keys to open the Run.
- Type “cmd” in the run and press enter.
- Now type “ipconfig” to show the IP address.
The “ipconfig” command shows everything about your computer network interfaces. You might have many physical or virtual network interface card.
Here, I just have one network interface on my Windows 10 computer. The result of ipconfig command shows that the IP 169.254.29.130 with the mask of 255.255.255.0 is my current Windows IP address.
This is a class C “autoconfiguration IPv4”. When your system doesn’t find any DHCP Server or manual IP address, it obtains auto IP address. So let’s change it.
How to Change IP Address with Command Prompt?
For change IP address, open command prompt or PowerShell. Both works the same and you can run all command prompt commends on Powershell as well. Ok, run cmd or Powershell as administrator. Netsh work in both command prompt and Powershell. I’m using Windows Powershell to change IP address on Windows 10 completely. Becuase the user interface and color’s of Powershell is better than Command prompt.
- Type “Powershell” in Windows 10 search box to run Windows Powershell.
- You need to run Powershell as administrator. Just press Windows+Shift the press enter to run Powershell as administrator. Or right-click the Powershell and click Run as administrator.
To find the network interface with the command line, type the following command on Powershell.
Netsh interface ipv4 show interface
The result shows two network interfaces. The Loopback and the Ethernet. The Loopback is Windows builtin network loopback interface, but our pointed network interface is the ethernet.
To find your IP address in Windows 10 with netsh command, just type the following command.
netsh interface ipv4 show config
It displays all the network interface configuration. The output result is clear and better than output result of “ipconfig” command on Command prompt. So to find an exact information of the network interface, just add the index ID of the network interface at the end of the command.
netsh interface ipv4 show config 2
That’s good. Let’s configure and change Windows 10 IP address with the command line. The command is bit long but easy to understand. No need to remember, just try to understand the netsh command structure.
To change the IP address of the “Ethernet0” network interface, type the following command.
netsh interface ipv4 set address name=2 static 200.100.10.5 mask=255.255.255.0 gateway=200.100.10.1
Once the command executed successfully, check the result with “netsh interface ipv4 show config 2” command. Yes, the output result shows the exact IP address has set on the “Ethernet0” network interface. Now the Windows IP address is 200.100.10.5 with the mask of 255.255.255.0 and default gateway is 200.100.10.1.
Note: You can’t change the default gateway separately with the following command. It will remove the IP address and just set the default gateway address.
netsh interface ipv4 set address name=2 gateway= (Gateway IP Address)
That’s good and enough for IP address configuration in Windows 10 with the command line. Let’s change DNS IP address from the command line.
- Related: MCSA Lab Manual Articles.
How to Change DNS IP address from Command Prompt?
DNS IP address is the unique address in the network that resolves computer name to IP address and IP address to the computer name. In the network, finding a computer with a name is easy than 32-bit IPv4 address. To set or change the DNS IP address, just simply do it with the following command.
netsh interface ipv4 set dns name=2 static 200.100.10.30
You might see some error on a simple local network, because of not having a DNS server. When you don’t have a DNS server, it’s not necessary to set DNS IP address on your computer.
Finally, recheck the result with “netsh interface ipv4 show config 2” command. The output netsh command should be displayed with DNS IP address.
Final World
Configure IP address with command prompt in Windows has tow benefits. The first benefit of working with Windows command line helps get you improve your skills in Windows environment. The second benefit is command line is faster than GUI. If you work with the command line, you will understand the power of command line.
The Windows command line interface has improved a lot in Windows 10. Now you can find some Linux commands that run in Windows 10 and works the same on Linux. Finally, hope you learn how to configure IP address with Command Prompt in Windows operating systems. If you don’t understand, please ask us about how to configure IP address with command prompt in Windows 10?
The Command Prompt application, sometimes referred to as command shell, is found in most Windows NT-based operating systems. Its purpose is to execute specific commands for troubleshooting or solving specific Windows issues, performing advanced administrative functions, and automating tasks via batch files and scripts.
That said, you can also use it to change your IP address when you want to spoof it to bypass geoblocks or online bans on sites that impose such restrictions on their content, or change your Domain Name System (DNS) servers for troubleshooting reasons or to make surfing more secure and faster.
In this guide, we’re going to show you how to change your IP address and DNS servers using the Command Prompt in Windows 10.
An IP address holds information about your device, location, your internet service provider (ISP), and browser information.
Changing it is useful when you have a malfunctioning router that’s providing addresses used by a different computer on the network or an invalid address is accidentally configured. It’s also helpful when you want to install a new router and reconfigure your home network to use the default IP address range.
The first step to changing your IP address is to find the network name for the interface you want to change.
- Open an elevated Command Prompt by typing CMD in the search bar and clicking on Run as Administrator.
- Next, type netsh interface ipv4 show config in the command prompt window, press Enter, and scroll down to the interface you want.
In our case, we’ll be modifying the WiFi interface, but you can pick the correct interface for your case. Make note of the interface name.
- To change the IP address, type this command: netsh interface ipv4 set address name=”YOUR INTERFACE NAME” static IP_ADDRESS SUBNET_MASK GATEWAY
In our example, this command would look like this: netsh interface ipv4 set address name=”Wi-Fi” static 192.168.0.173 255.255.255.0 192.168.0.0
This command will use the Wi-Fi interface, set the IP address to 192.168.0.173, set the subnet mask to 255.255.255.0 and set the default gateway to 192.168.0.0.
If you want to switch to using an IP address automatically assigned by a DHCP server instead of a static IP address, use the netsh interface ipv4 set address name=”YOUR INTERFACE NAME” source=dhcp command.
How To Change DNS Servers Using Command Prompt
A DNS server holds public IP addresses and related hostnames in a database, and is used to resolve or translate the hostnames to IP addresses. The server does this by running special software to communicate with other servers through special protocols based on certain requests from the computer.
The conversion process is thoroughly vetted and verified, and it happens quickly behind the scenes so as to obtain information corresponding to the server that the computer is looking for, and then tells the original connecting computer where to go so that it can connect to that server.
There are several reasons why you’d want to change your default DNS server, but the main ones are:
- Boost your privacy when getting around a firewall, bypassing geoblocks or ISP blocks on a website
- Increase security
- Parental controls like blocking websites from your router
- Speed your surfing, which your own ISP’s DNS servers may not offer because they’re not always reliable or up-to-date
Note: You can change DNS servers individually for your home network on your router or on computers, smartphone, and Chromebook, among other devices
How To Change DNS Servers With Command Prompt
Follow the steps below to learn how to change DNS servers using Command Prompt.
- Open an elevated Command Prompt by typing CMD in the search bar, and clicking Run as Administrator.
- Type netsh and press Enter.
- Next, type interface ip show config and press Enter.
- Find the network interface whose DNS server you want to change, and enter the netsh interface ipv4 set dns name=”YOUR INTERFACE NAME” static DNS_SERVER. This will set your primary DNS server.
From our example above, we changed the IP address for the “Wi-Fi” interface, so we’ll use the same example to change DNS servers.
For purposes of this guide, we’ll use Google’s primary public DNS server, 8.8.8.8. The command will look something like this: netsh interface ipv4 set dns name=”Wi-Fi” static 8.8.8.8
- Next, type the netsh interface ipv4 set dns name=”YOUR INTERFACE NAME” static DNS_SERVER index=2 command to set the secondary DNS server. Again, we’ll use Google’s public DNS secondary server, 8.8.8.8 as an example, which will look like this: netsh interface ipv4 set dns name=”Wi-Fi” static 8.8.4.4 index=2.
Note: You can use the netsh interface ipv4 set dnsservers name”YOUR INTERFACE NAME” source=dhcp command if you want the network interface to automatically pick DNS settings from a DHCP server. Continuing with our example, this command would look like this: netsh interface ipv4 set dnsservers name”Wi-Fi” source=dhcp
Conclusion
Command Prompt is a great tool to use when you want to change IP addresses and DNS servers. It’s faster and saves you the hassle of having to click through several windows and dialog boxes from the Control Panel interface just to get to the IPv4 Properties dialog box to do the same thing.
Was this guide helpful? Let us know by dropping your comment in the section below.
Related Posts
- HDMI Cable Types and Specifications Explained
- Flat vs Round Ethernet Cables: What’s Different and Which Is Better?
- USB-C vs HDMI: What’s Different and Which Is Best for Video Output?
- What Is Bluetooth 5 and How to Upgrade?
- What Is Mesh Network Topology?