Ip is invalid though my secondary ip is valid

Hi team ,

I have just now did ip White listing. But in primary ip address I put the wrong one now I can’t modify it but in secondary I have put the correct one .

I have done getip api call where I get response secondary ip match . But now when I am placing create order it is error ip is invalid

I am stuck with the issue no customer support still yet follow up multiple times please help

3 Likes

This is exactly the same issue i faced and asked for help in some other thread. Dont know how to get this resolved.

1 Like

Put IPv6 instead of IPv4, when I have try this my problem solve so you can also try it.

Hello @alok.nayak @Soumalya_Saha

We have apihelp@dhan.co, especially to resolve IP related issues. You can email your Client ID and IP, the team will look into it.

@HunterGP we are accepting both IPv4 and IPv6, so this shouldn’t be happening.

my first ip is ipv4 and secong ip is ipv6.. second ip is correctly matched but still getting error .

@HunterGP ,
I’ve added my ipv6 , still not getting whitelisted and matched . From my linux server i run this command and it produces a compressed ipv6 format.

curl -6 https://api64.ipify.org

output: 2a02:4780:12:29ba::1

Curl command also detecting this compressed ipv6 , but this cant be added in the dhan web as dhan team says we cant add a compressed ipv6.

so adding a uncomprssed ip like 2a02:4780:0012:29ba:0000:0000:0000:0001 is also not getting whitelisted !!!

@alok.nayak Do you have Static IP address? If yes, I assume it is a static IPv4 address.

If this IP is already added in the Dhan portal and you are still receiving an “INVALID IP” error in the order response, the issue could be due to how operating systems handle network traffic.

Most modern operating systems (including Windows and Linux) prefer IPv6 over IPv4 by default. And since your IPv6 is not static, it’s dynamic, it is quite possible that it is changing quite often. Whenever you’re placing an order it has already changed or so you should rely on IPv4.

You should change your operating system configuration to always give priority to IPv4 over IPv6.


Solution: Prefer IPv4 over IPv6

For Windows

Option 1 (Persistent)

Open Command Prompt as Administrator and run:

reg add HKLM\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters /v DisabledComponents /t REG_DWORD /d 32 /f

Then restart your system.

This ensures Windows consistently prefers IPv4.


Option 2 (Temporary – Not persistent and rest on restart)

netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 60 4

Note: This resets after reboot.


Linux

Preferred Method (Persistent – Recommended)

Edit the address selection policy:

sudo nano /etc/gai.conf

Uncomment or add the following line:

precedence ::ffff:0:0/96  100

Save the file.

This makes Linux prefer IPv4 over IPv6 (similar to Windows prefix policy).


Apply changes

Usually no reboot is required, but you can restart networking:

sudo systemctl restart networking


Verify

getent ahosts google.com

if IPv4 appears first, the preference is working.

1 Like

i have whitelisted my ip address but getting the error Reason: Request rejected: Orders are only allowed from whitelisted IP addresses. This request was received from IP “the ip adresss which is white listed”

@vinay_rana8727,

The issue is i have a valid and static ipv6 address . The uncompressed ipv6 format gets detected at dhan server end , but we cant add the uncompressed format on dhan web .

stored IP on Dhan web = 2a02:4780:0012:27ea:0000:0000:0000:0001
detected IP by dhan api = 2a02:4780:12:27ea::1

At network level both these uncompressed and compressed formats are 100% identical . Still api is not comparing them as normalized IPv6 objects and may be doing as strings which is leading to not getting whitelisted.

Now i got it resolved by enforcing ipv4 as my outgoing ip and disabling ipv6 on my server

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 ;
sudo sysctl -p ;
reboot ;

My primary ip is still ipv6 and secondary is ipv4 .

curl --request GET \
--url https://api.dhan.co/v2/ip/getIP \
--header 'Accept: application/json' \
--header 'access-token:eyJ0eXAiOiJKV1****4z3DnY_EAQ'

Response is ok for ipv4

{"modifyDatePrimary":"2026-04-15","modifyDateSecondary":"2026-04-16","primaryIP":"2a02:4780:0012:27ea:0000:0000:0000:0001","secondaryIP":"89.115.33.16","detectedIP":"89.115.33.16","ipMatchStatus":"SECONDARY_MATCH","ordersAllowed":true}