Pages

Showing posts with label WINDOWS. Show all posts
Showing posts with label WINDOWS. Show all posts

Friday, March 15, 2024

Streamlining IP Address Management on Windows Servers

Managing multiple IP addresses on a Windows server through the graphical interface can be a tedious process, requiring manual entry for each IP address in separate dialog boxes. However, there's a much simpler solution that allows you to add entire subnets in seconds using the command line.

Adding IP Addresses from the Command Line

Windows provides the netsh command, enabling configuration of network connections. To add an IP address, use the following syntax:

netsh interface ipv4 add address "Local Area Connection" 192.168.1.2 255.255.255.0

This command adds the IP address 192.168.1.2 with subnet mask 255.255.255.0 to the connection titled "Local Area Network."
Adding Multiple IP Addresses at Once

By combining the netsh command with a FOR /L loop, you can quickly add multiple IP addresses. The syntax for the loop is:

FOR /L %variable IN (start,step,end) DO command
To add every IP address from an entire subnet, use:

FOR /L %A IN (0,1,255) DO netsh interface ipv4 add address "Local Area Connection" 192.168.1.%A 255.255.255.0
This command efficiently adds all IP addresses from 192.168.1.0 to 192.168.1.255 to the "Local Area Connection" interface.

Quick Demonstration

To illustrate, let's add IP addresses 192.168.1.10 to 192.168.1.20:

FOR /L %A IN (10,1,20) DO netsh interface ipv4 add address "Local Area Connection" 192.168.1.%A 255.255.255.0
After running the command, the IP Configuration of the adapter displays the new addresses.

Additional Commands

Here are some useful additional netsh commands:

  • To list IP addresses: netsh int ipv4 show ipaddresses level=verbose
  • To delete an IP address: netsh int ipv4 delete address "Local Area Connection 1" 10.114.1.35

Adding IP Addresses to Your Dedicated Windows Server

For Windows Server 2003 and earlier:

  1. Log in to Remote Desktop.
  2. Navigate to Control Panel -> Network Connections -> Local Area Connection.
  3. Right-click Properties -> Internet Protocol (TCP/IP) -> Properties -> Advanced -> Add.

For Windows Server 2008:

  1. Log in to Remote Desktop.
  2. Open the Start menu and select Network.
  3. Double-click Network and Sharing Center.
  4. Click Change Adapter Settings -> Right-click server's network card -> Properties.
  5. Select Internet Protocol Version 4 (TCP/IPv4) -> Properties -> Advanced -> Add.

Friday, January 12, 2024

Understanding and Editing the Hosts File

Introduction:

The hosts file is a simple text file that maps hostnames to IP addresses. It allows a computer to resolve hostnames to IP addresses before it queries a DNS server. This file is available on various operating systems with similar but slightly varying paths and is particularly useful for redirecting traffic, testing websites before DNS changes, or blocking unwanted sites.

Here's a brief guide on the hosts file, its location across different operating systems, and how to edit it.

Understanding the Hosts File

The hosts file contains lines of text consisting of an IP address in the first text field followed by one or more hostnames. Each field is separated by white space (tabs are often preferred for historical reasons, but spaces are also used).

Example entry:

127.0.0.1 localhost

Hosts File Location

  • Windows 95/98/Me: C:\Windows\hosts
  • Windows NT/2000/XP: C:\windows\system32\drivers\etc\hosts or C:\winnt\system32\drivers\etc\hosts
  • Windows 7/8/10/11: C:\windows\system32\drivers\etc\hosts or use %systemroot%\system32\drivers\etc\hosts
  • Linux/Unix/Mac OS X: /etc/hosts

Note: Windows users may need to open Notepad as an Administrator to edit the file.

Editing the Hosts File

Windows:

  1. Open Notepad as Administrator: Right-click on Notepad and select "Run as Administrator".
  2. Open the Hosts File: In Notepad, go to File -> Open and navigate to C:\Windows\System32\drivers\etc. Change the file filter to "All Files" and open the hosts file.
  3. Edit and Save: Add your new entries. Save the file when done.

Linux/Unix/OS X:

  1. Open Terminal: You will need root access to edit the hosts file.
  2. Edit the Hosts File: Use a text editor like nano or vi. For example: sudo nano /etc/hosts.
  3. Edit and Save: Add your new entries. Save and exit the editor.

