Tag: DNS

Flush DNS Cache with PowerShell

Flush DNS Cache with PowerShell

Awhile ago I wrote a blog post called PowerShell Networking Cheat sheet, where I put together several networking commands which can be replaced by PowerShell. One of the latest once I saw and a couple of people requested is how you flush the DNS cache using PowerShell. This would allow you to replace ipconfig/ flushdns with PowerShell. Guess what, Microsoft as now a PowerShell cmdlet for that.

Clear and Flush DNS with PowerShell

You can use the following command to clear the DNS cache on a Windows system using PowerShell

 
Clear-DnsClientCache

Show DNS Cache with PowerShell

There is also a PowerShell command to show you the DNS cache:

 
Get-DnsClientCache

I hope this blog post and these commands are useful.



Get-NetIPConfiguration

Basic Networking PowerShell cmdlets cheatsheet to replace netsh, ipconfig, nslookup and more

Around 4 years ago I wrote a blog post about how to Replace netsh with Windows PowerShell which includes basic powershell networking cmdlets. After working with Microsoft Azure, Nano Server and Containers, PowerShell together with networking becomes more and more important. I created this little cheat sheet so it becomes easy for people to get started.

Basic Networking PowerShell cmdlets

Get-NetIPConfiguration

Get the IP Configuration (ipconfig with PowerShell)

Get-NetIPConfiguration

List all Network Adapters

Get-NetAdapter

Get a spesific network adapter by name

Get-NetAdapter -Name *Ethernet*

Get more information VLAN ID, Speed, Connection status

Get-NetAdapter | ft Name, Status, Linkspeed, VlanID

Get driver information

Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName

Get adapter hardware information. This can be really usefull when you need to know the PCI slot of the NIC.

Get-NetAdapterHardwareInfo

Disable and Enable a Network Adapter

Disable-NetAdapter -Name "Wireless Network Connection"
Enable-NetAdapter -Name "Wireless Network Connection"

Rename a Network Adapter

Rename-NetAdapter -Name "Wireless Network Connection" -NewName "Wireless"

IP Configuration using PowerShell

PowerShell Networking Get-NetIPAddress

Get IP and DNS address information

Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress

Get IP address only

(Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress).IPv4Address

Get DNS Server Address information

Get-NetAdapter -Name "Local Area Connection" | Get-DnsClientServerAddress

Set IP Address

New-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 10.0.1.95 -PrefixLength "24" -DefaultGateway 10.0.1.1

or if you want to change a existing IP Address

Set-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 192.168.12.25 -PrefixLength "24"

Remove IP Address

Get-NetAdapter -Name "Wireless" | Remove-NetIPAddress

Set DNS Server

Set-DnsClientServerAddress -InterfaceAlias "Wireless" -ServerAddresses "10.10.20.1","10.10.20.2"

Set interface to DHCP

Set-NetIPInterface -InterfaceAlias "Wireless" -Dhcp Enabled

Clear DNS Cache with PowerShell

You can also manage your DNS cache with PowerShell.

List DNS Cache:

 
Get-DnsClientCache

Clear DNS Cache

 
Clear-DnsClientCache

Ping with PowerShell

PowerShell Networking Test-NetConnection Ping

How to Ping with PowerShell. For a simple ping command with PowerShell, you can use the Test-Connection cmdlet:

 
Test-Connection thomasmaurer.ch

There is an advanced way to test connection using PowerShell

Test-NetConnection -ComputerName www.thomasmaurer.ch

Get some more details from the Test-NetConnection

Test-NetConnection -ComputerName www.thomasmaurer.ch -InformationLevel Detailed

Ping multiple IP using PowerShell

1..99 | % { Test-NetConnection -ComputerName x.x.x.$_ } | FT -AutoSize

Tracert

PowerShell Tracert

Tracert with PowerShell

Test-NetConnection www.thomasmaurer.ch –TraceRoute

Portscan with PowerShell

PowerShell Portscan

Use PowerShell to check for open port

Test-NetConnection -ComputerName www.thomasmaurer.ch -Port 80
Test-NetConnection -ComputerName www.thomasmaurer.ch -CommonTCPPort HTTP

NSlookup in PowerShell

PowerShell Networking NSlookup

NSlookup using PowerShell:

Resolve-DnsName www.thomasmaurer.ch
Resolve-DnsName www.thomasmaurer.ch -Type MX -Server 8.8.8.8

Route in PowerShell

