feat: add IPv4 support for WireGuard configuration

Updated configuration script to include IPv4 rules alongside existing IPv6 rules for iptables. This ensures that both protocols are properly handled, enhancing network versatility and compatibility. Enabled IPv4 forwarding in sysctl to support the new rules.
This commit is contained in:
Kumi 2024-07-18 17:26:12 +02:00
parent e192076414
commit b47e81791d
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -313,14 +313,17 @@ PersistentKeepalive = {persistent_keepalive}
ssh_execute_command(server_ip, f"echo '{wg_config}' > /etc/wireguard/wg0.conf")
ssh_execute_command(server_ip, "wg-quick up wg0")
# Configure ip6tables
ip6tables_rules = [
# Configure ip(6)tables
iptables_rules = [
"ip6tables -A FORWARD -i wg0 -j ACCEPT",
"ip6tables -A FORWARD -o wg0 -j ACCEPT",
"ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE",
"iptables -A FORWARD -i wg0 -j ACCEPT",
"iptables -A FORWARD -o wg0 -j ACCEPT",
"iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE",
]
for rule in ip6tables_rules:
for rule in iptables_rules:
ssh_execute_command(server_ip, rule)
@ -360,6 +363,7 @@ def main(provider, location, server_type):
"apt update",
"apt install -y wireguard",
"echo 'net.ipv6.conf.all.forwarding=1' >> /etc/sysctl.conf",
"echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf",
"sysctl -p",
]