Results 1 to 7 of 7

Thread: specifying port ranges-iptables

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Posts
    57

    specifying port ranges-iptables

    i have a iptable firewall installed on red hat 9.0.I wanted to allow a range of ports say 5000 to 5050 .I tied using 5000:5050 ,but it doesnt seem to work.Can any one help me out with the correct syntax.

    iptables version is iptables v1.2.7a:

    The command was

    iptables -t filter -A FORWARD -s 192.168.1.0/24 -p tcp -m state --state NEW -m multiport --dports 7000:7100 -j ACCEPT

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    man iptables will show you, that --dports or --destination-ports takes a comma seperated argument mentioning every ports in question, not a port range, so it will be:
    Code:
    #!/bin/sh
    
    PORTS="5000,5001,5002,5003,5004,5005,5006,5007,5008,5009,5010,\
           5011,5012,5013,5014,5015,5016,5017,5018,5019,5020,\
           5021,5022,5023,5024,5025,5026,5027,5028,5029,5030,\
           5031,5032,5033,5034,5035,5036,5037,5038,5039,5040,\
           5041,5042,5043,5044,5045,5046,5047,5048,5049,5050"
    iptables -t filter -A FORWARD -s 192.168.1.0/24 -p tcp -m state --state NEW -m multiport --dports $PORTS -j ACCEPT
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  3. #3
    Junior Member
    Join Date
    Mar 2006
    Posts
    57
    thks for the reply

    i tried adding ports from 7000 to 7100 ,but i got an error as

    invalid port/service ' ' specified.

  4. #4
    Junior Member
    Join Date
    Mar 2006
    Posts
    57
    i checked out in help ,it aloows only 15 ports at a time ,hence i assignes 10 ports at a time

    PORTS="7000,7001,7002,7003,7004,7005,7006,7007,700 8,7009,7010"
    iptables -t filter -A FORWARD -s 192.168.1.0/24 -p tcp -m state --state NEW -m multiport --dports $PORTS -j ACCEPT

    and its wrkg fine now


    thks for ur valuable input ,it helped solve the problem ,whcih i was facing for a long time.

  5. #5
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    You could shorten that to:
    Code:
    PORTS="7000,7001,7002,7003,7004,7005,7006,7007,7008,7009,7010 \
           7011,7012,7013,7014,7015,7016,7017,7018,7019,7020 \
           .... \
           7091,7092,7093,7094,7095,7096,7097,7098,7099,7100"
    for RANGE in $PORTS; do
        iptables -t filter -A FORWARD -s 192.168.1.0/24 -p tcp -m state --state NEW -m multiport --dports $RANGE -j ACCEPT
    done
    Notice the " "(space) befor every newline in the definition of PORTS.
    That way you can have all your ports gathered in one variable and run through them in a single line...
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  6. #6
    Junior Member
    Join Date
    Mar 2006
    Posts
    57
    thks .when i try the command of giving it in a single line ,it gives me an error as

    invalid port/service ' ' specified

  7. #7
    Junior Member
    Join Date
    Mar 2006
    Posts
    57
    ooops sorry ,i didnt check the for command ,thought it was the same earlier command.I will try and let u know.

Similar Threads

  1. How can block 443 port per user using iptables
    By khaledjamel in forum Linux - Hardware, Networking & Security
    Replies: 1
    Last Post: 12-01-2011, 02:05 PM
  2. Port foreword + openVPN + iptables ?
    By flan in forum Linux - Hardware, Networking & Security
    Replies: 2
    Last Post: 05-12-2011, 01:37 PM
  3. Iptables port forwarding, same network..
    By Zordhick in forum Security
    Replies: 2
    Last Post: 10-23-2009, 05:12 PM
  4. dual port net card: port trunking?
    By Blaqb0x in forum Linux - Hardware, Networking & Security
    Replies: 0
    Last Post: 02-06-2003, 10:33 PM
  5. Port Forwarding IPTABLES Script
    By Coral_Sea in forum Programming
    Replies: 0
    Last Post: 10-08-2002, 10:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •