Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I know this seems like a simple question, but I have searched all over the place and can't seem to find an answer.
Question: How do I block outbound traffic, from the local computer (i.e. this firewall is NOT forwarding traffic for any other computers)? I only want to use bittorrent, browse the internet, and connect to other computers (but not let them initiate connections with me) via SSH. Other than that, there should be no incoming or outbound traffic. What would a simple iptables script for this look like?
It's wierd that I couldn't find the answer to this, but it seems like all of the documentation and forum posts I've found seem to only discuss the INPUT chain and FORWARD chains, or is discussing a computer used as a firewall for multiple computers, that is forwarding traffic. All I want to do though is protect the computer the firewall is installed on.
How do I block outbound traffic, from the local computer (i.e. this firewall is NOT forwarding traffic for any other computers)? I only want to use bittorrent, browse the internet, and connect to other computers (but not let them initiate connections with me) via SSH. Other than that, there should be no incoming or outbound traffic. What would a simple iptables script for this look like?
It would look like this:
Code:
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# BitTorrent (Tracker):
iptables -A OUTPUT -p TCP --dport 6969 \
-m state --state NEW -j ACCEPT
# BitTorrent (P2P Connections):
iptables -A OUTPUT -p TCP --dport 6881:6999 \
-m state --state NEW -j ACCEPT
# HTTP:
iptables -A OUTPUT -p TCP --dport 80 \
-m state --state NEW -j ACCEPT
# HTTPS:
iptables -A OUTPUT -p TCP --dport 443 \
-m state --state NEW -j ACCEPT
# DNS:
iptables -A OUTPUT -p UDP --dport 53 \
-m state --state NEW -j ACCEPT
# DNS (TCP fallback):
iptables -A OUTPUT -p TCP --dport 53 \
-m state --state NEW -j ACCEPT
# SSH:
iptables -A OUTPUT -p TCP --dport 22 \
-m state --state NEW -j ACCEPT
The same thing, but more condensed:
Code:
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -p TCP \
-m multiport --dports 6969,6881:6999,80,443,53,22 \
-m state --state NEW -j ACCEPT
iptables -A OUTPUT -p UDP --dport 53 \
-m state --state NEW -j ACCEPT
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.