3

I have tried many similar question like below, in my case I used VM with Debian OS in VirtualBox:

  1. https://serverfault.com/questions/129086/how-to-start-stop-iptables-on-ubuntu
  2. Why do iptables rules disappear when restarting my Debian system?
  3. https://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules
  4. https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-iptables-on-ubuntu-14-04

I have tried to flush the iptables rules with these command:

sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

Follows with these command:

sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X

I have tried to:

iptables-save > /etc/iptables/rules.v4
iptables-save > /etc/iptables/rules.v6

When I reboot the machine, it back to the old rules again... I still got the same rules. I tried to use iptables-save, and I got these message.

# Generated by iptables-save v1.4.21 on Wed Mar 28 03:44:14 2018
*nat
:PREROUTING ACCEPT [127:23299]
:INPUT ACCEPT [14:1996]
:OUTPUT ACCEPT [32:1947]
:POSTROUTING ACCEPT [32:1947]
:OUTPUT_direct - [0:0]
:POSTROUTING_ZONES - [0:0]
:POSTROUTING_ZONES_SOURCE - [0:0]
:POSTROUTING_direct - [0:0]
:POST_public - [0:0]
:POST_public_allow - [0:0]
:POST_public_deny - [0:0]
:POST_public_log - [0:0]
:PREROUTING_ZONES - [0:0]
:PREROUTING_ZONES_SOURCE - [0:0]
:PREROUTING_direct - [0:0]
:PRE_public - [0:0]
:PRE_public_allow - [0:0]
:PRE_public_deny - [0:0]
:PRE_public_log - [0:0]
-A PREROUTING -j PREROUTING_direct
-A PREROUTING -j PREROUTING_ZONES_SOURCE
-A PREROUTING -j PREROUTING_ZONES
-A OUTPUT -j OUTPUT_direct
-A POSTROUTING -j POSTROUTING_direct
-A POSTROUTING -j POSTROUTING_ZONES_SOURCE
-A POSTROUTING -j POSTROUTING_ZONES
-A POSTROUTING_ZONES -g POST_public
-A POST_public -j POST_public_log
-A POST_public -j POST_public_deny
-A POST_public -j POST_public_allow
-A PREROUTING_ZONES -g PRE_public
-A PRE_public -j PRE_public_log
-A PRE_public -j PRE_public_deny
-A PRE_public -j PRE_public_allow
COMMIT
# Completed on Wed Mar 28 03:44:14 2018
# Generated by iptables-save v1.4.21 on Wed Mar 28 03:44:14 2018
*mangle
:PREROUTING ACCEPT [4925:1051078]
:INPUT ACCEPT [4925:1051078]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4791:1080206]
:POSTROUTING ACCEPT [4791:1080206]
:FORWARD_direct - [0:0]
:INPUT_direct - [0:0]
:OUTPUT_direct - [0:0]
:POSTROUTING_direct - [0:0]
:PREROUTING_ZONES - [0:0]
:PREROUTING_ZONES_SOURCE - [0:0]
:PREROUTING_direct - [0:0]
:PRE_public - [0:0]
:PRE_public_allow - [0:0]
:PRE_public_deny - [0:0]
:PRE_public_log - [0:0]
-A PREROUTING -j PREROUTING_direct
-A PREROUTING -j PREROUTING_ZONES_SOURCE
-A PREROUTING -j PREROUTING_ZONES
-A INPUT -j INPUT_direct
-A FORWARD -j FORWARD_direct
-A OUTPUT -j OUTPUT_direct
-A POSTROUTING -j POSTROUTING_direct
-A PREROUTING_ZONES -g PRE_public
-A PRE_public -j PRE_public_log
-A PRE_public -j PRE_public_deny
-A PRE_public -j PRE_public_allow
COMMIT
# Completed on Wed Mar 28 03:44:14 2018
# Generated by iptables-save v1.4.21 on Wed Mar 28 03:44:14 2018
*security
:INPUT ACCEPT [4826:1030935]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4814:1084121]
:FORWARD_direct - [0:0]
:INPUT_direct - [0:0]
:OUTPUT_direct - [0:0]
-A INPUT -j INPUT_direct
-A FORWARD -j FORWARD_direct
-A OUTPUT -j OUTPUT_direct
COMMIT
# Completed on Wed Mar 28 03:44:14 2018
# Generated by iptables-save v1.4.21 on Wed Mar 28 03:44:14 2018
*raw
:PREROUTING ACCEPT [4949:1054264]
:OUTPUT ACCEPT [4815:1084545]
:OUTPUT_direct - [0:0]
:PREROUTING_direct - [0:0]
-A PREROUTING -j PREROUTING_direct
-A OUTPUT -j OUTPUT_direct
COMMIT
# Completed on Wed Mar 28 03:44:14 2018
# Generated by iptables-save v1.4.21 on Wed Mar 28 03:44:14 2018
*filter
:INPUT ACCEPT [2653:591941]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2649:609004]
COMMIT
# Completed on Wed Mar 28 03:44:14 2018

What I want is like the rules below. I have set my rules.v4 to these command:

# Generated by iptables-save v1.4.21 on Tue Mar 27 02:48:59 2018
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
COMMIT
# Completed on Tue Mar 27 02:48:59 2018

But whenever I reboot the system, I always got the previous rules...

What could go wrong with my configuration? Am I missed something?

I have tried to uninstall iptables-persistent and reinstall it again, but I still got the same rules...

gagantous
  • 225
  • Firstly, you need define script in systemd, pre-up, post-down rules in /etc/network/interfaces or something else that set iptables rules. Follow this link: https://wiki.debian.org/DebianFirewall . It must be helpful. – Yurij Goncharuk Mar 28 '18 at 08:52

1 Answers1

2

Use the following command to save the IPV6 table:

ip6tables-save > /etc/iptables/rules.v6

To restore the IPV6 table use:

ip6tables-restore < /etc/iptables/rules.v6

The command iptables-save and iptables-restore is used only to manage the IPV4 table.

see man iptables-save :

  iptables-save — dump iptables rules to stdout
  ip6tables-save — dump iptables rules to stdout

and man iptables-restore

 iptables-restore — Restore IP Tables
 ip6tables-restore — Restore IPv6 Tables
GAD3R
  • 66,769