LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-01-2019, 08:07 AM   #1
OlgaM
Member
 
Registered: Mar 2019
Distribution: Debian Bullseye
Posts: 65

Rep: Reputation: Disabled
Nftables rules and tables dissapiered after reboot!


Hello, dear forum! Many times i used this place to got info about debian and all my question was resolved. But with nftables i got stuck. I use Debian Buster and tried nftables this way:

1. First, i blocked iptables to prevent mess

Code:
iptables -F
ip6tables -F
2. After that i created my ruleset

nft add table inet filter
and so on

3. I saved my ruleset

Code:
sudo nft list ruleset > /etc/nftables.conf
And it was saved right in place/

4. I installed netfilter-persistent and this command said me OK

Code:
sudo service netfilter-persistent save
But when i reboot my nftables rules and tables dissapiered!

I googled a lot for a few days but nothing works. If you have working solution, please, share it!
 
Old 03-01-2019, 07:31 PM   #2
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
Although I am not aware of netfilter-persistent and don't know what it does, it shouldn't be necessary. Buster, as I understand it, uses systemd, not sysvinit. So all you should need is nftables itself which is configured through /etc/nftables.conf.

Under systemd installing and/or running a service is not enough to have it activated across sessions/reboots. You also have to enable it.

Set up nftables the way you want it through /etc/nftables.conf. You start and stop it by
Code:
sudo systemctl start nftables
and
Code:
sudo systemctl stop nftables
When it runs the way you want it to, enable it with
Code:
sudo systemctl enable nftables
Now when you boot nftables will automatically start with the configuration in your /etc/nftables.conf. Changing the conf file will change the setup the next time it initializes, of course.

By the way, if the systemd commands claim nftables is masked then remove iptables and install nftables.
 
1 members found this post helpful.
Old 03-02-2019, 06:30 AM   #3
OlgaM
Member
 
Registered: Mar 2019
Distribution: Debian Bullseye
Posts: 65

Original Poster
Rep: Reputation: Disabled
That's works. Agillator, thank you very much!
I found info about netfilter-persistent in internet.
i think it is plugin and does the same job as
Quote:
sudo systemctl enable nftables
. Now i see that i don't need extra plugin and this plugin doesn't work for me.

I am not shure - should i put

Quote:
iptables -F
ip6tables -F
at the beginning of nftables.conf file or enter it manually after reboot?
 
Old 03-02-2019, 11:22 AM   #4
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
First, the commands you showed for flushing the firewall are iptables commands and you are using nftables so they don't apply!

At the beginning of your nftables.conf file you should put
Code:
flush ruleset
That flushes everything anytime you start nftables. You don't need to do anything else unless you are entering firewall rules manually from the terminal or through a script. Then your first instruction would be
Code:
sudo nft flush ruleset
but it is easiest to just to edit your nftables.conf file and restart through systemctl. That actually saves a lot of trouble.

A sample, bare bones configuration (/etc/nftables.conf) that accepts everything but is a good starting point would be
Code:
#!/usr/sbin/nft -f

flush ruleset

table inet filter {
   chain input {
      type filter hook input priority 0; policy accept;
   }

   chain forward {
      type filter hook forward priority 0; policy accept;
   }

   chain output {
      type filter hook output priority 0; policy accept;
   }
}
This, in effect, removes the firewall since it accepts everything from anywhere but is a good neutral starting point for programming a firewall. But, if you are going to program your firewall yourself you really need to get a good reference. There are a number of good books available. The one I use is "Linux Firewalls" Fourth Edition by Steve Suehring available through Amazon. It isn't cheap, none of them are, but that one is complete and deals with both iptables and nftables.
 
1 members found this post helpful.
Old 03-03-2019, 10:31 AM   #5
OlgaM
Member
 
Registered: Mar 2019
Distribution: Debian Bullseye
Posts: 65

Original Poster
Rep: Reputation: Disabled
Thank you a lot for Linux Security book! I am ready to pay for book, because i spent lots of money when try to clean my hacked laptop in service. Now i search for info by myself. It's the best way i think. I put
Quote:
flush ruleset
at the beginning of nftables.conf file.

I put also counter

Quote:
type filter hook input priority 0; counter; policy drop
Because i need to understand where i have a gap in my system. And i was surprised when i found this

Quote:
#sudo nft list ruleset
#chain output {
counter packets 321 bytes 21522;
}
How it can be possible if my laptop on airplan mode, bluetooth and wi-fi doesnt'work...

Thank you very much for your explanation, it's very helpfull!

If you advice me good linux system book i will be very greatfull.

Last edited by OlgaM; 03-03-2019 at 10:49 AM.
 
Old 03-03-2019, 10:31 AM   #6
OlgaM
Member
 
Registered: Mar 2019
Distribution: Debian Bullseye
Posts: 65