Common Entries:

  • Loopback Address: 127.0.0.1 is usually associated with the hostname localhost and is used to point back to your own machine.
  • Blocking Websites: To block a website, you might add an entry like
  • 127.0.0.1 unwanted-website.com.
  • Development Purposes: Redirect a domain to your local machine for development by adding an entry like

  • 127.0.0.1 my-website.dev.

Testing Changes:

After saving changes to your hosts file, you can test them by pinging the hostname you added:

  • Windows/Linux/Unix/OS X: Open your command prompt or terminal and type ping hostname (replace hostname with the one you added).

Conclusion:

Editing the hosts file is a powerful way to control how your system resolves hostnames. It's used by system administrators for testing, by developers for routing traffic to local development environments, and can even be used to block malicious or unwanted websites. Remember to back up the original file before making changes and ensure that you understand the implications of any modifications you make.

Monday, October 31, 2016

Appending Date in a PowerShell Script

The following example shows how we can append date on a file or object in a power shell. Following example uses a Aws Command for creating a Aws Image with Date Appended.

====
$CurrentDate = (Get-Date).tostring("dd-MM-yyyy-hh")
aws ec2 create-image --instance-id i-3442a --name ("test_" + $CurrentDate) --description ("test_" + $CurrentDate) --no-reboot
====

Wednesday, November 18, 2015

Create SFTP server in Windows Server.



Normally we need to install ftp role and get the site configured to use the FTP/SFTP in the windows server. Now we can Create SFTP server in windows server by enabling freeftpd from following URL

http://www.freesshd.com/?ctt=download

Saturday, August 15, 2015

Configure MySql and ODBC Connector In Windows 2012 Server

Installing MySql and its ODBC Connector In the Windows 2012 Server

Download The Microsoft Visual C++ 2010 Redistributable
http://www.microsoft.com/en-gb/download/details.aspx?id=14632

Download and install the ODBC Connector
http://cdn.mysql.com/Downloads/Connector-ODBC/5.3/mysql-connector-odbc-5.3.4-winx64.msi

Downoading the MySQL
http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26-winx64.zip

c:\mysql>cd bin
c:\mysql\bin>mysqld --install
Service successfully installed.

Go to Services and start the Mysql Services.

c:\mysql\bin>mysql -u root -p
>>No password is needed for first time

Set the root Password
=====================
mysql>
mysql> UPDATE mysql.user SET password=PASSWORD('redhat') WHERE user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | localhost |
| root | localhost |
+------+-----------+
4 rows in set (0.00 sec)


mysql> delete from mysql.user where user='';
Query OK, 1 row affected (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)


mysql> create database fileserver;
Query OK, 1 row affected (0.01 sec)

mysql>GRANT ALL PRIVILEGES ON fileserver.* TO 'fileserver'@'localhost' IDENTIFIED BY 'fileserver';
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql>

Tuesday, September 2, 2014

Enable Administrator Account in Windows

Open the command prompt with elevated privileges. To do this click the Start Orb then All Programs, click on Accessories, then right-click on Command Prompt and then select Run as administrator.
In the Command Prompt, type

net user administrator /active:yes

 

Monday, September 1, 2014

Download files through Command Prompt in Windows

HTTP
PowerShell

$source = "http://yoursite.com/file.xml"
$destination = "c:\application\data\newdata.xml"
Invoke-WebRequest $source -OutFile $destination

The Invoke-WebRequest cmdlet
Invoke-WebRequest is a cmdlet that lets you upload or download data from a remote server. This cmdlet allows for user agents, proxies, and credentials.

FTP
PowerShell

$source = "ftp://yoursite.com/file.xml"
$destination = "c:\application\data\newdata.xml"

Invoke-WebRequest $source -OutFile $destination -Credential ftpUser

The code example above is almost identical to the HTTP sample, with the main difference being that the $source variable has “ftp” at the beginning instead of “http”. You may also notice that we have used the -Credential parameter since FTP connections generally require a username and password.

Thursday, August 28, 2014

Windows 8 and fedora 20 Dual boot in HP

Recently I have moved to fedora 20 and window 8 which showed that HP laptops have a special bios which only allows windows EFI to be loaded as default so even after installing both the OS and making the EFI partition of fedora default the system boots from Windows EFI directory. To get the grub to boot first I did the following steps.

