i want to implement the following logic. Does it possible to have such implementation using batch or power shell ? please share with me script for that.
Let say I have a configuration file with the following "config.propertis":
BOOTPRORO=statis or dhcp
IPADDR=192.168.10.10
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
DNS=8.8.8.8
I want that at startup the system will check that file and configure network accordingly:
OS: Windows
if in BOOTPROTO=dhcp, when use DHCP in network configuration and ignore all another in config file, except DNS
if in BOOTPROTO=static, then use all variables from config file to configure IP as static.
So, I have such logic under the Linus, using shell. The script in configured in rc.d and execute before network service. Does it possible to implement such over the Windows ? Guys, please share the script !
We can definitely do this.
First things first, because a lot of systems have more than one network interface, you'll need to determine what the ifIndex is of the adapter that we want to change. Do that by running Get-NetIPInterface. You should see results like this:
In my example and going forward, I'll be using this index, 41. You should change this to match what you find on your own computer.
OK, now to read from the text file. Since you've provided the data in a key=value pair format, commonly called a hashtable, we can easily grab the data from there using ConvertFrom-Stringdata. This will give us a PowerShell hashtable, and we can pull the needed line out like this.
$values = get-content T:\config.properties | ConvertFrom-StringData
$values.BootProro
>statis
We can us this to set the PC in Dynamic IP mode, or to set static addresses. Now, for you to use this in your environment, you need to find the ifIndex, as I mentioned before. replace my index of 41 with your own, and then give it a shot. I've added -WhatIf to every line, so you will see what would happen when you run it. If you're happy with the changes it woudl make, remove -Whatif to make the script actually change the settings.
$values = gc T:\config.properties | ConvertFrom-StringData
if ($values.BOOTPRORO -eq "dhcp"){
Write-Output "---DHCP mode detected in 'config.properties' file"
Write-Output "---Setting Set-NetAdapter -DHCP Enabled"
Set-NetIPInterface –InterfaceIndex 41 –Dhcp Enabled -WhatIf
}
else{
Write-outPut "---static mode detected in 'config.properties' file"
Write-Output "---Removing network configuration"
Remove-NetIPAddress -InterfaceIndex 41 -whatif
Write-Output "---Setting new network configuration equal to"
$values
New-NetIPAddress -DefaultGateway $values.GATEWAY -IPAddress $values.IPADDR -PrefixLength 24 -InterfaceIndex 41 -WhatIf
Set-DnsClientServerAddress -ServerAddresses $values.DNS -InterfaceIndex 41 -WhatIf
}
The output looks like this:
in Windows we can set ip address via batch file or powershell script but when you use dhcp address your ip is Dynamic not static I Imposition you want static ip address
BAtch-file
netsh interface ip set address name=”Local Area Connection” static 192.168.10.10 255.255.255.0 192.168.10.1
netsh interface ip set dns name=”Local Area Connection” static 8.8.8.8
if you want be dhcp You should set
netsh interface ip set address name=”Local Area Connection” source=dhcp
note I Imposition you nic name is Local Area Connection
In powershell V3.0 and Later we Used
New-NetIPAddress –InterfaceAlias “Local Area Connection ” –IPv4Address “192.168.10.10” –PrefixLength 24 -DefaultGateway 192.168.10.1
Set-DnsClientServerAddress -InterfaceAlias “Local Area Connection” -ServerAddresses 8.8.8.8
and for startup you can put script .bat and .ps1 in startup windows but attention you should Set-ExecutionPolicy bypass before U run any script of powershell
for startup any script see link
I know how to access a ipv4 address using windows command.
Open command line and type
explorer.exe http://173.194.72.103
Here is the question, how to access a ipv6 address?
I tried to do this like ipv4
ping -6 www.google.com
result:Ping www.google.com [2607:f8b0:4006:808::1012]
explorer.exe http://2607:f8b0:4006:808::1012
or
explorer.exe https://2607:f8b0:4006:808::1012
Neither ok, they open "My Computer" panel.
If I put http://2607:f8b0:4006:808::1012 into the address bar of Google Chrome on Windows 7, it doesn't work (it searches for the "phrase" on Google). Likewise for IE. So I got to thinking, maybe your syntax is wrong, and it's not Explorer's fault. And I found this:
https://productforums.google.com/forum/#!topic/chrome/n3jUQROi1cA
Which says you must use brackets. And behold, this works:
explorer.exe http://[2607:f8b0:4006:808::1012]
The grammar is described in painstaking detail here: https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2
The key parts are:
host = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
I'm trying to get dnsmasq to push multiple search prefixes to windows machines. If I look in the MS dhcp server, it looks to be using dhcp option 135, but any attempt to configure that eg
dhcp-option=135,domain.local1,domain.local2
doesnt get pushed at all (I'm using tcpdump -i br0 -lenx -s 1500 port bootps or port bootpc | dhcpdump to view wat dnsmasq is sending)
I have minor success using dhcp option 15, but it only pushes a single name into the search prefix as displayed by ipconfig /all on windows
Any suggestions ?
Checking the ISC dhcp option list I found this:
119 Domain Search domain-search
One or more domain names, each enclosed in quotes and separated by commas
But note that dnsmasq actually provides you special option (although I'm not sure from which version it starts)
dhcp-option=option:domain-search,eng.apple.com,marketing.apple.com
Our client machines (Ubuntu 18 server using netplan/systemd-resolve) were not requesting DHCP option 119, but I could solve the problem by forcing the server (dnsmasq) to sentd that option in the reply anyway:
dhcp-option-force=option:domain-search,internal,maindomain.com
dhcp-option=option:domain-name,maindomain.com
Using the dhcp-option-force parameter makes sure that the list is sent to the clients regardless of what they ask for.
relatively new to batch files so please help me out;). What I'm trying to do is create a customized log file. Simple example:
ipconfig >> ip.log
this will display all the TCP/IP related info.
Let's say I only need the user to see the IP and Default Gateway, so the result in the output ip.log should look like this:
IPv4 Address: xxx.xxx.xxx.xxx
Default Gateway: xxx.xxx.xxx.xxx
How do I do this?
Generally you would use a filter for that purpose. You want to filter on certain strings, so findstr command is natural choice:
ipconfig | findstr /c:"IPv4 Address" /c:"Default Gateway" >>ip.log
I am setting up a development server in my flat. I have set up an Ubuntu DNS server on it and have added the zone weddinglist (just weddinglist - no TLD. It's just an internal domain.)
This works fine on my Ubuntu laptop.
On all my Windows PCs (Vista and XP) I get the following from the command prompt:
C:\Users\Giles Roadnight>nslookup weddinglist
Server: UnKnown
Address: 192.168.0.40
Name: weddinglist
Address: 192.168.0.41
C:\Users\Giles Roadnight>ping 192.168.0.41
Pinging 192.168.0.41 with 32 bytes of data:
Reply from 192.168.0.41: bytes=32 time<1ms TTL=64
Reply from 192.168.0.41: bytes=32 time<1ms TTL=64
Reply from 192.168.0.41: bytes=32 time<1ms TTL=64
Reply from 192.168.0.41: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.0.41:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\Users\Giles Roadnight>ping weddinglist
Ping request could not find host weddinglist. Please check the name and try again.
My ipconfig:
C:\Users\Giles Roadnight>ipconfig -all
Windows IP Configuration
Host Name . . . . . . . . . . . . : Giles-Desktop
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Marvell Yukon 88E8001/8003/8010 PCI Gigabit Ethernet Controller
Physical Address. . . . . . . . . : **-**-**-**-**-**
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::f179:680f:f313:5448%8(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.0.5(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
DNS Servers . . . . . . . . . . . : 192.168.0.40
NetBIOS over Tcpip. . . . . . . . : Enabled
I am pretty sure that I have the DNS set up OK as the nslookup is OK but I can't ping and I can't access webpages at weddinglist.
How can I make ping work for the Windows PCs?
It's possible that the Windows internal resolver is adding '.local' to the domain name because there's no dots in it. nslookup wouldn't do that.
To verify this possiblity, install 'Wireshark' (previously aka Ethereal) on your client machine and observe any DNS request packets leaving it when you run the ping command.
OK, further investigation on my own XP machine at home reveals that for single label names (i.e. "foo", or "foo.") the system doesn't use DNS at all, and instead uses NBNS (NetBios Name Service).
Using a hint found at http://www.chicagotech.net/netforums/viewtopic.php?t=1476, I found that I was able to force DNS lookups for single label domains by putting a single entry reading "." in the "Append these DNS
suffixes (in order)" in the "Advanced TCP/IP settings" dialog
I had this problem occasionally when using a multi-label name ie test.internal
The solution for me was to stop/start the dnscache on my windows 7 machine. Open a console as administrator and type
net stop dnscache
net start dnscache
then sigh and look for a way to get a Mac as your principal desktop.
I have the same issue with IIS running on my home server, on the client machine a command like ipconfig /flushdns usually solves the problem.
I had the same issue.
As pointed out by other answers ping and nslookup use different mechanisms to lookup an ip.
Chances are you are trying to ping a machine not on the same domain. When you ping the fully qualified name of the server this should then work.
nslookup works:
PS C:\Users\Administrator> nslookup nuget
Server: ad-01.docs.com
Address: 192.168.10.20
Name: nuget.docs.com
Address: 192.168.10.17
Ping fails:
PS C:\Users\Administrator> ping nuget
Ping request could not find host nuget. Please check the name and try again.
Ping works, using FQDN:
PS C:\Users\Administrator> ping nuget.docs.com
Pinging nuget.docs.com [192.168.70.17] with 32 bytes of data:
Reply from 192.168.10.17: bytes=32 time=1ms TTL=127
Reply from 192.168.10.17: bytes=32 time=2ms TTL=127
Reply from 192.168.10.17: bytes=32 time=2ms TTL=127
Reply from 192.168.10.17: bytes=32 time=2ms TTL=127
Ping statistics for 192.168.10.17:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 2ms, Average = 1ms
To fix this you will need to alter the DNS setting for the machine and add the DNS suffix to lookup.
Control Panel\Network and Internet\Network Connections
Network adapter -> properties
IPV4 -> Properties
General tab -> Advanced
DNS Tab
Select "Append these DNS suffixes (in order)"
Add the required domain names
Disable, then enable your network adapter (don't do this on a VM, you'll loose your connection, instead try 'ipconfig /renew')
I think this behavior can be turned off, but Window's online help wasn't extremely clear:
If you disable NetBIOS over TCP/IP,
you cannot use broadcast-based NetBIOS
name resolution to resolve computer
names to IP addresses for computers on
the same network segment. If your
computers are on the same network
segment, and NetBIOS over TCP/IP is
disabled, you must install a DNS
server and either have the computers
register with DNS (or manually
configure DNS records) or configure
entries in the local Hosts file for
each computer.
In Windows XP, there is a checkbox:
Advanced TCP/IP Settings
[ ] Enable LMHOSTS lookup
There is also a book that covers this at length, "Networking Personal Computers with TCP/IP: Building TCP/IP Networks (old O'Reilly book)". Unfortunately, I cannot look it up because I disposed of my copy a while ago.
Do you have an entry for weddinglist in your hosts file? You can find this in:
C:\WINDOWS\system32\drivers\etc
nslookup always uses DNS whereas ping uses other methods for finding hostnames as well.
I found a little bug in windows Server 2003 R2 EE.
you know that when you specify your IP address in the NIC (network connections), windows tells you that if you dont specify the preferred DNS server, it will put his own ip because it is an DNS server? well it doesn't do that...
I fixed my problem writing the dns adress manually, instead of letting windows do it for me.
Try ipconfig /displaydns and look for weddinglist. If it's cached as "name does not exist" (possibly because of a previous intermittent failed lookup), you can flush the cache with ipconfig /flushdns.
nslookup doesn't use the cache, but rather queries the DNS server directly.
It worked for me..
from https://superuser.com/a/507892
If you can ping the FQDN, look at how DNS devolution is set up the PC.
Winsock API which MS ping will automatically use the FQDN of the client PC if append primary and connection specific DNS suffix is checked in TCP/IP advanced DNS settings. If the host is in another domain, the client must perform DNS devolution.
Under XP TCP/IP advanced properties DNS, make sure append parent suffixes is checked so that the ping request traverses the domain back to the parent.
I think the problem can be because of the NAT. Normally the DNS clients make requests via UDP. But when the DNS server is behind the NAT the UDP requests will not work.
I know it's not your specific problem, but I faced the same symptoms when I configured a static IP address in the network adapter settings and forgot to enter a "Default Gateway".
Leaving the field blank, the network icon shows an Internet connection, and I could ping internal servers but not external ones, so I assumed it was a DNS problem. NSLookup still worked, but of course, ping failed to find the server (again, seemed like a DNS issue.) Anyway, one more thing to check. =P
FYI - I have been struggling with this issue for the past 3 hours. tried everything, flushing DNS, using a proxy, resetting catalog using netsh and clearing the routes. nothing worked so i decided to give windows restore a try, I did it using a windows cd -> repair -> system restore and it worked ! couldnt find any solutions online so i figured id post it
I also encountered this issue. No Windows application (except Chrome) could access the internet. I found it was a duplicate IP on the LAN. I changed the local IP, and everything, including ping, started working again.
I found the problem doing an
IPCONFIG /ALL
and it listed
IPv4 Address. . . . . . . . . . . : 10.10.0.20(Duplicate)
I also had this problem on a Server 2012 R2 VM joined to my local AD domain. I eventually solved the problem by taking the VM off the domain and re-joining it.