LinuxOS

How to get IPv4 connectivity on an IPv6 only VPS.

Some hosting providers like Scaleway allow to remove the IPv4 from the VPS in order to save 1€/month but doing this will result in losing connectivity to the “IPv4 world”.
Or you may have ordered a VPS that only has IPv6 connectivity and you want to access to a resource only accessible from the “IPv4 world”.
Here is how to gain your access back to the “IPv4 world”.

Change your name servers(s) to DNS64 name servers(s):

Note: You may deploy your own DNS64 & NAT64 server on a separate server by following this tutorial (untested): https://packetpushers.net/nat64-setup-using-tayga/.
Note²: You may find an explanation of what is NAT64 and DNS64 on Wikipedia.

  1. Choose a/multiple DNS64 public server(s) that has/have its own NAT64 public service from this list:
  • 2001:67c:2b0::4: provider: trex.fi / Location: Finland (Europe) / Quality of internet connectivity: good
  • 2001:67c:2b0::6: provider: trex.fi / Location: Finland (Europe) / Quality of internet connectivity: good
  • 2001:67c:27e4::64: provider: go6lab.si / Location: Slovenia (Europe) / Quality of internet connectivity: good
  • 2001:67c:27e4::60: provider: go6lab.si / Location: Slovenia (Europe) / Quality of internet connectivity: medium
  1. Replace the current name servers(s) of your /etc/resolv.conf file (old way) or in the configuration file of your network manager with the DNS64 name servers(s) that you have chosen earlier.
    If you don’t know how to change the name servers then search on your preferred search engine for a tutorial on how to change the DNS servers of your Linux distribution.
    If you don’t want to bother with configuring your network manager then you may deny any access to the /etc/resolv.conf file by using chattr +i /etc/resolv.conf after modifying the file.

Add real IPv4 connectivity for applications that work only in IPv4 (optional)

Note: This part of the tutorial only works on Linux distributions that have a systemd or Upstart as a service manager (Debian, Ubuntu, CentOS, and so on). If you are experienced enough you may “translate” the systemd service file to your service manager.
Note²: If you are using ArchLinux you don’t need to follow this part of the tutorial because there is a clatd package available on AUR: https://aur.archlinux.org/packages/clatd-git/.

  1. Install makegitcpan/perlgcc and tayga from your package manager (Debian/Ubuntu):
    sudo apt-get install -y make git gcc tayga perl
  2. Clone the clatd Github repository using:
    git clone https://github.com/toreanderson/clatd.git
  3. Change your current directory to the new directory called clatd:
    cd clatd
  4. Install clatd using:
    sudo make install
  5. Install the required perl dependencies for clatd:
    cpan Net::IP Socket6 IO::Socket::INET6 Net::DNS
  6. Start clatd with:
    sudo systemctl start clatd 
    [or] 
    initctl start clatd
  7. Wait around 30 seconds then check if you have IPv4 connectivity using curl:
    curl -4 google.com

Troubleshooting if case the curl command doesn’t work

  1. Execute
    systemctl status clatd

    and check if it say: This system already has IPv4 connectivity; no need for a CLAT.

  2. If that’s the case then add ExecStartPre=/bin/sh -c "sleep 30s && ip route del 0/0" after [Service] in the /etc/systemd/system/clatd.service file (this only works on systemd).
    If that’s not the case then try to change the DNS64 nameserver with another one from the list above then restart clatd

    sudo systemctl restart clatd

    and if it still doesn’t work then you are out of luck because your hosting provider doesn’t support the NAT64 protocol.

  3. Reload systemd and restart clatd:
    sudo systemctl daemon-reload && sudo systemctl restart clatd
  4. Check if you have IPv4 connectivity:
    curl -4 google.com

    And have Fun!

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button