LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   writing an iptable rule (https://www.linuxquestions.org/questions/linux-newbie-8/writing-an-iptable-rule-4175514531/)

bassplayer 08-12-2014 11:51 PM

writing an iptable rule
 
I am a student at ITT tech and am having trouble writing a iptable rule which will allow all incoming connections from 129.71.298.0/255.255.255.0 for services ssh, http, https, dns, dhcp.

szboardstretcher 08-13-2014 12:01 AM

What have you tried? Which part isn't working?

bassplayer 08-13-2014 12:15 AM

Too new for my own good
 
I'm afraid I haven't figured what to write or how to even begin to write the command. I'm sure it's not difficult but, for me right now it's Hugh. Any help would be great and I would be very grateful.

salasi 08-13-2014 02:44 AM

...and have you read this, which is the best documentation for all things iptables. Now, that might be more information than you wanted, but, on the assumption that after this problem there will be/would have been another problem, it will be worthwhile.

OK, to break it down a bit (I'm not going to answer your question directly), how would you, for example, do anything with http-related packets. What identifying feature would you use that allows you to separate those packets from the rest?

Could you do something similar with the other protocols (clue: yes, unclue, ssh might be more difficult, but that might be beyond the scope, depending)?

Could you do something that only works on packets from a particular source address range (again, clue: yes).

Could you combine the above (clue: yes).

Quote:

...trouble writing a iptable rule...
That seems to imply that only a single rule would be an acceptable answer. This may or may not be what you mean. I'll point out that a sequence of rules might be more flexible and may be able to achieve a more exact match to certain requirements and so, from that point of view, there may be an advantage in writing a sequence of rules, rather than just a single rule (there can also be disadvantages in writing a sequence of rules, so it depends a bit on context, which we don't have).

In any case, if you can write a sequence of rules that does pretty much what you want, it shouldn't be too difficult to come up with something similar (not exactly the same...but with some similarity), but compacted into a single rule.

It is difficult to know on what exact point you are stuck until you actually submit something that you have written, with a comment like 'and I don't know how to add this bit...' or '...but this seems to fail in that respect...'.

diablo046 08-13-2014 06:08 AM

Please make a backup copy before editing Iptables Rule


Kindly check the following configuration ( For Centos and RedHat)

# iptables -L ( To check)
# iptables -F ( To flush )
# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -A INPUT -s 129.71.298.0/24 -p tcp --destination-port 80 -j ACCEPT ( For http )
# iptables -A INPUT -s 129.71.298.0/24 -p tcp --destination-port 22 -j ACCEPT ( For ssh )
# iptables -A INPUT -s 129.71.298.0/24 -p tcp --destination-port 443 -j ACCEPT ( for https )
# iptables -A INPUT -s 129.71.298.0/24 -p tcp --destination-port 53 -j ACCEPT ( For dns tcp )
# iptables -A INPUT -s 129.71.298.0/24 -p udp --destination-port 53 -j ACCEPT ( For dns udp )
# iptables -A INPUT -s 129.71.298.0/24 -p tcp --destination-port 67 -j ACCEPT ( For DHCP )
# iptables -A INPUT -s 129.71.298.0/24 -p tcp --destination-port 68 -j ACCEPT ( For DHCP )
# iptables -P INPUT DROP ( Block other Incoming traffic,if you want )

Now check iptables by # iptables -L

If you want to save these iptables rules then,

# iptables-save > /etc/sysconfig/iptables
# iptables-restore < /etc/sysconfig/iptables

Hope this will help you little bit :)


All times are GMT -5. The time now is 08:04 PM.