Documente Academic
Documente Profesional
Documente Cultură
Home
About
Forum
Howtos & FAQs
Shell Scripts
Tutorials
RSS Subscribe
Bandwidth Monitoring This is very common scenario which permit access to a remote
Tool machine only by SSH. You would like to block all incoming traffic
Monitor Bandwidth & to your system except ssh connection. Here is simple ruleset to
Network Traffic Reports, do this (do not enter them immediately).
Alerts, Email, SNMP
Traps Add following rules to your iptables shell script:
www.ManageEngine.com/NetFlow
First rule will accept incoming (INPUT) tcp connection on port 22 (ssh server) and
second rule will send response of incoming ssh server to client (OUTPUT) from our ssh
server source port 22.
However, iptables with kernel 2.4/2.6 provides very powerful facility to filter rule
based upon different connection states such as established or new connection etc. Here
is complete small script to do this task:
#!/bin/sh
# My system IP/set ip address of server
SERVER_IP="65.55.12.13"
# Flushing all rules
iptables -F
iptables -X
# Setting default filter policy
iptables -P INPUT DROP
1 of 8 12/05/2009 10:37 PM
Linux : Iptables # 4 Block all incoming traffic but a... http://www.cyberciti.biz/tips/linux-iptables-4-block-al...
This script is purely strict firewall. It only allows incoming ssh. No other incoming
service or ping request or no outgoing service or request allowed. Incoming ssh
connection can be either new or already established one and that is what specified by
state rule '-m state --state NEW,ESTABLISHED'. Outgoing ssh connection state can be
established only. By default this script allows everyone to ssh in by rule -s 0/0. If you
want this access limited by IP or network address then replace -s 0/0 with IP address.
For example allow incoming ssh from IP 202.54.1.20:
Featured Articles:
2 of 8 12/05/2009 10:37 PM
Linux : Iptables # 4 Block all incoming traffic but a... http://www.cyberciti.biz/tips/linux-iptables-4-block-al...
How about opening outgoing ssh? I tried the rule to reverse it but not working. i
mean i need to ssh in on dsl box as well as ssh out!
Try
3 of 8 12/05/2009 10:37 PM
Linux : Iptables # 4 Block all incoming traffic but a... http://www.cyberciti.biz/tips/linux-iptables-4-block-al...
Thanks.
You have some funky characters on this page double “-” is being replaced by an
mdash or something … this causes a copy and paste of the rules to fail (at least on
my console)
you have ” �sport”, there should be two characters before sport, with extra
spaces this should be ” – - s p o r t”
Cheers
pbhj,
Hi,
I want to configured the firewall but there is a 5 server on wan & also at lan.
How I connect this all m/c through firewall for wan for ssh service.
or which reule I inser for ssh_key.
Nand
4 of 8 12/05/2009 10:37 PM
Linux : Iptables # 4 Block all incoming traffic but a... http://www.cyberciti.biz/tips/linux-iptables-4-block-al...
I tried the script on my linux box and it locked me out of SSH access totally. Use
with caution.
Hi,
I have a router wrt54gl with openwrt(kernel 2.4.x) and I can’t seem to block other
lan users.
router ip is 10.77.77.1 / netmask 255.255.255.0
squid server is 10.77.77.228 3128 port
iptables -F
iptables -Z
iptables -X
iptables -t nat -F
iptables -t nat -Z
iptables -t nat -X
iptables -A INPUT -s 10.77.77.228 -j ACCEPT
iptables -A INPUT -d 10.77.77.228 -j ACCEPT
iptables -A OUTPUT -s 10.77.77.1 -j ACCEPT
iptables -A OUTPUT -d 10.77.77.228 -j ACCEPT
iptables -A INPUT -s 10.77.77.1/24 -d 10.77.77.1 -j ACCEPT
iptables -A INPUT -s 10.77.77.1/24 -d 10.77.77.228 -p tcp –dport 3128 -j ACCEPT
iptables -A OUTPUT -d 10.77.77.1/24 -s 10.77.77.1 -j ACCEPT
iptables -A INPUT -p udp –sport 67:68 –dport 67:68 -j ACCEPT
iptables -A OUTPUT -p udp –sport 67:68 –dport 67:68 -j ACCEPT
iptables -A INPUT -p udp –dport 53 -j ACCEPT
iptables -A OUTPUT -p udp –dport 53 -j ACCEPT
iptables -A INPUT -p tcp –dport 80 -j ACCEPT
iptables -A INPUT -p tcp –dport 3128 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 3128 -d 10.77.77.228 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 80 -d ! 10.77.77.228 -j DROP
iptables -A OUTPUT -p tcp –dport 3128 -d ! 10.77.77.228 -j DROP
#this one redirect port 80 to 3128 squid server
iptables -t nat -A PREROUTING -s ! 10.77.77.228 -p tcp –dport 80 -j DNAT –to
10.77.77.228:3128
iptables -t nat -A POSTROUTING -s 10.77.77.1/24 -d 10.77.77.228 -j
MASQUERAD
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
I just want to allow 10.77.77.228, and all others to be blocked for all protocols, all
ports except 80 port tcp, 53 udp(dns), 67,68 udp(dhcp). The above rules don’t
work. I am still able to ping,ftp or p2p from any host from the lan.
5 of 8 12/05/2009 10:37 PM
Linux : Iptables # 4 Block all incoming traffic but a... http://www.cyberciti.biz/tips/linux-iptables-4-block-al...
I would like to propose an alternative howto that I know that I would benefit from,
probably many others too. I have several dedicated servers at a provider that
charges $100/month for a firewall for EACH SERVER. This is like 1/3 to 1/2 the
cost of each server. All I want is one machine reachable from the net at large to
serve as my ssh entrance, and my web server load balancer. So I want to cut off all
the other machines from inbound connections from the net. So they need to be
able to accept connections on the internal subnet to get load balanced to. But
they also need to be able to get out to the real world to download the occasional
item, and also hit REST apis of various types. Maybe other stuff. I would think this
is fairly typical, but I bet a lot of people shell out the ducats for the firewall
service. Ouch, I says.
That’s it.
thanks
dumbfounder
Leave a Comment
Name *
E-mail *
You can use these HTML tags and attributes: <a href="" title=""> <abbr title="">
<acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime="">
<em> <i> <q cite=""> <strike> <strong>
Submit
6 of 8 12/05/2009 10:37 PM
Linux : Iptables # 4 Block all incoming traffic but a... http://www.cyberciti.biz/tips/linux-iptables-4-block-al...
you@address.com Sign up
Search
Related Posts
Sponsored Links
Unified Communications:
Thoughts, Strategies and Predictions Join the discussion.
7 of 8 12/05/2009 10:37 PM
Linux : Iptables # 4 Block all incoming traffic but a... http://www.cyberciti.biz/tips/linux-iptables-4-block-al...
www.seamlessenterprise.com
IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com
Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com
Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com
See your text ad here
Follow us on
8 of 8 12/05/2009 10:37 PM