I am trying to wrap my head around IPV6 networks. I have a static IPV4 from my isp and when I am building apps I use what I am assuming is a "hard coded" address. Like the below:

//The * are replaced with my static IPV4 address
network_connect_raw(client, "**.**.**.***", 8000);

Are IPV6 addresses always dynamic? Or to switch to an IPV6 network would I need to get a static IPV6 address to hardcode into my application? Either way I would need some method to consistently and reliably connect to my server...

I know a little bit about DNS. Is it that you hard code a "route" to the DNS which returns with the current address for your IPV6 server that could be dynamic?

Here are Google's DNS IPV6 addresses:

The Google Public DNS IPv6 addresses are as follows:



I'm thinking I would need to get a domain name... and then "hard code" a DNS IPV6 name into my application; which would then submit my domain name to get translated into IPV6. Is this correct?

  • 1
    Never hard code a static address into your programs, no matter if it's IPv4 or IPv6. Make it configurable (as commandline option, configuration file entry, or whatever), and allow both names (like www.google.com) and numeric addresses. I.e., do a DNS lookup first. Your OS, whatever it is, has libraries for that. – dirkt Sep 18 '18 at 10:29

I use what I am assuming is a "hard coded" address

Yes. "Hardcoding" means putting the information directly in your code, instead of using some indirect means (such as DNS or simple config file). This is a general term and not limited to IP, or even networking.

If your connect() calls refer directly to an IP address – then yes, you are hardcoding the address. If the address ever changes, you will have to recompile the program.

Are IPV6 addresses always dynamic?

No. Both IPv4 and IPv6 follow the same general rules:

  • Whether your ISP provides you with static or dynamic addresses depends entirely on what contract you sign with them (including what plan you choose, etc.)

    For residential and smaller business connections, addresses are allocated by the ISP according to the ISP's policies. You might get one public IPv4 address or a dozen, you might get an IPv6 /64 or a /48, these allocations might be static or they might change every day – all depends on the contract that you've signed with the ISP.

  • How you assign addresses to your servers and other computers within your LAN depends entirely on you. If you want a device's address to remain static, you can do that.

    It's true that dynamic assignment via SLAAC in IPv6 is a bit more common than DHCP in IPv4. However, 'dynamic' does not mean that the address will change. Indeed, with IPv6 SLAAC, the same device will usually keep picking the same address forever.

    Finally, nothing prevents you from manually configuring a fixed address for the device. Doing so is perfectly normal in IPv6.

Or to switch to an IPV6 network would I need to get a static IPV6 address to hardcode into my application?

You shouldn't hardcode specific addresses in your application in the first place.

I guess I was more asking about how to avoid hard coding an address into an application

Put them somewhere outside the application. The two most common methods are:

  • using DNS – that is, configuring a domain name to point to your server;

  • providing a configuration mechanism – such as an .ini file, or the Registry, or something else entirely.

I'm thinking I would need to get a domain name... and then "hard code" a DNS IPV6 name into my application

Yes. You're still hardcoding something (the domain name), but at least the domain name is much less likely to change – whereas a server's IP address may have many reasons to be changed. (For example, the server might be moved to another location, or its whole network might be restructured, or switched to a different ISP.)

Although I would say that there isn't such a thing as "DNS IPv6 names". A domain name may refer to both IPv4 and IPv6 addresses at the same time, and it might even have multiple addresses of the same type.

A well written program will try all addreses it finds (e.g. with help of the getaddrinfo() function). This allows it to work in both IPv4-only and IPv6-only networks, as well as mixed ones.

  • I'll have to look into SLAAC and manually configuring a fixed IPV6 address. As far as a well written program trying all addresses it finds; don't most applications connect to very specific services and would therefore need only 1 address per service? – Pfap Sep 18 '18 at 23:52
  • No. Again, as I mentioned, if you want to offer both IPv6 and IPv4, that's already two addresses – one for either type. The same service may actually be provided by multiple machines, resulting in multiple addresses. (That's a rudimentary form of load-balancing, aka "DNS round-robin".) – grawity Sep 19 '18 at 4:07

The question of the availability of static IPv6 is better addressed to your ISP. Not all ISPs support them, while for others a static IPv6 assignment automatically comes with a static IPv4 assignment.

I note that if available, the static IPv6 is only a prefix delegation. If you have an IPv6 compliant router, then it can accept that prefix delegation and subsequently assign or allow you to assign static IPv6 addresses to devices attached to your network.

If by "hard coding" you meant using a short name instead of typing the IPv6 long string, you may define it as an alias via the hosts file. See the StackOverflow post
IPv6 in windows hosts file.

  • Right, because paying for something that is as plentiful as IPV6 addresses is counterintuitive. – Pfap Sep 18 '18 at 9:56
  • I guess I was more asking about how to avoid hard coding an address into an application. – Pfap Sep 18 '18 at 10:08
  • You could give it an alias via the hosts file. – harrymc Sep 18 '18 at 10:11
  • Added more info to my answer. – harrymc Sep 18 '18 at 10:35

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.