My disk partition are as below. Device           Start          End   Size Type
/dev/sda1         2048       616447   300M Windows recovery environment
/dev/sda2       616448       821247   100M EFI System
/dev/sda3       821248      1083391   128M Microsoft reserved
/dev/sda4      1083392    122882047  58.1G Microsoft basic data
/dev/sda5    122882048    123291647   200M EFI System
/dev/sda6    123291648    124315647   500M Microsoft basic data
/dev/sda7    124315648    548470783 202.3G Linux LVM
/dev/sda8    548470784    976771071 204.2G Microsoft basic data

Here I have two EFI partition /dev/sda2 (Windows) and /dev/sda5 (Fedora). As the setting is embedded in HP bios we needed a work around.

So I mounted the partititons first .

mount /dev/sda5 fedora/
mount /dev/sda2 win/

Now we copy the Fedora EFI content to Windows partions as follows

cp -rp fedora/EFI/fedora win/EFI/

In the windows partion you can find a default HP EFI content . Just rename it to some thing else.

Now rename the windows boot loader

mv win/EFI/Microsoft/Boot/bootmgfw.efi  win/EFI/Microsoft/Boot/bootmgfwB.efi

Now copy the grubloader into the place of windows bootloader

cp win/EFI/fedora/grubx64.efi win/EFI/Microsoft/Boot/bootmgfw.efi

Now recreate the grub.cfg and place it in win/EFI/fedora

grub2-mkconfig -o win/EFI/fedora/grub.cfg

It should be done by now reboot the machine and check it .

 

 

Monday, July 28, 2014

Windows Commands

ASSOC

assoccmd2 15 CMD Commands Every Windows User Should Know
Most files in Windows are associated with a specific program that is assigned to open the file by default. At times, remembering these associations can become confusing. You can remind yourself by entering the command “assoc” to display a full list of file extensions and the programs they’re connected with.
You can also extend the command to change file associations. For example, “assoc .txt=” will change the file association for text files to whatever program you enter after the equal sign. The ASSOC command itself will reveal both the extension names and program names, which will help you properly use this command. You can probably do this more easily in the GUI, but the command line interface is a perfectly functional alternative.
Cipher

ciphercmd 15 CMD Commands Every Windows User Should Know
Deleting files on a mechanical hard drive doesn’t really delete them at all. Instead, it marks the files as no longer accessible and the space they took up as free. The files remain recoverable until they’re overwritten with new data, which can take some time.
The cipher command, however, can be used to wipe a directory by writing random data to it. To wipe your C drive, for example, you’d use the command “cipher /w:c”, which will wipe free space on the drive. The command does not overwrite undeleted data, so you will not wipe out files you need by running this command.
There’s also a host of other cipher commands, however, they are generally redundant with Bitlocker enabled versions of Windows.
Driverquery

driverquerycmd 15 CMD Commands Every Windows User Should Know
Drivers remain among the most important software installed on a PC. Improperly configured or missing drivers can cause all sorts of trouble, so its good to have access to a list of what’s on your PC. That’s exactly what the “driverquery” command does. You can extend it to “driverquery -v” to obtain more information including the directory in which the driver is installed.
File Compare

This command can be used to identify differences in text between two files, and is particularly useful for writers and programmers trying to find small changes between two versions of a file. Simply type “fc” and then the directory path and file name of the two files you want to compare.
fccmd 15 CMD Commands Every Windows User Should Know
You can also extend the command in several ways. Typing “/b” compares only binary output, “/c” disregards the case of text in the comparison, and “/l” only compares ASCII text.
So, for example, you could use the following:
fc /l "C:\Program Files (x86)\example1.doc" "C:\Program Files (x86)\example2.doc"
to compare ASCII text in two word documents.
Ipconfig

This command relays the IP address that your computer is currently using. However, if you’re behind a router (like most computers today), you’ll instead receive the local network address of the router.
Still, ipconfig is useful because of its extensions. “ipconfig /release” followed by “ipconfig /renew” can force your Windows PC into asking for a new IP address, which is useful if your computer claims one isn’t available. You can also use “ipconfig /flushdns” to refresh your DNS address. These commands are great if the Windows network troubleshooter chokes, which does happen on occasion.
Netstat

Entering the command “netstat -an” will provide you with a list of currently open ports and related IP addresses. You’ll also be told what state the port is in – listening, established or closed. This is a great command if you’re trying to troubleshoot the devices your PC is connected to or you’re afraid you’re infected with a Trojan and are trying to locate a malicious connection.'

