-1

I was updating my iptables in CentOS 6.4

I added port 8080 to iptables and ran iptables save. However now when I view my iptables all it is showing me is:

# Generated by iptables-save v1.4.7 on Wed Apr  9 13:46:25 2014
*filter
:INPUT ACCEPT [135:9225]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [85:12488]
COMMIT
# Completed on Wed Apr  9 13:46:25 2014

Is this a summarised view or have I saved my iptables horribly wrong?

iptables -L -n -v

Chain INPUT (policy ACCEPT 177 packets, 14590 bytes)
  pkts bytes target prot opt in out source destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) 
  pkts bytes target prot opt in out source destination 

Chain OUTPUT (policy ACCEPT 135 packets, 22979 bytes) 
  pkts bytes target prot opt in out source destination 
9
  • What is the output for iptables -L -n -v ?
    – krisFR
    Apr 9, 2014 at 4:01
  • Not much: Chain INPUT (policy ACCEPT 177 packets, 14590 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 135 packets, 22979 bytes) pkts bytes target prot opt in out source destination
    – Max
    Apr 9, 2014 at 4:42
  • I have updated your question with this. Seems that your rules are not here...How did you setup them ? If you saved them with iptables-save try to restore them with iptables-restore
    – krisFR
    Apr 9, 2014 at 4:59
  • Used vi to edit the iptables and then :wq However I saw another user suggested using iptables save so I ran that. Now it is like this
    – Max
    Apr 9, 2014 at 5:01
  • So you have a script to manage your iptables rules ? well, run it
    – krisFR
    Apr 9, 2014 at 5:04

2 Answers 2

1

Using iptables-save without arguments will output all rules directly from the kernel. If it shows no rules, I would trust that you really do not have any rules. What command did you use to add a rule? What did you do after that, before running iptables-save?

5
  • Yes I used it without arguments. I used vi and inserted rules in the iptables file. Didn't do anything between than and iptables save (no dash)
    – Max
    Apr 9, 2014 at 6:51
  • Then you need to load that file; in it's simplest form: iptables-restore < /path/to/file/you/edited
    – fukawi2
    Apr 9, 2014 at 7:05
  • So you did not even load the updated iptables file into the kernel? That would explain why the rule is not in the kernel. I think the command to load it like it happens during boot would be service iptables start, but it may be better to use iptables-restore < filename to load it. Remember that if you are doing this over a network connection, you could potentially kick yourself off the machine, so be careful.
    – kasperd
    Apr 9, 2014 at 7:08
  • I've always edited the file directly and saved in vi. Is that incorrect?
    – Max
    Apr 10, 2014 at 2:44
  • Red Hat Linux would load rules from /etc/sysconfig/iptables at boot. The same probably applies to many of the distributions based on Red Hat Linux.
    – kasperd
    Apr 10, 2014 at 6:05
1

The persistent iptable rules for CentOS6 is stored under /etc/sysconfig/iptables. iptables-save will print out rules to STDOUT which is not what you want.

If you make changes to running iptables config and would like to make those persistent, then instead of running iptables-save, do

/sbin/service iptables save
4
  • See my comment and the OPs reply - it looks like this is just what they did.
    – user9517
    Apr 9, 2014 at 7:55
  • OK then it should just work, unless there were syntax errors in the iptables rule to add,or if the save command was run with insufficient perms.
    – Petter H
    Apr 9, 2014 at 8:06
  • It looks like the OP didn't have any rules loaded. They edited their /etc/sysconfig/iptables file, then ran service iptables save and overwrote their rules ::shurgs::
    – user9517
    Apr 9, 2014 at 8:11
  • that would explain the observed behaviour.
    – Petter H
    Apr 9, 2014 at 8:14

Not the answer you're looking for? Browse other questions tagged .