Common problems sometimes demand uncommon solutions
Occasionally, one or other (not updated/lazy) application may not support direct usage when the starting point is an IPv6 address, because they are designed to use an IPv4-formatted address. Despite this, they usually are tolerant to the IPv4 range you're using, allowing you to specify internal IPv4s (which are in the range 10.x.x.x/8, 172.16.x.x/12 - 172.32.x.x/12, or 192.168.x.x/16), as you would already have on any other purchased NAT VPS, since they don't distinguish between addresses.
The only difference between C-Servers and other providers on NAT VPS is that while others provide a IPv4 NAT internal address by default (which is not public, only private), we prefer to provide an IPv6 public address that is dual-function (also sends/recieves IPv4 requests) and then translate + internally route your request to/from the main server's IPv4.
Due to SolusVM 2 templates and cloud-init images not predicting an alternative internal IPv4 address, and C-Servers' stance as an IPv6-first company, we don't provide by default such addresses. However, in this guide, we will show you how to have IPv4 connectivity on applications that demand an IPv4-only address. This is accomplished by a simple three-step process:
- disabling cloud-init on your VPS;
- adding the internal IPv4 address to the system;
- creating an internal socat between that IPv4 and IPv6 for full connectivity.
Packets that arrive in your VPS from IPv6 are already complete, the redirection is entirely internal at the TCP/IP socket level, and this has been a solution used for quite a while now.
How to have native internal IPv4 connectivity on MultiVPS
sudo touch /etc/cloud/cloud-init.disabled
For Ubuntu 22.04/24.04 (using Netplan):
sudo nano /etc/netplan/01-netcfg.yaml
Within this file, do not delete anything else, and add (again, just an example, check the process for your OS):
network:
version: 2
ethernets:
eth0: # Your interface name might be different
addresses:
- 10.0.0.10/24 # Add the entry and eventually replace with your desired internal IPv4 range and subnet (blocks 172.16.x.x/12, 192.168.x.x/16)
Ctrl+O to save, Enter to confirm, Ctrl+X to exit the Nano editor.
For Enterprise Linux (RHEL/CentOS/Tencent/AlmaLinux/Rocky Linux, example for RHEL 9/AlmaLinux 9), on a normal command line via SSH or VNC, write:
nmcli con mod eno1 ipv4.addresses 192.168.1.100/24 [you can insert any other private IPv4 range, ensure subnet and IP are OK]
nmcli con mod eno1 ipv4.gateway 192.168.1.1 [from within the same private IPv4 range chosen, always the first address of it]
nmcli con mod eno1 ipv4.dns 8.8.8.8 [use any regular IPv4 DNS]
nmcli con mod eno1 ipv4.method manual [do NOT insert auto, this is a non-DHCP address]
To put the connection up simply insert:
nmcli con up eno1
sudo apt update && sudo apt install socat -y # For Debian/Ubuntu, OR
sudo dnf install socat # For RHEL-based distros (example working for RHEL8/RHEL9-based distros)
And activate IPv4 and IPv6 forwarding support at sysctl:
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.all.forwarding=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
sudo nano /etc/systemd/system/ipv4-to-ipv6-routing.service
Add the following content:
[Unit]
Description=IPv4 to IPv6 Socat Routing Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/socat TCP4-LISTEN:PORT,bind=10.0.0.10,reuseaddr,su=nobody,fork TCP6:[YOUR_IPV6_ADDRESS]:PORT
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Replace:
10.0.0.10
with your desired internal IPv4 address[YOUR_IPV6_ADDRESS]
with the public provided IPv6 address for your VPSPORT
with a port number you want to forwardsudo systemctl enable ipv4-to-ipv6-proxy.service
sudo systemctl start ipv4-to-ipv6-proxy.service
And this service will now start automatically upon every boot.
Socat works TCP/UDP, from IPv4 to IPv6, and from IPv6 to IPv4. Examples of commands are:
socat UDP4-LISTEN:10683,bind=10.0.0.10,reuseaddr,su=nobody,fork UDP6:[2a00::212:4b00:615:a1f7]:10683 » says to listen for UDP at port 10683 on the internal IPv4 connection, routes to a public IPv6 address at the given address and at the same port.
socat TCP6-LISTEN:10022,bind=[2a00::212:4b00:615:a1f7],reuseaddr,su=nobody,fork TCP4:10.0.0.10:10022 » says to listen for TCP under IPv6 at port 10022 on the given public IPv6 address, routes to IPv4 VPS internal IP stack at the same port.
Fair warning
This solution is persistent and will stay on every reboot.
However, if this does fail for some reason (e.g. updates that change systemd, socat or networking functions), you may need to create a script to run on every boot - crontab or similar scripting tools may be interesting for this - such as that the IPv4 is reinserted upon every boot on your VPS. If that is needed, it may be also a good idea to do the same to socat.
Solus VM 2 has cloud-init, which usually provides the network info upon every boot, erasing the previous information - unless a user disables it and automates the process of including an IP upon boot on their VPS (which, since it originates from userspace, never collides with cloud-init).
If everything else goes wrong, simply use our C-Servers GoBack backup service to restore your VPS to an earlier point in time, or simply reinstall the VPS using one of our OS templates, from scratch.
One thing is for sure
This solution will fix most issues with IPv4-only applications.