Original Poster
Rep: Reputation: Disabled
Thank you a lot for Linux Security book! I am ready to pay for book, because i spent lots of money when try to clean my hacked laptop in service. Now i search for info by myself. It's the best way i think. I put
Quote:
flush ruleset
at the beginning of nftables.conf file.

I put also counter

Quote:
type filter hook input priority 0; counter; policy drop
Because i need to understand where i have a gap in my system. And i was surprised when i found this

Quote:
#sudo nft list ruleset
#chain output {
counter packets 321 bytes 21522;
}
How it can be possible if my laptop on airplan mode, bluetooth and wi-fi doesnt'work...

Thank you very much for your explanation, it's very helpfull!

If you advice me good linux system book i will be very greatfull.

Last edited by OlgaM; 03-03-2019 at 10:49 AM.
 
Old 03-03-2019, 11:53 AM   #7
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
At least part of what you are seeing is the work the system is always doing behind the scenes. One thing you probably have not done is allowed the loopback interface, lo. The system uses this to communicate with itself, so if you have set policies to DROP and not allowed the firewall to accept traffic on lo you will have lots of drops and also will find that many things on the system do not work right. One of the things any guide to firewalls using any system will tell you to do is to add a rule accepting traffic on the lo interface. Programming a firewall from scratch can really be somewhat complicated which is why you really do need a good guide to go by.

Another gotcha that can bite: opening ssh. Assume you are working on a remote computer with no physical access. You are using ssh to access it. You decide to set your policies to be fairly restrictive which is a good idea (AT THE RIGHT TIME!). So, you set INPUT and FORWARD to DROP which keeps the world from getting in unwanted and set OUTPUT to ACCEPT which allows you to contact the world. Makes sense EXCEPT you have now blocked all external ssh input including yourself! You are now locked out with no way to get in unless you have physical access to open things up again. And even if you do give yourself ssh access first you still have problems because the outside world cannot respond to your contacts so you have to enable what is called 'Connection Tracking' which requires a system module to be turned on and the appropriate rules added to the firewall. It is things like this that you would not know unless you have a good guide to follow at least the first time. Your willingness to buy a book is excellent. The information can be found for free on the internet but having a book makes it always available and at your fingertips.
 
1 members found this post helpful.
Old 03-05-2019, 11:20 AM   #8
OlgaM
Member
 
Registered: Mar 2019
Distribution: Debian Bullseye
Posts: 65

Original Poster
Rep: Reputation: Disabled
Agillator, thank you for lot's of userful information! I set all connections to DROP, but in OUTPUT chain i still see number of packets. So, my nftables.conf file looks like that:

Quote:
#!/usr/sbin/nft -f

flush ruleset

table inet filter {
chain input {
type filter hook input priority 0; counter; policy drop;
}

chain forward {
type filter hook forward priority 0; counter; policy drop;
}

chain output {
type filter hook output priority 0; counter; policy drop;
}
}
Thank you for point to lo interface. I got lot's of userful info from your posts and need time to learn it.

So, there is two ways:

1. System uses this to communicate with itself.

2. Laptop still on remote control and packets goes through it despite on OUTPUT DROP. I think i need use 'Connection Tracking' as you said and admin tools. I need to see where outgoing packets starting, server, protocol, port, network frequency et so on.

Starting reading book
 
Old 10-20-2019, 07:28 AM   #9
penguu
LQ Newbie
 
Registered: Oct 2019
Posts: 1

Rep: Reputation: Disabled
Question

hello i see first result in google

is also more book for nftable recommendation??


good for learn
 
Old 02-10-2021, 01:52 PM   #10
sman123
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Rep: Reputation: Disabled
Try this:

Code:
nft list ruleset > /etc/nftables.rules
and then edit /etc/nftables.conf to add an include statement.

Code:
table inet filter {
	chain input {
		type filter hook input priority 0; policy accept;
	}

	chain forward {
		type filter hook forward priority 0; policy accept;
	}

	chain output {
		type filter hook output priority 0; policy accept;
	}
}

include "/etc/nftables.rules"

Last edited by sman123; 02-10-2021 at 01:58 PM.
 
  


Reply



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
Help to Convert some iptables NAT rules to nftables netpumber Linux - Server 1 03-08-2017 03:51 PM
nftables and VPN joni1101 Linux - Networking 2 11-30-2015 05:22 PM
[SOLVED] nftables add table and chains kikilinux Linux - Security 6 12-18-2014 02:14 PM
auditctl -l not showing any rules even though i have rules written in audit.rules alphaguy Linux - Security 1 02-07-2014 05:28 PM
LXer: Tables of Contents, Indexes and Other Special Tables in Scribus LXer Syndicated Linux News 0 05-13-2011 05:30 AM

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

All times are GMT -5. The time now is 09:54 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