LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-04-2019, 02:33 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
iptables - How do I know RELATED ports?


Hello

I'm trying to understand RELATED state in iptables.

This is the definition:
Quote:
RELATED connections are also validated by another rule and they apply for a few protocols. The RELATED state signifies a packet that is generated is in relation with some other existing communication. This may make it possible to connect on a different port, that port should only be part of a related process like an FTP data connection. Which ports are allowed are controlled by protocol specific conntrack kernel module.
This is my understanding:
In iptables, when you allow port 21 (ftp), then its related port 20 (data) will automatically considered as RELATED (to port 21) and hence allowed to pass through.

I'm I right?

If wrong, please correct me.

If right, how do I know what are the related ports of FTP connection specified in its conntrack module? I know its specific conntrack kernel module is nf_conntrack_ftp.

From /etc/services file, I assume these are all FTP related ports:
Code:
ftp-data        20/tcp
ftp-data        20/udp
ftp             21/tcp
ftp             21/udp          fsp fspd
ftp-data        20/sctp                 # FTP
ftp             21/sctp                 # FTP
ftp-agent       574/tcp                 # FTP Software Agent System
ftp-agent       574/udp                 # FTP Software Agent System
but, I want verification from conntrack module. How do I know those related ports?

Also while I'm here, will someone tell me RegEx for finding 'ftp' and zero or one hyphen.

This is what show in my terminal
Code:
# egrep ^ftp-? /etc/services 
ftp-data        20/tcp
ftp-data        20/udp
ftp             21/tcp
ftp             21/udp          fsp fspd
ftp-data        20/sctp                 # FTP
ftp             21/sctp                 # FTP
ftp-agent       574/tcp                 # FTP Software Agent System
ftp-agent       574/udp                 # FTP Software Agent System
ftps-data       989/tcp                 # ftp protocol, data, over TLS/SSL
ftps-data       989/udp                 # ftp protocol, data, over TLS/SSL
ftps            990/tcp                 # ftp protocol, control, over TLS/SSL
ftps            990/udp                 # ftp protocol, control, over TLS/SSL
I don't want italicised to show up.

Thanks
 
Old 02-04-2019, 08:35 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by ddenial View Post
This is my understanding:
In iptables, when you allow port 21 (ftp), then its related port 20 (data) will automatically considered as RELATED (to port 21) and hence allowed to pass through.

I'm I right?
No. The FTP protocol uses a random, unprivileged port at the client for the data transfer. It's not something you can look up in a table. It is the job of the FTP protocol helper module in the firewall to look into the control channel packets and determine which port connection needs to be set up as RELATED in the connection tracking.

See https://en.wikipedia.org/wiki/File_T...tocol_overview
 
1 members found this post helpful.
Old 02-05-2019, 06:51 AM   #3
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by rknichols View Post
No. The FTP protocol uses a random, unprivileged port at the client for the data transfer. It's not something you can look up in a table. It is the job of the FTP protocol helper module in the firewall to look into the control channel packets and determine which port connection needs to be set up as RELATED in the connection tracking.

See https://en.wikipedia.org/wiki/File_T...tocol_overview
Thanks. It clears my confusion.
 
  


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
reject all ip & ports and allow only some ports with iptables ysar68 Linux - Security 1 05-12-2007 08:50 PM
ports, ports, ports cjae Linux - Networking 1 04-09-2006 09:38 AM
iptables v1.2.9: Unknown arg `/sbin/iptables' Try `iptables -h' or 'iptables --help' Niceman2005 Linux - Security 4 12-29-2005 08:20 PM
block m$ related ports using iptables carboncopy Linux - Security 8 01-28-2005 12:30 PM
iptables: block ports and RELATED, ESTABLISHED Klaus Pforte Linux - Security 6 07-17-2003 10:00 AM

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

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