Do you need a static IPv4 for your self-hosted services but only have a Carrier-Grade NAT (CGNAT) IPv4 from your ISP? If your router shows an IPv4 similar to 100.64.x.x, then you are sharing your IPv4 address with other customers. However, your ISP has assigned you an IPv6 subnet.
Set up a NAT bridge using an inexpensive VPS (€1/month) or a free Oracle FreeTier VPS to forward all IPv4 traffic. The VPS acts as a gateway, and traffic is encrypted using a WireGuard VPN tunnel.
apt-get update && apt-get upgrade -ycurl -L https://install.pivpn.io | baship anano /etc/wireguard/wg0.confAdd the following line after ListenPort (replace your_interface with the actual interface name):
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o your_interface -j MASQUERADErebootpivpn -aEnter a profile name, e.g., home_network.
nano /etc/wireguard/wg0.confAdd your home network's IP range under AllowedIPs:
AllowedIPs = 10.70.193.2/32, 192.168.8.0/24cat /etc/wireguard/configs/home_network.confnano /etc/sysctl.confChange:
#net.ipv4.ip_forward = 1to:
net.ipv4.ip_forward = 1nano /ip.shAdd:
#!/bin/bash
iptables -t nat -A POSTROUTING -j MASQUERADEiptables -A PREROUTING -t nat -p tcp --match multiport ! --dports 22,51820 -j DNAT --to-destination 192.168.8.14
iptables -A PREROUTING -t nat -p udp --match multiport ! --dports 22,51820 -j DNAT --to-destination 192.168.8.14iptables -t nat -A PREROUTING -p "tcp" --dport "80" -j DNAT --to-destination "192.168.8.14":"80"sudo apt install netfilter-persistent
sudo netfilter-persistent save
sudo systemctl enable netfilter-persistentchmod +x /ip.sh
crontab -eAdd:
@reboot /ip.shrebootapt-get update && apt-get upgrade -y && apt-get install -y wireguard openresolv wireguard-dkmsnano /etc/wireguard/wg0.confPostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -o your_interface -j MASQUERADE
PostUp = echo 1 > /proc/sys/net/ipv4/ip_forwardPersistentKeepalive = 25systemctl enable wg-quick@wg0rebootIf using IONOS, allow the WireGuard port in the firewall settings.
Edit wg0.conf:
DNS = 9.9.9.9Disable stub resolver:
/etc/systemd/resolved.conf.d/disable-stub.confAdd:
[Resolve]
DNSStubListener=noRestart systemd-resolved:
sudo systemctl restart systemd-resolvedpivpn offservice wg-quick@wg0 stopTo prevent unauthorized access, use SSH key authentication and dynamically allow only your current IP via DNS lookup.
nano /dynamic-ssh-access.shPaste the provided script. https://github.com/JonaxScript/DynDNS-SSH-Iptables
*/5 * * * * root /path/to/dynamic-ssh-access.shYour self-hosted services are now accessible via the VPS IPv4 while traffic remains encrypted through WireGuard. Adjust firewall rules and NAT settings as needed.