Настройка сети в Hyper-V с помощью Powershell

Настройка сети в Hyper-V с помощью Powershell 01Настройка сети в Hyper-V с помощью Powershell может являться достаточно распространенным сценарием, ведь во многих случаях хост Hyper-V представляет из себя систему с интерфейсом Server Core. Факт однообразия конфигурации хостов виртуализации только способствует такому подходу.

В статье вы увидите пример решений одной из задач администрирования реальной инфраструктуры в продакшене.


Если вам интересна тематика Windows Server, рекомендую обратиться к тегу  Windows Server  на моем блоге.


Настройка сети в Hyper-V с помощью Powershell

Если читать лень и хотите сразу получить скрипт, то пожалуйста — NetReconfigure(rev.1.0.0). Есть также расширенная версия, которая обрабатывает некоторые возможные ситуации — NetReconfigure(rev.1.0.1).

Но все же я советую прочесть хотя бы раздел ниже, чтобы понимать для чего предназначен сценарий.

Также не забудьте установить переменные в актуальные для вас значения.

Окружение

Что было: парк серверов виртуализации, которые нужно перенастроить. Конфигурация типовая, на каждом сервере одна встроенная сетевая карта с двумя интерфейсами.

  • Один интерфейс использовался для управления хостом;
  • На втором интерфейсе висел единственный виртуальный коммутатор, через который ВМ выходили наружу.

То есть достучаться до хоста можно было по одному единственному адресу.

Что нужно было сделать: на базе двух интерфейсов создать тиминг-группу, на базе этой тиминг-группы создать внешний виртуальный коммутатор и подключить к нему все ВМ.

Если интересуют детали реализации на уровне сетевого оборудования, то конечно же каждый из двух сетевых интерфейсов сервера планировалось что будет смотреть в отдельный коммутатор. То есть была цель реализовать избыточность на уровне сетевого оборудования.

Примечание: внимательный читатель спросит зачем все это нужно, если избыточности на уровне сетевых карт сервера нету. Все верно, но хоть что-то. На моей памяти коммутаторы выходили из строя значительно чаще, чем сетевые карты на серверах, так что есть смысл обеспечить резервирование хотя бы на таком уровне.

Последовательность операций

Коротко пройдемся по основным этапам настройки.

Удаление старого виртуального коммутатора

Вы не сможете удалить виртуальный коммутатор, если к нему будут подключены ВМ. Отключаем все адаптеры всех ВМ одной командой:

Теперь можно удалить виртуальный коммутатор:

Напомню, что в моем окружении на каждом сервере был только один vSwitch.

Сохранение сетевых настроек

На каждом сервере был всего лишь один адаптер со статическими сетевыми настройками, а потому можно их легко запомнить, чтобы потом назначить тиминг-адаптеру.

Сохраняем ip-адрес:

Маску подсети:

Шлюз (пришлось погуглить, чтобы дойти до такой конструкции)

Серверы DNS:

Все настройки сохранены.

Создание тиминг-группы

Создается одной командой:

Конструкция ( Get-NetAdapter -Physical ).Name возвращает список имен всех физических интерфейсов. Если ваша конфигурация отличается, вам стоит обратить внимание на этот момент.

Создание виртуального коммутатора

Тиминг-группа создана, можно на её основе создать виртуальный коммутатор:

Параметр -AllowManagementOS $true создаст виртуальный сетевой адаптер хоста.

Возвращение сетевых настроек

Тиминг-группа создана, виртуальный коммутатор на её основе тоже. После этого создался виртуальный сетевой адаптер хоста (имя по умолчанию vEthernet (External)), которому мы должны назначить ранее сохраненные сетевые настройки:

DNS-настройки восстанавливаются отдельно:

После завершения работы скрипта хост должен быть доступен по старому адресу.

Подключение адаптеров ВМ

Подключаем все адаптеры всех ВМ к единственному виртуальному коммутатору:

Далее самое интересное.

Настройка VLAN виртуальных машин

Порты коммутаторов, к которым подключен сервер, должны быть выставлены в trunk-режим. Каждой виртуальной машине выставим идентификатор VLAN:

Примечание: такой подход более гибкий. Каждой виртуальной машине вы можете выставить произвольный идентификатор VLAN.

Команда PowerShell выше эквивалентна ручному выставлению VLAN ID в настройках сетевого адаптера виртуальной машины:

