• Forward traffic.

    echo "net.ipv4.ip_forward = 1
    net.ipv6.conf.all.forwarding = 1" | sudo tee /etc/sysctl.d/routing.conf > /dev/null
    sudo sysctl --system
    
  • Masquerade.

    • For nftables, add table below to /etc/nftables.conf and then run sudo systemctl enable nftables && sudo systemctl start nftables.

      table inet nat {
      	chain postrouting_srcnat {
      		type nat hook postrouting priority srcnat; policy accept;
      		oifname "eth0" counter masquerade
      	}
      }
      
    • For iptables.

      sudo iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
      sudo iptables-save | sudo tee /etc/iptables/rules.v4 > /dev/null