PowerShell Networking Route

How to replace Route command with PowerShell

Get-NetRoute -Protocol Local -DestinationPrefix 192.168*
Get-NetRoute -InterfaceAlias Wi-Fi
 
New-NetRoute –DestinationPrefix "10.0.0.0/24" –InterfaceAlias "Ethernet" –NextHop 192.168.192.1

NETSTAT in PowerShell

PowerShell Networking Netstat

How to replace NETSTAT with PowerShell

Get-NetTCPConnection
Get-NetTCPConnection –State Established

NIC Teaming PowerShell commands

Create a new NIC Teaming (Network Adapter Team)

New-NetLbfoTeam -Name NICTEAM01 -TeamMembers Ethernet, Ethernet2 -TeamingMode SwitchIndependent -TeamNicName NICTEAM01 -LoadBalancingAlgorithm Dynamic

SMB Related PowerShell commands

SMB PowerShell SMB Client Configuration

Get SMB Client Configuration

Get-SmbClientConfiguration

Get SMB Connections

Get-SmbConnection

Get SMB Mutlichannel Connections

Get-SmbMutlichannelConnection

Get SMB open files

Get-SmbOpenFile

Get SMB Direct (RDMA) adapters

Get-NetAdapterRdma

Hyper-V Networking cmdlets

Hyper-V PowerShell Get-VMNetwork Adapter

Get and set Network Adapter VMQ settings

Get-NetAdapterVmq
# Disable VMQ
Set-NetAdapterVmq -Enabled $false
# Enable VMQ
Set-NetAdapterVmq -Enabled $true

Get VM Network Adapter

Get-VMNetworkAdapter -VMName Server01

Get VM Network Adapter IP Addresses

(Get-VMNetworkAdapter -VMName NanoConHost01).IPAddresses

Get VM Network Adapter Mac Addresses

(Get-VMNetworkAdapter -VMName NanoConHost01).MacAddress

I hope you enjoyed it and the post was helpful, if you think something important is missing, please add it in the comments.



Create a DNS Entry for Exchange Autodiscover

Exchange

This is a small post how you can create the DNS records for Exchange Autodiscover in the Genotec Hosting Control Panel.

  1. First login to the HCC (Hosting Control Center).
  2. Navigate to Domainnames and choose your domain
  3. (OPTIONAL) If you not already have, create a new A record for your mailserver (for example mail.the-it-crowd.ch)
    A Record
  4. (OPTIONAL) If you not already create a MX record for your domain, create a MX record
    MX record
  5. Create a CNAME for your autodiscover domain. Normally this is pointing to your mailserver. You could also use the allready exisiting mail.the-it-crowd.ch A record. But I would recommend you to create this CNAME.
    CNAME
  6. Create the Autodiscover SRV record
    TYP: SRV HOST: _autodiscover._tcp.the-it-crowd.ch. DATA:
    0 0 443 autodiscover.the-it-crowd.ch.
    SRV


Office 365 – Verify domain hosted at Genotec

office365

You can add your own Domain to your Office 365 account. If your domain is hosted at Genotec, you can simply create the DNS records for your domain with the DNS editor Genotec provides in the Hosting Control Center.

Under Domainnames, yourdomainname.com you can create a new TXT entry to verify your domain. For example:

Office 365 Verify Domain Name Genotec

After you have verifyed your Domain you have to add some other DNS Records for Exchange and Lync Online to work.

Here the DNS records for Exchange Online:

Office 365 Genotec Exchange Online Records

Office 365 Genotec Exchange Online Records

Office 365 Genotec Exchange Online Records

 

And here the DNS Records for Lync Online:

Office 365 Genotec Lync Online Records

Office 365 Genotec Lync Online Records

Remember to add the dot at the end of hostnames.

 

 



Office 365 important DNS knowledge

office365

Last week Microsoft launched Office 365. Office365 is clearly a great product. Microsoft offers three different “plans”. One is for small businesses, Plan P, maybe stands for Professional or Personal. Plan P is a offer for small businesses with less than 26 users. For bigger companies or Enterprises Microsoft offers Plan E (Enterprise) which also includes Plan K (kiosk workers).

Now there are a lot of differences between this plans which are described on the Office365 website. But there is something I just realized after I used Office 365 the first time. If you want to use Office 365 with your own domain, Microsoft has two ways to do this.

