Skip to contentSkip to conversation

blocking all trafic exapt selcter ports

DISCUSSION Kashif Ali Bukhari 6 participants 9 messages Apr 23, 2005

lore
Share & tools
lore
#0 lore raw

i want to block all inbod access to my linux box and want to allow dns, http proxy,ssh,telnet,and ftp
how can i do this

Signature · 6 lines
Syed Kashif Ali Bukhari
Network Associate Asia Net
Cell :- +92-300-4018407 , +92-300-4295604
Ph +92-42-111-111-202 Fax +92-42-5840905
MSN:- [email protected] ; [email protected]
http://asia.net.pk , http://asiatec.biz
#1 lore raw
Quoted 4 lines · Kashif Ali Bukhari

i want to block all inbod access to my linux box and want to allow dns, http proxy,ssh,telnet,and ftp
how can i do this

First, please see
http://www.catb.org/~esr/faqs/smart-questions.html

iptables -A INPUT -p tcp --dport  21 -j ACCEPT
iptables -A INPUT -p tcp --dport  22 -j ACCEPT
iptables -A INPUT -p tcp --dport  23 -j ACCEPT
iptables -A INPUT -p tcp --dport  53 -j ACCEPT
iptables -A INPUT -p tcp --dport  3128 -j ACCEPT

iptables -P INPUT DROP

or if you compile your kernel/iptables with multiport support

iptables -A INPUT -m multiport -p tcp --dports 21-23,53,3128 -j ACCEPT iptables -P INPUT DROP

A classic RTFM/STFW case, nonetheless...

#2 lore raw
In reply to Kashif Ali Bukhari
Quoted 4 lines · Kashif Ali Bukhari

i want to block all inbod access to my linux box and want to allow dns, http proxy,ssh,telnet,and ftp
how can i do this

First, please see
http://www.catb.org/~esr/faqs/smart-questions.html

iptables -A INPUT -p tcp --dport  21 -j ACCEPT
iptables -A INPUT -p tcp --dport  22 -j ACCEPT
iptables -A INPUT -p tcp --dport  23 -j ACCEPT
iptables -A INPUT -p tcp --dport  53 -j ACCEPT
iptables -A INPUT -p tcp --dport  3128 -j ACCEPT

iptables -P INPUT DROP

or if you compile your kernel/iptables with multiport support

iptables -A INPUT -m multiport -p tcp --dports 21-23,53,3128 -j ACCEPT iptables -P INPUT DROP

A classic RTFM/STFW case, nonetheless...

#3 lore raw
Quoted 7 lines · Ed
Quoted 3 lines · Kashif Ali Bukhari

i want to block all inbod access to my linux box and want to allow dns, http proxy,ssh,telnet,and ftp
how can i do this

First, please see
http://www.catb.org/~esr/faqs/smart-questions.html

i love that link.

Quoted 4 lines
iptables -A INPUT -p tcp --dport  21 -j ACCEPT
iptables -A INPUT -p tcp --dport  22 -j ACCEPT
iptables -A INPUT -p tcp --dport  23 -j ACCEPT
iptables -A INPUT -p tcp --dport  53 -j ACCEPT

and:
iptables -A INPUT -p udp --dport 53 -j ACCEPT

Quoted 6 lines

iptables -A INPUT -p tcp --dport 3128 -j ACCEPT iptables -P INPUT DROP

or if you compile your kernel/iptables with multiport support

iptables -A INPUT -m multiport -p tcp --dports 21-23,53,3128 -j ACCEPT

multiport doesn't support ranges, mport does (and it uses a ':' not a '-'):

  iptables -A INPUT -p tcp -m mport --dports 21:23,53,3128 -j ACCEPT
  iptables -A INPUT -p udp --dport 53 -j ACCEPT
Quoted 3 lines

iptables -P INPUT DROP

A classic RTFM/STFW case, nonetheless...

yes. couldn't resist the nit-pick, though. ;-)

-j

--
"Joe Swanson: You can't just come over here and annex my pool!
Peter: Oh yeah? Well, according to paragraph 7, sentence 3, word 8 of the Geneva Convention..."the". So, tough luck, Swanson."
--Family Guy

#4 lore raw
Quoted 8 lines · Jason Opperisano
Quoted 6 lines · Ed
Quoted 3 lines · Kashif Ali Bukhari

i want to block all inbod access to my linux box and want to allow dns, http proxy,ssh,telnet,and ftp
how can i do this

Quoted 6 lines
Quoted 2 lines

First, please see
http://www.catb.org/~esr/faqs/smart-questions.html

i love that link.

Me too :)

Quoted 5 lines

and:
iptables -A INPUT -p udp --dport 53 -j ACCEPT

Ooops, shouldn't respond when really tired. =P

Quoted 3 lines

multiport doesn't support ranges, mport does (and it uses a ':' not a '-'):

Again, tiredness :S (glad you caught that).

Quoted 4 lines
Quoted 1 line

A classic RTFM/STFW case, nonetheless...

yes. couldn't resist the nit-pick, though. ;-)

