I am using Windows Server 2012-R2 (amazon ec2) machine.
and I want to change and verify hostname in it. I checked on net and found hostname command. But when I run hostname or hostname -i command I get following error..
sethostname: Use the Network Control Panel Applet to set hostname.
hostname -s is not supported.
I further googled this problem and apparently this command is not usable on windows 2012-r2 servers. Is there any alternative or workaround command that can do the job for me??
On windows the computer name is also often referred to as hostname. However this creates some confusion. Some people use the term hostname to refer to the leftmost part of domain name which can only be set on a DNS server. However another meaning of a hostname is just an arbitrary label assigned to a machine on a computer network, and this can be directly changed on the specific machine.
There are several ways to change the computer name from the command line on windows 2012:
Method 1. Open cmd and type:
SCONFIG and you will get selection menu where #2 says Computer Name:
Method 2. From cmd type:
netdom renamecomputer %computername% /newname:<NewName> /reboot:0
Method 3. From the PowerShell console:
netdom renamecomputer $env:computername /newname:<NewName> /reboot:0
To verify the name form cmd type:
nbtstat -A xxx.xxx.xxx.xxx (where x is the ip address)
Another way to verify the name form cmd just type "hostname" without any parameters:
hostname
Related
i have an odd issue for when i run this command:
Set-DhcpServerv4Reservation -computer name -ip 1.1.1.1 -clientid macaddress
it removes a few other variables, such as "root path". when I run get-dhcpreservation on an IP that has all of its variables set, "root path" is not something it returns, and it is not something that I can set with powershell -- plus, i'd rather it not be removed.
are there any other methods to update a dhcp reservations mac address?
after fiddling around with Set-DhcpServerv4Reservation there is really no way to set the mac address with that command without deleting option values that are set, such as iscsi targets. there is also seemingl
the fix was using Get-DhcpServerv4OptionValue to store what would be deleted as a variable, use set-dhcpserver4reservation to set the MAC address, then use set-dhcpserverv4optionvalue to add back what was deleted.
not the most ideal solution but i was successfully able to update the mac address while preserving everything that the command was deleting.
I mean to get a terminal in an Ubuntu 20.04LTS server via ssh under PS 5.1 in Win 10.
I know I can work with native support for OpenSSH, and I have already done it before.
Now I want to do it without having admin rights, to minimize "tainting" my system.
For reasons described below (1), I think I cannot work with native OpenSSH.
For reasons described below (2), I think it is possible.
For instance, I can already start a session and issue remote commands ref, see below (3).
But I couldn't start a terminal.
Is there a way to accomplish what I mean?
How?
(1) Why, for my purposes, I cannot work with native OpenSSH?
For instance, the first two commands in the PS-way of enabling OpenSSH already require admin (my PS is in Spanish):
> Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Get-WindowsCapability : La operación solicitada requiere elevación.
> Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Add-WindowsCapability : La operación solicitada requiere elevación.
(2) Why I think it might be possible to get an ssh terminal without admin rights in PS?
Because I can already perform several similarly demanding actions as a regular user without admin rights, outside PS:
1.1. I can ssh from Msys2 portable
1.2. I can connect from putty (portable)
1.3. I can transfer via WinSCP portable
Item (3) below.
(3) How to start an ssh session and issue remote commands from PS
Install Posh-SSH for the current user only.
Then
> New-SSHSession -Host xxx.xxx.0.xxx -Credential (Get-Credential)
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Server SSH Fingerprint
Do you want to trust the fingerprint xx:xx:...
[] Y [] N [?] Ayuda (el valor predeterminado es "N"): y
SessionId Host Connected
--------- ---- ---------
0 xxx.xxx.0.xxx True
> Get-SSHSession
SessionId Host Connected
--------- ---- ---------
0 xxx.xxx.0.xxx True
> Invoke-SSHCommand -Index 0 -Command "pwd"
Host : xxx.xxx.0.xxx
Output : {/home/user1}
ExitStatus : 0
The latest versions of Windows 10 (and 11) have the ssh.exe built-in. It does not need to be installed. If you do not have it, you either do not have up-to-date version of Windows 10, or the OpenSSH component was somehow explicitly removed/forbidden.
Anyway, you can download ssh.exe manually from Win32-OpenSSH project. You do not need Administrator permissions for that. It does not need any installation.
But on the other hand, if you are not supposed to install software, why are you trying to bypass those restrictions, if you already have PuTTY? Use PuTTY, not ssh. If you need a console tool for automation, you can use PuTTY plink.exe. It's a console equivalent of PuTTY. And for automation purposes, it's identical to OpenSSH ssh (it does not have all the interactive features of ssh – for interactive purposes, use PuTTY).
Windows 10 has SSH built in since v1809. An OpenSSH-Client is already installed, you can directly use it by calling ssh. Try Get-Command ssh. It should return C:\WINDOWS\System32\OpenSSH\ssh.exe. You can connect to anything that supports SSH without administrative privileges "out of the box":
ssh -l <username> <DNS-Name/IP>
There is also an OpenSSH-Server available, but has to be enabled as a feature first. You probably need administrative privileges to enable that.
MS documentation on enabling OpenSSH-Server
In order to verify a newly implemented firewall rule, I typically do the following manually:
Ex. Firewall rule: SRC-ip, DST-ip, DST-port, (protocol=TCP)
Login to the SRC box
Open up a cmd window on the SRC box (assuming Windows OS)
telnet (and check for connectivity)
I would like to automate this (to verify a long list of rules) using batch-scripting or PowerShell scripting.
I would like to be able to run the script on a third machine (other than SRC/DST).
I tried to use "Enter-PSSession" on PowerShell window to fire off remote telnet command but it didn't work, the telnet command just returned nothing.
Please share any ideas on how to implement this script.
Thanks,
Jatin
check this one: http://thesurlyadmin.com/2013/04/04/using-powershell-as-a-telnet-client/ which based on Lee-Holmes code:
http://www.leeholmes.com/blog/2006/08/30/replacing-telnet-exe-now-removed-from-vista/
Also you can add your commands to a text file and execute it using plink.exe(Putty Link) with the -m switch
-m file read remote command(s) from file
I have written a batch file to set the IP address of a host server and the two virtual machines running on it. At the moment you have to copy the script onto each machine and run it which isn't what I want, I would like to run the script on the host server and have the commands passed to each VM.
Is this possible?
You could make a powershell script which uses PsExec(comes with sysinternals) to run a scriptblock or script file on your vm machine.
It will look something like this:
PSExec \RPC001 -i -u myID -p myPWD PowerShell C:\script\StartPS.ps1
Apparantly targetting a VM could be more tricky, see this link for more information:
Is there a way to psexec into my own virtual machine (windows xp mode)?
I want to know if there is an existing command or script to retrieve the Canonical Name Record (CNAME) for a given computer or server. I would like to use this via CMD/Powershell I don't mind if such command or script uses the Windows Registry Editor (regedit).
The hostname program/command should give you the DNS name of the local machine, whereas the shell command echo %COMPUTERNAME% should show you the NetBIOS name (which might be different).