With Plan P you have to delegate all the DNS configuration to Microsofts DNS servers, which means your DNS servers for your domain, will be somednsserver.microsoft.com. Microsoft offers you a simple UI to create additional CNAME and A records. And all your MX records and A records which are used by Office 365 will be created automatically. This makes it very easy, but even for some small businesses this does not work, because they may need more than just some simple additional A records or CNAMEs.

If you wanna use your own DNS servers or the DNS servers of your provider, you have to use one of the Enterprise plans (there are more than one plan). With a Plan E1 for example, you can choose to delegate all the DNS administration to the Microsoft DNS servers or you can choose your own, maybe already existing public DNS servers. In this case Microsoft tells you which DNS records you need to create (MX, TXT and A records).



Quick nslookup Guide

nslookup help

This is a quick note how to use nslookup.exe.

Start nslookup and check for domain

C:> nslookup
Default Server:  ns1.corp.pepsi.local
Addresse:  10.10.20.1
> thomasmaurer.ch
Default Server: ns1.corp.pepsi.local
Addresse: 10.10.20.1
 
Name:    thomasmaurer.ch
Address:  217.26.52.30
>

Change Nameserver for search querys

> server ns2.corp.pepsi.local
Default Server: ns2.corp.pepsi.local
Addresse: 10.10.20.2
>

Set a query type (ex. A,AAAA,A+AAAA,ANY,CNAME,MX,NS,PTR,SOA,SRV)

> set type=mx
> thomasmaurer.ch
Server: ns2.corp.pepsi.local
Address:  10.10.20.2
 
thomasmaurer.ch MX preference = 10, mail exchanger = mx2.mail.genotec.ch
thomasmaurer.ch MX preference = 10, mail exchanger = mx1.mail.genotec.ch
mx1.mail.genotec.ch   internet address = 217.26.49.141
mx1.mail.genotec.ch   internet address = 217.26.49.140
mx2.mail.genotec.ch   internet address = 217.26.49.139
mx1.mail.genotec.ch   internet address = 217.26.49.142
>

nslookup.exe help

Commands:   (identifiers are shown in uppercase, [] means optional)
NAME            - print info about the host/domain NAME using default server
NAME1 NAME2     - as above, but use NAME2 as server
help or ?       - print info on common commands
set OPTION      - set an option
    all                 - print options, current server and host
    [no]debug           - print debugging information
    [no]d2              - print exhaustive debugging information
    [no]defname         - append domain name to each query
    [no]recurse         - ask for recursive answer to query
    [no]search          - use domain search list
    [no]vc              - always use a virtual circuit
    domain=NAME         - set default domain name to NAME
    srchlist=N1[/N2/.../N6] - set domain to N1 and search list to N1,N2, etc.
    root=NAME           - set root server to NAME
    retry=X             - set number of retries to X
    timeout=X           - set initial time-out interval to X seconds
    type=X              - set query type (ex. A,AAAA,A+AAAA,ANY,CNAME,MX,NS,PTR,SOA,SRV)
    querytype=X         - same as type
    class=X             - set query class (ex. IN (Internet), ANY)
    [no]msxfr           - use MS fast zone transfer
    ixfrver=X           - current version to use in IXFR transfer request
server NAME     - set default server to NAME, using current default server
lserver NAME    - set default server to NAME, using initial server
root            - set current default server to the root
ls [opt] DOMAIN [> FILE] - list addresses in DOMAIN (optional: output to FILE)
    -a          -  list canonical names and aliases
    -d          -  list all records
    -t TYPE     -  list records of the given RFC record type (ex. A,CNAME,MX,NS,PTR etc.)
view FILE           - sort an 'ls' output file and view it with pg
exit            - exit the program


How to add a Windows Server 2008 R2 Core as Secondary DNS Server

This shows you how you can add a secondary DNS Server to your Network on a Windows Server 2008 R2 Core.

  1. As usual you configure the Windows Server 2008 R2 Core with Sconfig
  2. Now install the DNS Server role on the Windows Server 2008 R2 Core
    Windows Server 2008 R2 Core DNS Serverstart /w ocsetup DNS-Server-Core-Role
  3. On the primary DNS Server open the DNS Server MMC
  4. Right click properties on the DNS zones you wanna transfer to the new core server
  5. Add the new DNS Server in the Name Server Tab. In this case this is server04.corp.pepsi.local
    Windows Server 2008 R2 DNS Server
  6. Allow Zone Transfers to this Server or Server in the Name Servers Tab
    Windows Server 2008 R2 DNS Server