How to make a iptables firewall rule

Dear experts here:

I have added a rule in /etc/sysconfig/iptables file for my iptables firewall but it failed when I restarted the service.

[root@titan ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules: iptables-restore: line 10 failed
                                                           [FAILED]
[root@titan ~]#


The file is as below, line number 8 is what I just added.

  1 # Generated by iptables-save v1.3.5 on Sat Jan 19 11:04:49 2013
  2 *filter
  3 :INPUT ACCEPT [179065:145346048]
  4 :FORWARD ACCEPT [0:0]
  5 :OUTPUT ACCEPT [159509:132200597]
  6 -A INPUT -p tcp -m state --state NEW -m tcp --dport 8000 -j ACCEPT
  7 -A INPUT -p tcp -m state --state NEW -m tcp --dport 8000 -j ACCEPT
  8 -A INPUT -p udp -s 10.10.4.0/22 -m state --state NEW -m udp --dport 123 -j ACCEPT
  9 -A INPUT -p tcp -m state --state NEW -m tcp --dport 8000 -j DROP
 10 COMMIT
 11 # Completed on Sat Jan 19 11:04:49 2013
 12

Open in new window

Jason YuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason YuAuthor Commented:
[root@titan ~]# vi /etc/sysconfig/iptables
[root@titan ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

[root@titan ~]#
0
MazdajaiCommented:
What kernel are you running?

The line looks fine. Try to uncomment / comment the line and run:

service iptables reload 

Open in new window


If that did not work try using system-config-firewall-tui to add the rule.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jason YuAuthor Commented:
[root@titan ~]# cat /etc/*-release
CentOS release 6.3 (Final)
CentOS release 6.3 (Final)
CentOS release 6.3 (Final)
[root@titan ~]#
0
Jason YuAuthor Commented:
Interesting, it's working now.

[root@titan ~]# service iptables reload
[root@titan ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8000
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8000
3    ACCEPT     udp  --  10.10.4.0/22         0.0.0.0/0           state NEW udp dpt:123
4    DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8000

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

[root@titan ~]#
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.