LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-14-2020, 09:29 PM   #1
hdg4
LQ Newbie
 
Registered: Jun 2020
Posts: 5

Rep: Reputation: Disabled
Smile iptables


Hi,
i did some changes to iptables and save the changes 'iptables-save'.

but after restarting the service or rebooting the system, the iptables are reset.

Is there any way to make iptables permanent even after restarting the service or rebooting the system ?


Thanks
 
Old 07-14-2020, 09:51 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,317
Blog Entries: 28

Rep: Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140Reputation: 6140
Please provide some context.

What distro/version are you using?

What procedure precisely did you use to make these changes?

What precisely was the text of the changes you attempted to make?

Thanks.
 
Old 07-14-2020, 10:06 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You make your changes permanent by running iptables-restore at system startup. Your distro may have a service that accomplishes this.

Quote:
Originally Posted by hdg4 View Post
but after restarting the service or rebooting the system, the iptables are reset.
Which service?

Last edited by berndbausch; 07-14-2020 at 10:09 PM.
 
Old 07-14-2020, 10:15 PM   #4
hdg4
LQ Newbie
 
Registered: Jun 2020
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for the reply.

Using centos 7.

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.

Thanks
 
Old 07-14-2020, 10:29 PM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
Quote:
Originally Posted by hdg4 View Post
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:

That is the direction the kernel is going and stuff which is broken in old, legacy iptables will likely remain broken.
 
1 members found this post helpful.
Old 07-14-2020, 11:57 PM   #6
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 07-15-2020, 12:05 AM   #7
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by hdg4 View Post
So i was thinking, is there any way to make the iptables rules permanent which i entered even after restarting or rebooting the system.
RHEL 7 has an iptables service, so I guess Centos does as well.

In short, you put your configuration in /etc/sysconfig/iptables and enable that service. For more detail, see the documentation.
 
  


Reply

Tags
iptables



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables error in android: iptables-save and iptables-restore not working preetb123 Linux - Mobile 5 04-11-2011 01:56 PM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
IPtables Log Analyzer from http://www.gege.org/iptables/ brainlego Linux - Software 0 08-11-2003 06:08 AM
iptables book wich one can you pll recomment to be an iptables expert? linuxownt Linux - General 2 06-26-2003 04:38 PM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration