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 - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2021, 07:37 AM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,813

Rep: Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958

A VB NAT connection its just like a simple router. All outgoing traffic but no new connections on the input side.
iptables are flushed but if policy is dropped nothing is going work.

Last edited by michaelk; 06-09-2021 at 07:52 AM.
 
Old 06-10-2021, 02:31 AM   #17
B.L.R
LQ Newbie
 
Registered: Jun 2021
Posts: 12

Original Poster
Rep: Reputation: Disabled
Success!

Alright. So, it works now!

Turns out all I needed to do was add "NEW" to my OUTPUT UDP DNS port.

Then I started stripping things off. I found that I, surprisingly, could remove all DNS port access on my INPUT. No problem.

Also, no need to have this on OUTPUT, apparently:
iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT

Anyone see anything else worth stripping?

Again, what I'm trying to achieve is to have access to web traffic through OUTPUT, with only ESTABLISHED connections coming in through INPUT.

Current settings from iptables-save are attached.

/ BLR
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2021-06-10 at 09.18.12.png
Views:	16
Size:	118.6 KB
ID:	36568  
 
Old 06-10-2021, 02:34 AM   #18
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,378
Blog Entries: 3

Rep: Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772
On the INPUT chain, you might need RELATED in addition to ESTABLISHED.

On the OUTPUT chain, you will probably need NTP to keep the time in sync.
 
Old 06-10-2021, 02:37 AM   #19
B.L.R
LQ Newbie
 
Registered: Jun 2021
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
On the INPUT chain, you might need RELATED in addition to ESTABLISHED.

On the OUTPUT chain, you will probably need NTP to keep the time in sync.
NTP is not required for this assignment, but I will modify this for my personal use afterwards and take it into account. Thanks!

Why RELATED? If it aint broke...
 
Old 06-10-2021, 02:53 AM   #20
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,378
Blog Entries: 3

Rep: Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772
Quote:
Originally Posted by B.L.R View Post
Why RELATED? If it aint broke...
It is broken.

One example would be that RELATED is needed for receiving an ICMP error in response to an attempted outgoing message.

If you are going to adapt the filter rules for your own use later, then I'll say yet again that you might look at nftables. These would be of use for that:

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

as well as the utility iptables-translate

After you get your grade be sure to get some entertainment out of asking why iptables is still being taught instead of keeping up with current developments.
 
1 members found this post helpful.
Old 06-11-2021, 04:20 AM   #21
B.L.R
LQ Newbie
 
Registered: Jun 2021
Posts: 12

Original Poster
Rep: Reputation: Disabled
Now I stripped it even more, and still have access to internet. I must have misunderstood something here, clearly, because to me this should drop all incoming packets and make me loose my connection.
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2021-06-11 at 11.17.39.png
Views:	12
Size:	107.4 KB
ID:	36576  
 
Old 06-11-2021, 05:05 AM   #22
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,378
Blog Entries: 3

Rep: Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772
It's getting more and more broken.

Try clearing the counters

Code:
iptables -Z
and then add a line to log outgoing packets right before the get dropped and watch the logs.
 
Old 06-11-2021, 06:24 AM   #23
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,813

Rep: Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958Reputation: 5958
ESTABLISHED The packet is associated with a connection which has seen packets in both directions.

Since you are allowing a new,established for the output, traffic is now established so
iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT

becomes a generic rule for all incomming traffic that is already established or originated from that computer. As an example you can ssh to another computer but can not ssh from another computer to this one. A "generic" established rule allows any input from other services like NTP, network printing or updates.

Where as
iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate ESTABLISHED -j ACCEPT

Only allows traffic established on a specific port i.e ssh.

A I understand how iptables works...
 
Old 07-02-2021, 12:18 AM   #24
MikeDeltaBrown
Member
 
Registered: Apr 2013
Location: Arlington, WA
Distribution: Slackware
Posts: 96

Rep: Reputation: 10
Just to help clarify:
During the TCP handshake, you send a connection request to an outside server; that is NEW.
The server sends back a ACK+SYN; that is RELATED.
You send a ACK back to the server that you are SYNc'd; you are now ESTABLISHED.

From the other direction:
BadActor tries to connect to your server; that is NEW..... -j DROP

You don't want NEW -j ACCEPT on the INPUT chain unless it also references a specific port/service that you are knowingly making available.
 
1 members found this post helpful.
Old 07-02-2021, 04:24 AM   #25
B.L.R
LQ Newbie
 
Registered: Jun 2021
Posts: 12

Original Poster
Rep: Reputation: Disabled
Hello everybody.

I wanted to share with you, for posterity's sake, the solution I used.

Again, the goal being to ALLOW only ESTABLISHED connections on the INPUT, on ports required to connect to webpages on the internet. Only via OUTPUT should NEW connections be possible.

It seems I misunderstood some concepts along the way, hopefully the rules are a little bit clearer now.

If you think there's something that I should add / strip away, please feel free to come with suggestions.

/ BLR
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2021-06-14 at 13.53.04.png
Views:	6
Size:	127.8 KB
ID:	36726  
 
Old 07-02-2021, 10:44 PM   #26
MikeDeltaBrown
Member
 
Registered: Apr 2013
Location: Arlington, WA
Distribution: Slackware
Posts: 96

Rep: Reputation: 10
I think this was mentioned above, but it probably got lost with the flood of information but your INPUT lines should be checking the connection tracking state (ctstate) of the SOURCE port not the DESTINATION.
--dport should be --sport on all INPUT lines.

To show this, you can make an SSH connection to some computer. Then, in another window, run:
Code:
netstat -p | grep ssh
When I run this I get
Code:
tcp        0      0 192.168.66.2:41232      192.168.66.195:ssh  ESTABLISHED 32596/ssh
This shows that my local host is using port 41232 and is connected to the ssh port (22) on the server. Your INPUT lines won't work because they are expecting both computers to be using port 22 (ssh) and the local host won't.

A very good reference for iptables firewalls is: "Designing and Implementing Linux Firewalls with QoS using netfilter, iproute2, NAT and L7-filter". It has very good real-world examples and explains everything quite well.
 
1 members found this post helpful.
  


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
Configuring Squid with acl but without configuring the navigator carlos.alfaro1 Linux - Networking 1 08-15-2018 06:59 AM
DNS issues, Downloading issues, Web issues. UbuntuHelp Linux - Networking 1 08-28-2012 07:34 AM
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
Configuring IPTABLES goldfish Linux - Newbie 6 10-15-2003 04:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

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