How can I make iptables service start automatically after reboot on CenOS/RHEL7?

52

Solution 1

Although this question is old, I came across the same issue and discovered the solution here.

systemctl mask firewalld
systemctl stop firewalld

Basically firewalld conflicts iptables and so will prevent iptables from loading:

# cat /usr/lib/systemd/system/firewalld.service 
[Unit]
Description=firewalld - dynamic firewall daemon
Before=network.target
Before=libvirtd.service
Before=NetworkManager.service
Conflicts=iptables.service ip6tables.service ebtables.service

...

I was able to solve this by masking firewalld to ensure it does not start automatically and will never be started thereafter. Of course you will need to ensure iptables is enabled:

systemctl enable iptables

Solution 2

init scripts are gone. Now its systemctl. Its out there in all CentOS7 docs. To chkconfig ipatables or to start iptables service at startup you need to use this:-

systemctl enable iptables

You should checkout simple things to be known about systemctl at the Cyberciti docs on iptables.

Share:
52

Related videos on Youtube

iRunner
Author by

iRunner

Updated on September 18, 2022

Comments

  • iRunner
    iRunner over 1 year

    I am developing an android app.I am using RelativeLayout for login page and adding a button at the bottom using android:layout_alignParentBottom="true", but whenever i am type into login box keypad is getting displayed and that login button is also getting shifted above the keypad.I want that button always to remain at the bottom.

    How to achieve that?

  • iRunner
    iRunner about 11 years
    Awesome.thnks a lot.Working fine now.
  • Dave
    Dave over 9 years
    Hi flemingovirus, I did trying what you have suggested and also looked at the link but it is still not working. Any ideas? thanks
  • Dave
    Dave over 9 years
    [root@CentOS-7}# rpm -ql iptables-services.x86_64 /etc/sysconfig/ip6tables /etc/sysconfig/iptables /usr/lib/systemd/system/ip6tables.service /usr/lib/systemd/system/iptables.service /usr/libexec/initscripts/legacy-actions/ip6tables /usr/libexec/initscripts/legacy-actions/ip6tables/panic /usr/libexec/initscripts/legacy-actions/ip6tables/save /usr/libexec/initscripts/legacy-actions/iptables /usr/libexec/initscripts/legacy-actions/iptables/panic /usr/libexec/initscripts/legacy-actions/iptables/save /usr/libexec/iptables /usr/libexec/iptables/ip6tables.init /usr/libexec/iptables/iptables.init
  • Dave
    Dave over 9 years
    there is no dpkg so I used rpm instead. is this output sensible? thanks
  • flemingovirus
    flemingovirus over 9 years
    Oh I am so sorry, my mind got mixed up with another question. ok forget about the location of iptables. So what do you get when you use systemctl? Post the output on your question.
  • Dave
    Dave over 9 years
    thanks but I get the following error: "error reading information on service iptables: No such file or directory" Also, to me it looks like a really complicated way to do this. Is there no other way to implement this in CentOS. In the end I am only trying to use it as a standard web/mail server. How can one use a web server if port 80 and 443 are not opened by default. Am I doing something wrong?
  • flemingovirus
    flemingovirus over 9 years
    @Dave the output of systemctl says it has been put for startup. Check with a reboot.
  • Dave
    Dave over 9 years
    Hi yes I did several times but no luck unfortunately
  • Dave
    Dave over 9 years
    I cannot understand why these rules are forgotten after reboot
  • amir jj
    amir jj over 9 years
    iptables is builtin in Centos. i think you had a problem in installation. please try $sudo service iptables status and write output in comment.
  • Davor Cubranic
    Davor Cubranic almost 4 years
    The document you reference does not say that firewalld prevents iptables from loading, where did you get that idea?
  • Davor Cubranic
    Davor Cubranic almost 4 years
    Could be interaction with firewald? (See @zanegray's answer.)