Ping

pingcmd 15 CMD Commands Every Windows User Should Know
Sometimes, you need to know whether or not packets are making it to a specific networked device. That’s where ping comes in handy. Typing “ping” followed by an IP address or web domain will send a series of test packets to the specified address. If they arrive and are returned, you know the device is capable of communicating with your PC; if it fails, you know that there’s something blocking communication between the device and your computer. This can help you decide if an issue is caused by improper configuration or a failure of network hardware.
Pathping

This is a more advanced version of ping that’s useful if there are multiple routers between your PC and the device you’re testing. Like ping, you use this command by typing “pathping” followed by the IP address, but unlike ping, pathping also relays some information about the route the test packets take.
Tracert

tracertcmd 15 CMD Commands Every Windows User Should Know
The “tracert” command is similar to pathping. Once again, type “tracert” followed by the IP address or domain you’d like to trace. You’ll receive information about each step in the route between your PC and the target. Unlike pathping, however, tracert also tracks how much time (in milliseconds) each hop between servers or devices takes.
Powercfg

Powercfg is a very powerful command for managing and tracking how your computer uses energy. You can use the command “powercfg /hibernate on” and “powercfg /hibernate off” to manage hibernation, and you can also use the command “powercfg /a” to view the power-saving states currently available on your PC.
Another useful command is “powercfg /devicequery s1_supported” which displays a list of devices on your computer that support connected standby. When enabled, these devices can be used to bring your computer out of standby – even remotely. You can enable this by selecting the device in Device Manager, opening its properties, going to the Power Management tab and then checking the “Allow this device to wake the computer” box.
“Powercfg /lastwake” will show you what device last woke your PC from a sleep state. You can use this command to troubleshoot your PC if it seems to wake from sleep at random.
powercfgcmd 15 CMD Commands Every Windows User Should Know
The “powercfg /energy” command can be used to build a detailed power consumption report for your PC, which is output to a directory indicated after the command finishes. This report will let you know of any system faults that might increase power consumption, like devices that are blocking certain sleep modes, or which aren’t properly configured to respond to your power management settings.
Windows 8 added “powercfg /batteryreport”, which provides a detailed analysis of battery use, if applicable. Normally output to your Windows user directory, the report provides details about the time and length of charge and discharge cycles, lifetime average battery life, and estimated battery capacity.'
Shutdown

As of Windows 8/8.1 there is now a shutdown command that – you guessed it! – shuts down your computer. This is of course redundant with the already easily accessed shutdown button, but what’s not redundant is the “shutdown /r /o” command, which restarts your PC and launches the Advanced Start Options menu, which is where you can access Safe Mode and Windows recovery utilities. This is useful if you want to restart your computer for troubleshooting purposes.
System File Checker

System File Checker is an automatic scan and repair tool that focuses on Windows system files. You will need to run the command prompt with administrator privileges and enter the command “sfc /scannow”. If any corrupt or missing files are found, they’ll be automatically replaced using cached copies kept by Windows for just that purpose. The command can require a half-hour to run on older notebooks.
Recovery Image

recimgcmd 15 CMD Commands Every Windows User Should Know
Virtually all Windows 8/8.1 computers ship from the factory with a recovery image, but the image may include bloatware you’d rather not have re-installed. Once you’ve un-installed the software you can create a new image using the “recimg” command. Entering this command presents a very detailed explanation of how to use it. You must have administrator privileges to use the recimg command, and you can only access the custom recovery image you create via the Windows 8 “refresh” feature.
Tasklist

The “tasklist” command can be used to provide a current list of all tasks running on your PC. Though somewhat redundant with Task Manager, the command may sometimes find tasks hidden from view in that utility.
tasklist 15 CMD Commands Every Windows User Should Know
There’s also a wide range of modifiers. “Tasklist -svc” shows services related to each task, “tasklist -v” can be used to obtain more detail on each task, and “tasklist -m” can be used to locate .dll files associated with active tasks. These commands are useful for advanced troubleshooting.
Taskkill

Tasks that appear in the “tasklist” command will have an executable and process ID (a four-digit number) associated with them. You can force stop a program using “taskkill -im” followed by the executable’s name, or “taskkill -pid” followed by the process ID. Again, this is a bit redundant with Task Manager, but may be used to kill otherwise unresponsive or hidden programs.