Yeah, there are ways to bypass iptables/ip6tables rules for localhost traffic. You can configure the rules to allow all traffic to and from the loopback interface (lo).
For IPv4, allow all traffic on the loopback interface:
sudo iptables -A INPUT -i lo -j ACCEPT sudo iptables -A OUTPUT -o lo -j ACCEPT
Make sure that localhost traffic is allowed:
sudo iptables -A INPUT -s 127.0.0.0/8 -j ACCEPT sudo iptables -A OUTPUT -d 127.0.0.0/8 -j ACCEPT
For IPv6, allow all traffic on the loopback interface:
sudo ip6tables -A INPUT -i lo -j ACCEPT sudo ip6tables -A OUTPUT -o lo -j ACCEPT
Make sure that localhost traffic is allowed:
sudo ip6tables -A INPUT -s ::1 -j ACCEPT sudo ip6tables -A OUTPUT -d ::1 -j ACCEPT
Save the rules
Debian/Ubuntu:
sudo sh -c "iptables-save > /etc/iptables/rules.v4" sudo sh -c "ip6tables-save > /etc/iptables/rules.v6"
Redhat:
sudo sh -c "iptables-save > /etc/sysconfig/iptables" sudo sh -c "ip6tables-save > /etc/sysconfig/ip6tables"
Good luck!
--append(-A) option for appending new rules, and not allow users to use the--insert(-I) option, for inserting new rules to the top of rules chain. When doing so, you use--insertoption only for superuser access to firewall rules and create rules for allowing traffic on localhost. You need to make sure that users have no sudo/root access and that users can only edit a restricted part of iptables configuration, which another superuser program/script then assembles with your superuser-iptables configuration and applies it.