I have a server with iptables rules setup. I want to use the same rules on a new server. Can I somehow copy/paste them or download/re-upload them using terminal? I'm on Ubuntu.
Yes. Save it as follows:
sudo iptables-save > iptables.conf
Restore it as follows:
sudo iptables-restore < iptables.conf
And since it’s all in a text file—in this case iptables.conf
—you can then do further editing and tweaks based on machine specific parameters and scenarios.
Also, if you plan on retaining rules on reboot, consider having iptables-persistent
installed and then copying the rules into the area that iptables-persistent
loads them:
sudo cp iptables.conf /etc/iptables/rules.v4
Above is for IPv4 rules. For for IPV6 rules do this:
sudo cp iptables.conf /etc/iptables/rules.v6