Настройка сети в Hyper-V с помощью Powershell 02

Остался последний этап.

Настройка VLAN хоста

Установим идентификатор VLAN на виртуальном адаптере хоста:

Где $HostVlanId — идентификатор VLAN, который определен в этой переменной в самом начале скрипта.

Команда PwerShell выше эквивалентна ручному выставлению VLAN ID в настройках виртуального коммутатора.

Настройка сети в Hyper-V с помощью Powershell 03

Примечание: Внимание! При изменении этих настроек вы можете потерять соединение с хостом.

На этом работа скрипта завершена, доступ к хосту и всем ВМ должен восстановиться.

comments powered by HyperComments
3locally
2022-07-04 17:28:07
<strong>3insular</strong>
phd without dissertation
2022-07-05 19:10:50
<strong>writing your dissertation in https://professionaldissertationwriting.com/</strong>
buy dissertation online
2022-07-05 21:10:38
<strong>phd thesis https://helpwithdissertationwritinglondon.com/</strong>
undergraduate dissertation
2022-07-05 23:49:10
<strong>sample dissertation https://dissertationwritingcenter.com/</strong>
dissertation writing tutor
2022-07-06 02:18:03
<strong>dissertation writing tutors https://dissertationhelpexpert.com/</strong>
dissertation help methodology
2022-07-06 04:38:41
<strong>dissertation abstracts international https://accountingdissertationhelp.com/</strong>
dissertation editing services
2022-07-06 06:08:43
<strong>what is a dissertation https://examplesofdissertation.com/</strong>
dissertation abstracts
2022-07-06 11:13:40
<strong>writing your dissertation in a week https://bestdissertationwritingservice.net/</strong>
acknowledgements dissertation
2022-07-06 14:34:19
<strong>phd thesis https://businessdissertationhelp.com/</strong>
writing your dissertation in a week
2022-07-06 18:21:21
<strong>edd dissertation topics https://customdissertationwritinghelp.com/</strong>
dissertation writing plan
2022-07-06 21:07:55
<strong>creative writing lindenberg https://writingadissertationproposal.com/</strong>
buy art online berlin
2022-07-07 03:44:25
<strong>writing your dissertation in https://dissertationhelperhub.com/</strong>
help writing
2022-07-07 06:23:03
<strong>writing my dissertation https://customthesiswritingservices.com/</strong>
online casino real money usa
2022-07-25 20:17:30
<strong>live dealer online casino https://download-casino-slots.com/</strong>
sugarhouse casino online nj
2022-07-25 21:17:34
<strong>us casino online https://firstonlinecasino.org/</strong>
free sign up bonus online casino
2022-07-25 23:18:05
<strong>new online casino no deposit bonus codes https://onlinecasinofortunes.com/</strong>
online casino dealer
2022-07-26 02:48:19
<strong>online casino reviews usa https://newlasvegascasinos.com/</strong>
el royale online casino review
2022-07-26 05:00:09
<strong>zone online casino login https://trust-online-casino.com/</strong>
no deposit online casino bonus codes
2022-07-26 07:58:26
<strong>wv casino online https://onlinecasinosdirectory.org/</strong>
online casino spielen
2022-07-26 10:27:39
<strong>online casino free money https://9lineslotscasino.com/</strong>
online bitcoin casino
2022-07-26 13:01:48
<strong>wynn casino online https://free-online-casinos.net/</strong>
resorts casino online app
2022-07-26 18:41:01
<strong>usa online casino https://cybertimeonlinecasino.com/</strong>
slots casino online
2022-07-26 20:46:12
<strong>online casino no deposit sign up bonus https://1freeslotscasino.com/</strong>
san manuel online casino promo codes
2022-07-26 23:46:43
<strong>online casino code https://vrgamescasino.com/</strong>
foxwoods online casino
2022-07-27 02:33:18
<strong>online casino pa https://casino-online-roulette.com/</strong>
paradise casino online
2022-07-27 03:57:30
<strong>online casino minimum deposit https://casino-online-jackpot.com/</strong>
hardrock online casino nj
2022-07-27 07:03:30
<strong>mgm casino online https://onlineplayerscasino.com/</strong>
harrah's casino online
2022-07-27 09:24:17
<strong>las vegas online casino real money https://ownonlinecasino.com/</strong>
newest pa online casino
2022-07-27 15:57:26
<strong>play free casino games online https://casino8online.com/</strong>
business vpn
2022-08-07 14:33:00
<strong>best vpn to use in china https://freevpnconnection.com/</strong>
private vpn
2022-08-07 16:41:39
<strong>vpn to buy https://shiva-vpn.com/</strong>
best vpn protocols
2022-08-07 19:25:53
<strong>top vpn service providers https://freehostingvpn.com/</strong>
buy dedicated vpn
2022-08-07 23:07:12
<strong>best vpn netflix https://ippowervpn.net/</strong>
incognito vpn
2022-08-07 23:53:36
<strong>free vpn service https://imfreevpn.net/</strong>
secure vpn
2022-08-08 03:00:36
<strong>proton vpn free trial https://superfreevpn.net/</strong>
best vpn for gaming
2022-08-08 04:24:39
<strong>best vpn for routers https://free-vpn-proxy.com/</strong>
buy vpn online
2022-08-08 07:49:50
<strong>free vpn for linux https://rsvpnorthvalley.com/</strong>
which gay dating app has most members
2022-08-23 14:30:50
<strong>gay dating sites cape cod https://gay-singles-dating.com/</strong>
dating gay costa rican men
2022-08-23 15:57:56
<strong>gay bear dating sites https://gayedating.com/</strong>
#ИМЯ?
2022-08-23 18:41:26
<strong>adam for adam gay online dating hookups https://datinggayservices.com/</strong>
online dating best site
2022-08-24 13:22:35
<strong>free single site https://freephotodating.com/</strong>
dating sites for mature singles adults
2022-08-24 17:04:15
<strong>free dating sites in iran https://adult-singles-online-dating.com/</strong>
date free internet
2022-08-24 20:07:36
<strong>european dating site uk https://adult-classifieds-online-dating.com/</strong>
date online personal
2022-08-24 22:22:29
<strong>europe online dating https://online-internet-dating.net/</strong>
free date
2022-08-25 01:25:55
<strong>free adult dating sites https://speedatingwebsites.com/</strong>
dating services online
2022-08-25 02:09:38
<strong>online dating meet https://datingpersonalsonline.com/</strong>
meet older women for free
2022-08-25 04:24:49
<strong>single dating https://wowdatingsites.com/</strong>
pof dating
2022-08-25 07:43:42
<strong>the best online dating site https://lavaonlinedating.com/</strong>
xxxlesbian dominance
2022-08-25 10:06:07
<strong>local dating sites free https://freeadultdatingpasses.com/</strong>
singles chat
2022-08-25 10:59:11
<strong>japanese chubby https://virtual-online-dating-service.com/</strong>
free dating sites for men
2022-08-25 15:02:02
<strong>100 free chat and dating for adults free https://zonlinedating.com/</strong>
free adult personals
2022-08-25 16:38:02
<strong>best dating websites https://onlinedatingservicesecrets.com/</strong>
fastest withdrawal online casino
2022-08-30 08:50:18
<strong>nj casino online sites https://onlinecasinos4me.com/</strong>
mgm pa online casino
2022-08-30 15:03:28
<strong>wv online casino https://online2casino.com/</strong>
gay zoom webcam chat
2022-09-03 03:00:53
<strong>gay chat cams free https://newgaychat.com/</strong>
gay local chat
2022-09-03 07:46:22
<strong>gay chat rooms no registration https://gaychatcams.net/</strong>
snap chat gay shoutouts
2022-09-03 11:42:09
<strong>easy gay chat https://gaychatspots.com/</strong>
zoom cams gay sex chat
2022-09-03 17:46:28
<strong>b - gay chat https://gay-live-chat.net/</strong>
hiv gay chat san diego
2022-09-03 20:55:41
<strong>bbrt gay chat site https://chatcongays.com/</strong>
chat gay en mexico.com
2022-09-04 03:06:49
<strong>open gay chat rooms https://gayphillychat.com/</strong>
gay live chat
2022-09-04 07:10:42
<strong>gay cam chat avenue https://gaychatnorules.com/</strong>
mature gay chat app
2022-09-04 09:55:48
<strong>miai chat gay https://gaymusclechatrooms.com/</strong>
chat ave gay
2022-09-04 15:19:18
<strong>gay chat nyc https://free-gay-sex-chat.com/</strong>
gay phone chat locker*
2022-09-05 00:19:56
<strong>gay chat toms river nj https://gayinteracialchat.com/</strong>
gay chat lines
2022-10-20 17:11:02
<strong>anonymous gay chat https://gaymanchatrooms.com/</strong>
paper helper
2022-10-20 18:41:01
<strong>best online paper writing service https://term-paper-help.org/</strong>
cheap custom written papers
2022-10-20 19:29:24
<strong>order a paper online https://sociologypapershelp.com/</strong>
pay someone to write paper
2022-10-20 20:34:24
<strong>pay for paper https://uktermpaperwriters.com/</strong>
pay people to write papers
2022-10-20 22:24:18
<strong>best paper writing services https://paperwritinghq.com/</strong>
paper writing services reviews
2022-10-21 01:14:10
<strong>pay to write papers https://write-my-paper-for-me.org/</strong>
custom writing paper service
2022-10-21 02:20:07
<strong>help with writing paper https://doyourpapersonline.com/</strong>
write my philosophy paper
2022-10-21 04:40:08
<strong>write my nursing paper https://researchpaperswriting.org/</strong>
write my paper for money
2022-10-21 06:06:56
<strong>some to write my paper https://cheapcustompaper.org/</strong>
pay people to write papers
2022-10-21 08:23:32
<strong>what should i write my paper about https://writingpaperservice.net/</strong>
where can you buy resume paper
2022-10-21 11:01:54
<strong>papers writing help https://mypaperwritinghelp.com/</strong>
buying paper
2022-10-21 11:44:12
<strong>where can i find someone to write my paper https://writemypaperquick.com/</strong>
professional college paper writers
2022-10-21 12:52:34
<strong>customized paper https://essaybuypaper.com/</strong>
buy a college paper online
2022-10-21 14:17:50
<strong>college papers for sale https://papercranewritingservices.com/</strong>
need help writing a paper
2022-10-21 16:05:03
<strong>buy school papers online https://premiumpapershelp.com/</strong>
order a paper
2022-10-21 17:36:14
<strong>college paper help https://ypaywallpapers.com/</strong>
write my papers
2022-10-21 18:38:51
<strong>best write my paper website https://studentpaperhelp.com/</strong>
1scapegrace
2023-01-26 23:38:52
<strong>1overall</strong>
creative writing coursework ideas
2023-02-05 14:24:54
<strong>coursework writers https://brainycoursework.com/</strong>
coursework writer uk
2023-02-05 15:34:35
<strong>degree coursework https://courseworkninja.com/</strong>
coursework writer uk
2023-02-05 17:07:49
<strong>coursework help university https://writingacoursework.com/</strong>
coursework in english
2023-02-05 19:18:11
<strong>coursework support https://mycourseworkhelp.net/</strong>
do my coursework
2023-02-05 21:00:11
<strong>coursework resources https://courseworkdownloads.com/</strong>
coursework writing service uk
2023-02-05 22:58:20
<strong>coursework uk https://coursework-expert.com/</strong>
creative writing coursework ideas
2023-02-05 23:42:19
<strong>coursework sample https://teachingcoursework.com/</strong>
woman dating sites
2023-02-08 13:48:00
<strong>vip dating now https://jewish-dating-online.net/</strong>
datiing websites
2023-02-08 14:59:55
<strong>free dating apps no fees https://jewish-dating-online.net/</strong>
cdff dating site login
2023-02-08 19:04:41
<strong>tinder dating site https://onlinedatingsurvey.com/</strong>
free free online dating
2023-02-08 20:20:22
<strong>free dating site for ladys https://onlinedatingsuccessguide.com/</strong>
meet single women
2023-02-08 21:32:56
<strong>adult online dating https://onlinedatinghunks.com/</strong>
personals online
2023-02-08 22:54:11
<strong>date sites free for men https://datingwebsiteshopper.com/</strong>
dating free online sites
2023-02-09 00:15:25
<strong>dating websites for free https://allaboutdatingsites.com/</strong>
free local dating
2023-02-09 01:43:00
<strong>free american dating site for christian https://freedatinglive.com/</strong>
online dating services
2023-02-09 02:26:55
<strong>internet dating services https://freewebdating.net/</strong>
Яндекс.Метрика