...and for that I am grateful. TY (really!) for the corrections. =) I shouldn't post when really tired (instead of drinking, that'll be my excuse).

/me goes back to primarily lurking...

#5 lore raw

Re: blocking all traffic except selected ports

Quoted 10 lines · Ed
Quoted 2 lines · Jason Opperisano

multiport doesn't support ranges, mport does (and it uses a ':' not a '-'):

Again, tiredness :S (glad you caught that).

Actually (after having a pot of coffee) I just looked at iptables -m multiport --help on my box, and saw the following:

multiport v1.3.1 options:
--source-ports [!] port[,port:port,port...]
--sports ...
match source port(s)
--destination-ports [!] port[,port:port,port...]
--dports ...
match destination port(s)
--ports [!] port[,port:port,port]
match both source and destination port(s)

It seems multiport has been updated to use port ranges after all.

(Note to self: don't reply to messages right after waking up either. UGH! I thought there was a reason that I switched from mport to multiport on my router...)

https://lists.netfilter.org/pipermail/netfilter-devel/2005-January/017977.html

# uname -r && iptables --version
2.6.11.7
iptables v1.3.1

From http://www.netfilter.org/patch-o-matic/pom-obsolete.html

Quoted 10 lines

iptables mport match
Author: Andreas Ferber <[email protected]>
Status: Deprecated by 'multiport' version1 in 2.6.11-rcX

This module is an enhanced multiport match. It has support for byte ranges as well as for single ports.
Up to 15 ports are allowed. Note that a portrange uses up 2 port values.

Examples:

# iptables -A FORWARD -p tcp -m mport --ports 23:42,65

The way I understand it, if you're using a Linux kernel that is older than 2.6.11-rcX, use mport. Otherwise use multiport.

/me still admits being wrong about the ':' separator, as well as forgetting about the UDP protocol for DNS though. =)

(Thanks for the nitpicking, J, it really is appreciated. I don't want to spread *incorrect* information.)

#6 lore raw

Re: blocking all traffic except selected ports

Quoted 21 lines · Ed

Actually (after having a pot of coffee) I just looked at iptables -m multiport --help on my box, and saw the following:

multiport v1.3.1 options:
--source-ports [!] port[,port:port,port...]
--sports ...
match source port(s)
--destination-ports [!] port[,port:port,port...]
--dports ...
match destination port(s)
--ports [!] port[,port:port,port]
match both source and destination port(s)

It seems multiport has been updated to use port ranges after all.

(Note to self: don't reply to messages right after waking up either. UGH! I thought there was a reason that I switched from mport to multiport on my router...)

Quoted 5 lines

https://lists.netfilter.org/pipermail/netfilter-devel/2005-January/017977.html

# uname -r && iptables --version
2.6.11.7
iptables v1.3.1

this brings out an interesting point--as i was speaking from an iptables 1.2.11 perspective (i have not updated a single box to 1.3.x)...we're probably going to have to start specifying iptables version on almost every post to keep from confusing the hell outta people.

-j

--
"Chris: Dad, there's a guy outside who says I can't go to school.
Peter: Yeah? Him and what army?
Chris: The U.S. Army.
Peter: ...that's a good army."
--Family Guy

#7 lore raw

Re: blocking all traffic except selected ports

Quoted 4 lines · Jason Opperisano

this brings out an interesting point--as i was speaking from an iptables 1.2.11 perspective (i have not updated a single box to 1.3.x)...we're probably going to have to start specifying iptables version on almost every post to keep from confusing the hell outta people.

*nod* I could easily see this becoming a problem. Is this something that is worth posting / starting and administrative / thread on this list stating that there has been a Flag Day in iptables? Do we need to come up with a conversion method or at least a table that references version with the old way and new way?

Grant. . . .

#8 lore raw

Re: blocking all traffic except selected ports

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 8 lines · Taylor Grant
Quoted 4 lines · Jason Opperisano

this brings out an interesting point--as i was speaking from an iptables 1.2.11 perspective (i have not updated a single box to 1.3.x)...we're probably going to have to start specifying iptables version on almost every post to keep from confusing the hell outta people.

*nod* I could easily see this becoming a problem. Is this something that is worth posting / starting and administrative / thread on this list stating that there has been a Flag Day in iptables? Do we need to come up with a conversion method or at least a table that references version with the old way and new way?

Versioning in the subject would be the preferred method;

Subject : version 1.2.11 Re: blocking all traffic except selected ports

Thanks,

Ron DuFresne
- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
admin & senior security consultant: sysinfo.com
http://sysinfo.com
Key fingerprint = 9401 4B13 B918 164C 647A E838 B2DF AFCC 94B0 6629

...We waste time looking for the perfect lover
instead of creating the perfect love.

-Tom Robbins <Still Life With Woodpecker>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFCatVMst+vzJSwZikRAvAbAKCpAXAS3PH1kC3Hq09509NNUgARkwCgtuuQ OPK3cfmrOEhJ+m00T61LPn8=
=2J+A
-----END PGP SIGNATURE-----