Author: Jugal Shah

  • Networking Interview Questions

    What is IPv6?

    Internet Protocol version 6 (IPv6) is a network layer IP standard used by electronic devices to exchange data across a packet-switched internetwork. It follows IPv4 as the second version of the Internet Protocol to be formally adopted for general use.  ipv6 it is a 128 bit size address. This is total 8 octants each octant size is 16 bits separated with “:”, it is in hexa decimal format. These 3 types:

    1. unicast address
    2. multicast address
    3. anycast address

    loopback address of ip v6 is ::1

    What is subnet?

    A subnet allows the flow of network traffic between hosts to be segregated based on a network configuration. By organizing hosts into logical groups, subnetting can improve network security and performance.

    What is Subnet Mask?

    A mask used to determine what subnet an IP address belongs to. An IP address has two components, the network address and the host address. For example, consider the IP address 150.215.017.009. Assuming this is part of a Class B network, the first two numbers (150.215) represent the Class B network address, and the second two numbers (017.009) identify a particular host on this network.

    Subnetting enables the network administrator to further divide the host part of the address into two or more subnets. In this case, a part of the host address is reserved to identify the particular subnet. This is easier to see if we show the IP address in binary format.

    What is Default Gateway?

    a gateway is a device on a network that acts as an entrance to another network. In more technical terms, a gateway is a routing device that knows how to pass traffic between different subnets and networks. A computer will know some routes (a route is the address of each node a packet must go through on the Internet to reach a specific destination), but not the routes to every address on the Internet. It won’t even know all the routes on the nearest subnets. A gateway will not have this information either, but will at least know the addresses of other gateways it can hand the traffic off to. Your default gateway is on the same subnet as your computer, and is the gateway your computer relies on when it doesn’t know how to route traffic.

    The default gateway is typically very similar to your IP address, in that many of the numbers may be the same. However, the default gateway is not your IP address.

    Describe how the DHCP lease is obtained.
    It’s a four-step process consisting of (a) IP request, (b) IP offer, © IP selection and (d) acknowledgement.

    What’s the difference between forward lookup and reverse lookup in DNS?
    Forward lookup is name-to-address, the reverse lookup is address-to-name.

    How can you recover a file encrypted using EFS? Use the domain recovery agent.

    What is LMHOSTS file?
    It’s a file stored on a host machine that is used to resolve NetBIOS to specific IP addresses.

    How can you force the client to give up the dhcp lease if you have access to the client PC?
    ipconfig /release

  • Open Systems Interconnection Model

    OSI 7 Layers Reference Model For Network Communication

    Open Systems Interconnection (OSI) model is a reference model developed by ISO (International Organization for Standardization) in 1984, as a conceptual framework of standards for communication in the network across different equipment and applications by different vendors. It is now considered the primary architectural model for inter-computing and internetworking communications. Most of the network communication protocols used today have a structure based on the OSI model. The OSI model defines the communications process into 7 layers, which divides the tasks involved with moving information between networked computers into seven smaller, more manageable task groups. A task or group of tasks is then assigned to each of the seven OSI layers. Each layer is reasonably self-contained so that the tasks assigned to each layer can be implemented independently. This enables the solutions offered by one layer to be updated without adversely affecting the other layers.

    The OSI 7 layers model has clear characteristics. Layers 7 through 4 deals with end to end communications between data source and destinations. Layers 3 to 1 deal with communications between network devices.

    The specific description for each layer is as follows:

    Layer 7:Application Layer

    Defines interface to user processes for communication and data transfer in network

    Provides standardized services such as virtual terminal, file and job transfer and operations

    Layer 6:Presentation Layer

    Masks the differences of data formats between dissimilar systems

    Specifies architecture-independent data transfer format

    Encodes and decodes data; Encrypts and decrypts data; Compresses and decompresses data

    Layer 5:Session Layer

    Manages user sessions and dialogues

    Controls establishment and termination of logic links between users

    Reports upper layer errors

    Layer 4:Transport Layer

    Manages end-to-end message delivery in network

    Provides reliable and sequential packet delivery through error recovery and flow control mechanisms

    Provides connectionless oriented packet delivery

    Layer 3:Network Layer

    Determines how data are transferred between network devices

    Routes packets according to unique network device addresses

    Provides flow and congestion control to prevent network resource depletion

    Layer 2:Data Link Layer

    Defines procedures for operating the communication links

    Frames packets

    Detects and corrects packets transmit errors

    Layer 1:Physical Layer

    Defines physical means of sending data over network devices

    Interfaces between network medium and devices

    Defines optical, electrical and mechanical characteristics

  • What is the Global.asax file?

    What is the Global.asax file?

    The Global.asax file (also known as the ASP.NET application file) is an optional file that is located in the application’s root directory and is the ASP.NET counterpart of the Global.asa of ASP. This file exposes the application and session level events in ASP.NET and provides a gateway to all the application and the session level events in ASP.NET. This file can be used to implement the important application and session level events such as Application_Start, Application_End, Session_Start, Session_End, etc. This article provides an overview of the Global.asax file, the events stored in this file and how we can perform application wide tasks with the help of this file.

    According to MSDN, “The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET.” The Global.asax file is parsed and dynamically compiled by ASP.NET into a .NET Framework class the first time any resource or URL within its application namespace is activated or requested. Whenever the application is requested for the first time, the Global.asax file is parsed and compiled to a class that extends the HttpApplication class. When the Global.asax file changes, the framework reboots the application and the Application_OnStart event is fired once again when the next request comes in. Note that the Global.asax file does not need recompilation if no changes have been made to it. There can be only one Global.asax file per application and it should be located in the application’s root directory only.

    The following are some of the important events in the Global.asax file.

    · Application_Init

    · Application_Start

    · Session_Start

    · Application_BeginRequest

    · Application_EndRequest

    · Application_AuthenticateRequest

    · Application_Error

    · Session_End

    · Application_End

    The purpose of these event handlers is discussed in this section below.

    Application_Init

    The Application_Init event is fired when an application initializes the first time.

    Application_Start

    The Application_Start event is fired the first time when an application starts.

    Session_Start

    The Session_Start event is fired the first time when a user’s session is started. This typically contains for session initialization logic code.

    Application_BeginRequest

    The Application_BeginRequest event is fired each time a new request comes in.

    Application_EndRequest

    The Application_EndRequest event is fired when the application terminates.

    Application_AuthenticateRequest

    The Application_AuthenticateRequest event indicates that a request is ready to be authenticated. If you are using Forms Authentication, this event can be used to check for the user’s roles and rights.

    Application_Error

    The Application_Error event is fired when an unhandled error occurs within the application.

    Session_End

    The Session_End Event is fired whenever a single user Session ends or times out.

    Application_End

    The Application_End event is last event of its kind that is fired when the application ends or times out. It typically contains application cleanup logic.

  • “Cannot Generate SSPI Context” error message, more comments for SQL Server

    The Cannot generate SSPI context issue is described by http://support.microsoft.com/?id=811889 in general. In this article we will discuss one daunting case of “Cannot generate SSPI context” error message when failing to connect to SQL server.

    In most related cases, customers report this issue as “They are not able to connect to their local SQL Server, but once they connect to my network, they can’t connection to my local SQL Server”.

    Such issue is reported against MSDE and SQLExpress versions. But actually, it can happen with any version/edition of SQL Server, including SQL Server 2000 and SQL Server 2005 that support NT integrated authentication.

    The error message for the failed connection is
    [SNAC] “[SQL Native Client]SQL Network Interfaces: The Local Security Authority cannot be contacted.[SQL Native Client]Cannot generate SSPI context”

    [MDAC] “Cannot generate SSPI context”;

    Failed System.Data.SqlClient.SqlException: Cannot generate SSPI context

    It can happen when all of followings are true:
    (1) The hosting machine of SQL Server is connected to a network, including home network or dialup connection, but it is disconnected from its domain.
    (2) The OS of the hosting machine is Windows XP or 2000. Not windows 2003.
    (3) The connection is to a local SQL Server.
    (4) Connection configuration causes network library to choose TCP/IP provider.

    A scenario that meets all of (1) (2) and (3) looks like an extreme corner case. But the reality is that it is quite often if the hosting machine is a laptop computer.

    To avoid condition (1) by connecting to your corporate domain through VPN or disconnecting from network completely.

    From user’s perspective, however, in many cases, either connecting over VPN or disconnecting from network might prevent you from accessing some valuable resources, so I want to discuss solutions that do not depend on (1) first.

    In most cases, users do not explicitly require TCP/IP as the connection provider. For example connection strings in form of “.\”, “(local)\”, “\” are among them. We might wonder why network library chooses TCP/IP provider instead of Shared Memory provider, if the connection string is not prefixed with “tcp” and the server is local.

    Answer is that it can happen if the TCP/IP provider is in front of other providers in the client protocol order list, or/and the local server is not listening on Share Memory and Name Pipe.

    As described above, only TCP/IP provider has the issue; hence, configuring network library not to choose TCP/IP is a solution. To do that, first, on the server side, make sure your server is listening on Shared Memory or/and Named Pipe connection requests; then, on the client side, change the protocol order list such that Shared Memory and/or Named Pipe are in front of TCP/IP, or prefixing your connection strings with “lpc” or “np” to force Shared Memory or Named Pipe, or using alias that prefix Named Pipe in connection strings, whichever you feel most comfortable with. Note that certain SKUs of SQL Server have named pipe connection turned off by default.

    If You really want the TCP/IP connection, the option is to use TCP/IP loop-back address, i.e. “127.0.0.1”, as your . You can also add an entry into the /etc/host file as well.

    For example, if your connection string has form of “\” and is not prefixed with “tcp”, without modifying the connection string, you can configure an alias with alias name as \, protocol as TCP/IP, server as “127.0.0.1\” or “127.0.0.1,”.

    Remember that the “Cannot Generate SSPI context” problem described in this post only happens when connecting to a local server; thus, the “127.0.0.1” is applicable.

    Be aware that only TCP/IP provider can provides the benefits of Kerberos authentication as discussed in http://blogs.msdn.com/sql_protocols/archive/2005/10/12/479871.aspx

    From the error message reported by SNAC ODBC/OLEDB, you can differentiated the issue described by this post from another case of “Cannot generate SSPI context”, in which the root cause is because, in Active Directory, the Service Principle Name (SPN) of SQL Server is registered for a domain account different from the SQL Server is actually running under.

    Make sure service account has enough permission in AD to register the SPN. You can check the below parameters for SPN as well.

    SET SPN-L Service Account. You can get more information for the SPN from this post.
    http://sqldbpool.com/2009/11/26/service-principle-name/

    Check that SPN is registered, if registered there shouldn’t be duplicate entry, should be match with the service account, Service account should have enough permission, PORT number is correct.

    For the connection failure…
    You can also check Resolving Connection failure article.

    Troubleshooting this in the AI era

    Years later, my approach to this error has a new step. I still run the deterministic checks first — DNS, port, clock skew, SPNs, the actual auth scheme — because those are facts, not guesses. Then I paste the output into an AI assistant and let it rank the likely causes. The script does the facts; the AI does the reasoning. Here is the script:

    <#
    .SYNOPSIS
    Troubleshoot "Cannot generate SSPI context" — SQL Server Kerberos checklist.
    .DESCRIPTION
    Run from the CLIENT machine. Checks DNS, port reachability, time skew,
    SPN registration, and the actual auth scheme of a live connection.
    Paste the full output into an AI assistant with the prompt printed at the end.
    .PARAMETER ServerInstance
    e.g. "SQL01" or "SQL01\INST1,1433"
    .PARAMETER ServiceAccount
    The domain account running SQL Server, e.g. "CONTOSO\sqlsvc".
    Needed for the SPN check.
    .EXAMPLE
    .\Test-SspiContext.ps1 -ServerInstance "SQL01" -ServiceAccount "CONTOSO\sqlsvc"
    #>
    [CmdletBinding()]
    param(
    [Parameter(Mandatory = $true)][string]$ServerInstance,
    [string]$ServiceAccount
    )
    $targetHost = ($ServerInstance -split '[\\,]')[0]
    Write-Host "=== SSPI / Kerberos diagnostics for $ServerInstance ===" -ForegroundColor Cyan
    # 1. DNS — Kerberos needs the *name*, not the IP, to match the SPN
    Write-Host "`n[1] DNS resolution"
    try {
    $dns = Resolve-DnsName $targetHost -ErrorAction Stop | Select-Object -First 1
    Write-Host " OK: $targetHost -> $($dns.IPAddress)"
    } catch { Write-Host " FAIL: cannot resolve $targetHost" -ForegroundColor Red }
    # 2. Port reachability
    Write-Host "`n[2] TCP 1433 reachability"
    $t = Test-NetConnection -ComputerName $targetHost -Port 1433 -WarningAction SilentlyContinue
    if ($t.TcpTestSucceeded) { Write-Host " OK: port 1433 open" }
    else { Write-Host " FAIL: port 1433 unreachable" -ForegroundColor Red }
    # 3. Time skew — Kerberos dies beyond ~5 minutes
    Write-Host "`n[3] Time skew (Kerberos tolerance: 5 min)"
    Write-Host " Local time (UTC): $([DateTime]::UtcNow.ToString('u'))"
    Write-Host " If the server clock differs by more than 5 minutes, Kerberos auth fails."
    # 4. SPN registration for the service account
    if ($ServiceAccount) {
    Write-Host "`n[4] SPNs registered for $ServiceAccount"
    $spns = setspn -L $ServiceAccount 2>&1
    $mssql = $spns | Select-String 'MSSQLSvc'
    if ($mssql) { $mssql | ForEach-Object { Write-Host " $_" } }
    else { Write-Host " FAIL: no MSSQLSvc SPN found — the classic SSPI cause" -ForegroundColor Red }
    } else {
    Write-Host "`n[4] SPN check skipped (pass -ServiceAccount to enable)"
    }
    # 5. Live connection: what auth scheme did we actually negotiate?
    Write-Host "`n[5] Live connection auth scheme"
    try {
    $cs = "Server=$ServerInstance;Integrated Security=SSPI;Connection Timeout=10;"
    $con = New-Object System.Data.SqlClient.SqlConnection($cs)
    $con.Open()
    $cmd = $con.CreateCommand()
    $cmd.CommandText = "SELECT auth_scheme FROM sys.dm_exec_connections WHERE session_id = @@SPID"
    $scheme = $cmd.ExecuteScalar()
    $con.Close()
    if ($scheme -eq 'KERBEROS') { Write-Host " OK: connected via KERBEROS" -ForegroundColor Green }
    else { Write-Host " WARN: connected via $scheme (not Kerberos) — delegation / double-hop will fail" -ForegroundColor Yellow }
    } catch {
    Write-Host " FAIL: $($_.Exception.Message)" -ForegroundColor Red
    }
    Write-Host "`n=== Now paste everything above into your AI assistant with this prompt: ===" -ForegroundColor Cyan
    @'
    I'm getting "Cannot generate SSPI context" connecting to SQL Server from a domain-joined client.
    Below is my diagnostic output. Tell me the single most likely root cause and the exact fix,
    ordered by likelihood. Be specific — SPN commands, account names, exact syntax.
    '@

    Run it as .\Test-SspiContext.ps1 -ServerInstance “SQL01” -ServiceAccount “CONTOSO\sqlsvc”, then paste the full output into your AI assistant with the prompt the script prints. The script gathers the evidence; the AI ranks the suspects.

    I’m getting “Cannot generate SSPI context” connecting to SQL Server from a domain-joined client. Below is my diagnostic output. Tell me the single most likely root cause and the exact fix, ordered by likelihood. Be specific — SPN commands, account names, exact syntax.

  • Important Backup Options

    Important Backup options

    INIT

    Specifies that all backup sets should be overwritten, but preserves the media header. If INIT is specified, any existing backup set data on that device is overwritten.

    The backup media is not overwritten if any one of the following conditions is met:

    • All backup sets on the media have not yet expired. For more information, see the EXPIREDATE and RETAINDAYS options.
    • The backup set name given in the BACKUP statement, if provided, does not match the name on the backup media. For more information, see the NAME clause.

    Use the SKIP option to override these checks. For more information about interactions when using SKIP, NOSKIP, INIT, and NOINIT, see the Remarks section.

    Note If the backup media is password protected, SQL Server does not write to the media unless the media password is supplied. This check is not overridden by the SKIP option. Password-protected media may be overwritten only by reformatting it. For more information, see the FORMAT option.