Ping : IPv6 repsonses when I want IPv4

If you have a Windows device and it’s not prehistoric, there is a fair chance it will come with IPv6 as well as IPv4 - if your device doesn’t, then it’s probably quite old and requires an upgrade.

IPv6 : Unloved Addressing System

IPv6 seems to get a lot of bad press and people prefer the IPv4 version because it’s familiar, if we take the most basic version that everyone should know of this example, let’s use this;

Localhost in IPv4 is 127.0.0.1
Localhost in IPV6 is ::1:

Both these addresses are valid and still get you to the same destination, but there’s something about the unfamiliar one that people don’t like, I’m not sure why because once you get to work with it IPv6 addresses they are not actually that bad, It’s the change to the industry that people don’t like.

My home network is IPv6 (to a certain broadband router then its back to IPv4)

My home network actually uses IPv6 for the gateway and DNS, and it will get so far into my broadband providers infrastructure before it falls back to IPv4 - but using the new address system interested me so I thought it would be a good idea to set it up at home.

List IP Addresses

If you want to view the address of your Windows device you can sue the old method of this which is:

ipconfig 

Then if you want more informtion you can make that:

ipconfig /all

That looks like this, but what is all that alien crap in the green box, well that is your IPv6 link-local address which allows your device to talk to other devices on the network on the same subnet using IPv6:


Yuck, I do not want that IPv6 rubbish on my devices.......really, you may find some software or services do not function without this IPv6 link-local address being active - and its not actully that irritating to have IPv6 enabled for you day-to-day activities.

If you wish to run that command in Powershell then the command the command is two fold, first run this to get the name of your network alias:

Get-NetIPAddress | fl InterfaceAlias

That will return the names of all the network card alias or names as below:


 We have established that your network card alias is called is called "Ethernet 3"

Get-NetIPAddress -InterfaceAlias "Ethernet 3"

That will look like this:


Where is the issue then?

Well ping is the baseline tool for troubleshooting and the question will be asked "can you ping it" and when you try to ping itself for example you get this:


"What is the hell is this alien crap" is your thought again, well this is not alien hieroglyphics but more the IPv6 address for localhost as we discussed earlier.

Making questional decisions with IPv6

I would not recommend just disabling IPv6 because you do not like it, or do not  understand it and Microsoft seem to agree, you can check that out here

It would appear Microsoft agree here as the first section of that article says:


However you do not want ::1: you want to see the trusty and familar 127.0.0.1 - because its comforting to you in time of need, what is worse you are not happy with that response so you head to your network connection properties and you unselect the IPv6 protocol binding like this:


This action is complete and you go back to the ping command and try you trusty "ping" again and this time you are in a land of bliss as you get the recognised and trusty address back:


You now see what you expect here and you get on with other testing, as a ping only tests the ICMP protocol, so tat fact you can ping something only proves network routing to it, it does not prove you can talk to it as thst uses TCP/UDP.

Did I just overeact and disable a protocol as it was unfamiliar ?

Yes, indeed you did and what is worse you did not need to turn off the protocol as turning it off there does not actually "turn it off" it only unbinds the protocol, but you did not need to go that far, all you needed to do was change the ping command to include "-4" 

ping localhost -4

This would then have used the IPv4 address not the IPv6 address:


Disable IPv6 Properly

If you disable IPv6, or you need to for techincal reason then you need to disable it and not unbind it, so for this I have wrote a script that will detect the status of IPv6 and then give you the options to enable/disable the IPv6 protocol.

Note : If its disabled and you enabled IPv6 or its enabled and you disable it you will need to reboot your device.

Script : IPv6Options.ps1

# Function to check the status of IPv6 on all network adapters
function Check-IPv6Status {
    $bindings = Get-NetAdapterBinding -ComponentID ms_tcpip6
    Write-Host "IPv6 Status on Network Adapters:" -ForegroundColor Cyan
    foreach ($binding in $bindings) {
        $status = if ($binding.Enabled) { "Enabled" } else { "Disabled" }
        Write-Host "$($binding.Name): $status"
    }
}

# Function to disable IPv6
function Disable-IPv6 {
    Write-Host "Disabling IPv6 on all network adapters..." -ForegroundColor Yellow
    Get-NetAdapterBinding -ComponentID ms_tcpip6 | ForEach-Object {
        Disable-NetAdapterBinding -Name $_.Name -ComponentID ms_tcpip6
        Write-Host "IPv6 disabled on $($_.Name)"
    }
}

# Function to enable IPv6
function Enable-IPv6 {
    Write-Host "Enabling IPv6 on all network adapters..." -ForegroundColor Green
    Get-NetAdapterBinding -ComponentID ms_tcpip6 | ForEach-Object {
        Enable-NetAdapterBinding -Name $_.Name -ComponentID ms_tcpip6
        Write-Host "IPv6 enabled on $($_.Name)"
    }
}

# Function to prefer IPv4 over IPv6
function Prefer-IPv4 {
    Write-Host "Configuring system to prefer IPv4 over IPv6..." -ForegroundColor Magenta
    New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" -Name "DisabledComponents" -Value 0x20 -PropertyType DWord -Force | Out-Null
    Write-Host "System is now configured to prefer IPv4 over IPv6." -ForegroundColor Magenta
}

# Main function to run the script
function Main {
    Write-Host "IPv6 Management Script" -ForegroundColor Cyan
    Check-IPv6Status

    Write-Host "`nPlease choose one of the following options:" -ForegroundColor Cyan
    Write-Host "1. (E)nable IPv6 on all network adapters" -ForegroundColor Green
    Write-Host "2. (D)isable IPv6 on all network adapters" -ForegroundColor Yellow
    Write-Host "3. (P)refer IPv4 over IPv6" -ForegroundColor Magenta
    Write-Host "4. (Q)uit the script" -ForegroundColor Red

    $choice = Read-Host "`nEnter your choice (E, D, P, or Q)"

    switch ($choice.ToUpper()) {
        "E" {
            Enable-IPv6
            Write-Host "IPv6 has been enabled on all network adapters." -ForegroundColor Green
        }
        "D" {
            Disable-IPv6
            Write-Host "IPv6 has been disabled on all network adapters." -ForegroundColor Yellow
        }
        "P" {
            Prefer-IPv4
            Write-Host "IPv4 is now preferred over IPv6 on all network adapters." -ForegroundColor Magenta
        }
        "Q" {
            Write-Host "Exiting script..." -ForegroundColor Red
            return
        }
        default {
            Write-Host "Invalid option selected. Please run the script again and choose either 'E', 'D', 'P', or 'Q'." -ForegroundColor Red
        }
    }

    Write-Host "Restarting computer for changes to take effect..." -ForegroundColor Cyan
    Restart-Computer
}

# Run the main function
Main

This is what it looks like on the main menu with the options for you to chose you payload and you event have a cute little rainbow in the text colours.




Previous Post Next Post

نموذج الاتصال