replace these commands with iptables for ubuntu
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --zone=public --add-port=443/tcp --permanent
sudo firewall-cmd --zone=public --add-port=12345/tcp --permanent
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
Assistant
To accomplish the same tasks with iptables on Ubuntu that you were accomplishing with firewall-cmd on systems that utilize firewalld, you would use the iptables command to append rules allowing incoming traffic on TCP ports 80, 443, 12345, and 8080. Unlike firewall-cmd, iptables does not have a concept of "zones" by default, and changes are not automatically permanent—you'll need to save and reload them after reboot manually or by using a tool.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here is how you can add these rules with iptables:
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 12345 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
This appends (-A) rules to the INPUT chain to ACCEPT packets destined to the specified ports.
Making iptables Rules Permanent on Ubuntu
To make iptables rules persistent across reboots in Ubuntu, you'll need to save your current iptables rules to a file and then ensure they are reloaded when the system boots. Ubuntu uses iptables-persistent package for this purpose:
Install iptables-persistent (if it's not already installed):
During installation, iptables-persistent will ask if you want to save current IPv4 and IPv6 rules; you should select "Yes" if you have already applied your iptables rules.
If you didn’t save rules during installation or have updated your rules, you can save them manually:
Save the current iptables rules:
To save IPv4 rules:
sudo iptables-save > /etc/iptables/rules.v4
To save IPv6 rules (if needed):
sudo ip6tables-save > /etc/iptables/rules.v6
This manual method using iptables-save and ip6tables-save outputs your current iptables (and ip6tables for IPv6) configurations to files which iptables-persistent will automatically load on startup.
This way, your iptables configuration for opening ports 80, 443, 12345, and 8080 will persist across system reboots, mirroring the --permanent flag functionality of firewall-cmd.