LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-20-2022, 12:53 AM   #1
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Rep: Reputation: Disabled
iptables help please


I am just starting on IPTables and already running into issues


I have this


Code:
1- sudo iptables -P OUTPUT DROP
2- sudo iptables -A INPUT -p tcp -s 10.0.0.100 --dport 22 -j ACCEPT
3- sudo iptables -A INPUT -p tcp -s 0.0.0.0/0 --dport 22 -j DROP
4- sudo iptables -A INPUT -p tcp -s 10.0.0.155 -j ACCEPT
5- sudo iptables -A INPUT -p udp -s 10.0.0.155 -j ACCEPT
6- sudo iptables -A INPUT -s 10.0.0.0/24 -d 10.0.0.0/24 -j ACCEPT
7- sudo iptables -A OUTPUT -s 10.0.0.0/24 -d 10.0.0.0/24 -j ACCEPT

But this allows for example other IP addresses to connect via PORT 22 to the machine, which I thought I BLOCK via Rule Number 3, but my guess is that either RULE 6 or Rule 7 cancels this. Correct??

And If I remove RULES 6 and 7 then I even can't connect to the machine via SSH can't even PING IT!

Clarification, .100 is my PC, .155 is my NAS, my local subnet is 10.0.0.0/24

TiA

Edit: PS No other Rules exists (done a iptables -F and everything else INPUT/OUTPUT/FORWARD is set to accept before starting)

Last edited by iammike2; 05-20-2022 at 01:20 AM.
 
Old 05-20-2022, 02:35 AM   #2
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Rep: Reputation: Disabled
Why do you need firewall rules in LAN? What are you trying to achieve?
 
Old 05-20-2022, 02:58 AM   #3
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Thx,

just trying to understand IPtables.

If it already goes wrong with these basic rules, then wonder what is going to happen with OUTSIDE rules!

Last edited by iammike2; 05-20-2022 at 03:00 AM.
 
Old 05-20-2022, 03:04 AM   #4
elcore
Senior Member
 
Registered: Sep 2014
Distribution: Slackware
Posts: 1,753

Rep: Reputation: Disabled
1. When using -P OUTPUT DROP one must specify where OUTPUT is accepted. (remove rule 7 and output's all dropped)
2. When not using -P INPUT DROP then input is accepted and one must only specify which input is dropped.

So, your INPUT ACCEPT rules do nothing if -P INPUT (policy) is set to ACCEPT.
And your -P OUTPUT (policy) DROP will drop output of -p (protocol) icmp unless you specify the ACCEPT rule for icmp.

There's plenty of other stuff wrong with, but I hope this helps a bit.
 
1 members found this post helpful.
Old 05-20-2022, 03:53 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,313
Blog Entries: 3

Rep: Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723
Quote:
Originally Posted by iammike2 View Post
just trying to understand IPtables.
IPTables has been replaced by NFTables, so if you are just starting with packet filtering, you might skip IPTables.

https://wiki.nftables.org/wiki-nftab..._in_10_minutes

https://wiki.nftables.org/
 
1 members found this post helpful.
Old 05-20-2022, 08:13 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,637

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by iammike2 View Post
Thx,
just trying to understand IPtables. If it already goes wrong with these basic rules, then wonder what is going to happen with OUTSIDE rules!
Haven't you been working with iptables for three years now?

https://www.linuxquestions.org/quest...on-4175665271/
 
1 members found this post helpful.
Old 05-20-2022, 09:28 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,716

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
In addition, basically rules operate in order. -A appends the rule to the end of the chain so it depends on how they were added. Are you using a shell script or just typing them in on the command line? If using a script post its exact contents using code tags. To see the order run the command

iptables -L --line-numbers

To block ssh for incoming connections I would use:
iptables -A INPUT -i [interface name] -p tcp --dport 22 -j DROP

You also need to understand how basic server communications work. Basically the client talks to the server on one port, for ssh it is 22 by default and the server responds on another port. These ports are called ephemeral ports and it depends on the operating system but linux typically uses 32768–60999. This is why you need rule 6.

As posted with an output policy of drop nothing gets out without a specific rule. Much easier to learn if you reverse and use a policy of accept for output and drop for input.

You should also add input, output rules for lo.
 
1 members found this post helpful.
Old 05-20-2022, 12:03 PM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,662
Blog Entries: 4

Rep: Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943Reputation: 3943
I simply use shorewall to do the heavy lifting for me. I specify what I want using fairly-simple configuration files, and it spits out and applies the right set of rules. Perfect.
 
1 members found this post helpful.
Old 05-20-2022, 02:51 PM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,267
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
As michaelk points out, it is more useful and less error prone to view the rules as they actually exist in your kernel rather than as the commands used to insert them. To repeat how to do that:

Code:
iptables -L --line-numbers
Nftables is intended to replace iptables, but there is no urgency to change if you have some iptables knowledge. (I have found nftables a bit more difficult to work with than iptables, which may be due in part to my own old habits, but simply changing from one to the other does not instantly solve most problems.)

You have posted a set of rules then stated that they do not work, but have not clearly stated how you want them to work. You will find it a useful exercise to yourself, and in communicating your problems to others, to write out in simple human language how you want your rule set to work. For example:

Code:
My firewall should do the following -
    Accept incoming SSH on port 22 only from my PC (10.0.0.100), reject from anywhere else
    Accept all tcp and udp traffic between NAS (10.0.0.155) and this machine
    Reject everything else
You would then have a "specification" to implement with your rules and to communicate to others, and to test your results against. Then when you need to add some new traffic, start by adding it to the spec!
 
2 members found this post helpful.
Old 05-20-2022, 06:55 PM   #10
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Haven't you been working with iptables for three years now?

https://www.linuxquestions.org/quest...on-4175665271/

hahahaha. Not really only been playing with it but as you can see I still don't understand it!
 
Old 05-20-2022, 07:29 PM   #11
iammike2
Member
 
Registered: Oct 2018
Location: SE-Asia/Europe
Distribution: Raspi OS bullseye-arm64
Posts: 69

Original Poster
Rep: Reputation: Disabled
Thx Guys,

as always you gave me a lot to think about it.

I really like that suggestion by @Astrogeek to write down the "specification" first!!

Really appreciated. I hope one day I can help someone the same as you guys do!

 
  


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
iptables error in android: iptables-save and iptables-restore not working preetb123 Linux - Mobile 5 04-11-2011 01:56 PM
Please, Please,Please help with HD Cloning... knichel Linux - Software 7 09-16-2006 10:19 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
please please please help :'( ach1lles SUSE / openSUSE 2 02-28-2005 05:03 AM
Samba Help Please!!!! Please !!!! Please!!! Snake007uk Linux - Networking 18 07-10-2002 01:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:37 AM.

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