Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Before making any firewall changes using iptables, the firewalld service is stop and disable.
i am learning iptables, so the first command i executed 'iptables -F', to flush / delete all the existing rules.
The next command, block incoming icmp, 'iptables -A INPUT -p icmp -j DROP'
The above command successfully executed.
But later when i restart the iptables service 'systemctl restart iptables' or reboot the system. The rules which i specified got deleted / removed and the default rules got applied which comes when i installed the iptables-service.
So i was thinking, is there any way to make the iptables rules permanent which i entered even after restarting or rebooting the system.
So i was thinking, is there any way to make the iptables rules permanent which i entered even after restarting or rebooting the system.
(By the way, blocking ICMP will break your networking. )
If you are working with iptables, then take a look at the package iptables-persistent. However, make sure your rules work and don't lock you out of your own system. You can do that with an at job which restores the last known good configuration or else using the utility iptables-apply which should already be there on your system.
However, since you mention you are just starting to learn, I would suggest ignoring iptables altogether and focusing on NFTables instead. It is quite a different interface to the packet filter, but an easier one and has an advantage in that it works from a single configuration file. See:
I don't know centos but debian based distros have a file /etc/rc.local that is run last after booting. If you can find the equivalent for your os then write your iptables instructions as a script and call it from your rc.local equivalent. Let the system do the initial setup and then modify it to what you want. iptables-restore somehow has never worked right for me. The same can be said and done with nftables.
That being said there is another perhaps better and more reliable way though much more complicated. Centos, I believe, has gone to systemd like most other distros. I cannot give you all the details, it is going to require some study and investigation on your part. but you can create a systemd unit file to run just before the network is up but after the firewall unit is run then enable that unit file. Read the man page for systemd and the man pages it refers to for more information. Then look at existing files and find one close to what you want and alter it to work for you. On debian based distros some of them are in /etc/systemd/system but most are in /lib/systemd/system. If you work it this way then you will be doing things the way the OS probably wants you to. I will warn you, though, that you will probably end up joining the crowd that hates systemd. It is not a nice, friendly system and it can be difficult to get information but it can be done and once you have succeeded it will all work smoothly and reliably for you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.