What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands using iptables from sorted by
Terminal - Commands using iptables - 34 results
sudo iptables -A INPUT -m limit --limit 2000/sec -j ACCEPT && sudo iptables -A INPUT -j DROP
2015-03-09 20:16:17
User: qdrizh
Functions: iptables sudo
Tags: iptables

VPS server hosts suspect DOS attack if PPS is too high. This limits packets at the interface level. Do "sudo apt-get install iptables-persistent" to make persistent, or, if you already have, reconfigure with "sudo dpkg-reconfigure iptables-persistent"

iptables -L -vnx --line-numbers; iptables -t nat -D <chain-name> <number>
watch -n1 iptables -vnL
watch -n1 iptables -vnL
watch -d -n 2 iptables -nvL
2014-02-23 16:35:03
User: xxdesmus
Functions: iptables watch

This will highlight (with a box over it) any changes since the last refresh.

iptables -L INPUT --line-numbers
2013-12-19 16:14:25
Functions: iptables

Then you can remove the specific entry:

iptables -D INPUT 10

Just make sure these are set:



Else your changes won't stick when you restart iptables.

iptables-save > iptables.current; vi iptables.current; iptables-restore iptables.current; service iptables save
2013-12-04 18:41:48
User: bigc00p

These series of commands allows you all at once to make a backup of your current config, edit that config, then saves it as the running config and makes it persistent. I would advise knowing what your doing to the config before running this because if you mess up say the port 22 portion, you may get knocked off the system. ;) Don't say I didn't warn ya!

while true; do iptables -nvL > /tmp/now; diff -U0 /tmp/prev /tmp/now > /tmp/diff; clear; cat /tmp/diff; mv /tmp/now /tmp/prev; slee p 1; done
2012-04-15 00:02:33
Functions: cat diff iptables mv

this alternative shows the differences as they occur so that they are made plain

REJECT_RULE_NO=$(iptables -L RH-Firewall-1-INPUT --line-numbers | grep 'REJECT' | awk '{print $1}');/sbin/iptables -I RH-Firewall-1-INPUT $REJECT_RULE_NO -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -m comment --comment "Permit HTTP Service"
2012-02-02 12:21:06
User: ajmckee
Functions: awk grep iptables

Rather then editing the /etc/sysconfig/iptables file, or during a kickstart doing some awk/sed magic, easily add a rule in the correct place within iptables

sudo iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
2011-12-16 10:39:13
User: Dhinesh
Functions: iptables sudo
Tags: iptables

This command will open tcp port 3000 in your machine

iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; for table in `cat /proc/net/ip_tables_names`; do iptables -t $table -F; iptables -t $table -Z; iptables -t $table -X; done
2011-12-15 18:19:34
User: dash
Functions: iptables
Tags: Linux iptables

If you changed the default policy on any chain other than filter table chain's, this won't be enough.

iptables -A OUTPUT www.baidu.com -p tcp -j REJECT --reject-with tcp-reset
2011-06-26 03:12:22
User: kev
Functions: iptables
Tags: iptables

To save all rules so that they are not lost in case of a server reboot:

/etc/init.d/iptables save

iptables -A INPUT -s -j DROP
cd /etc/network/if-up.d && iptables-save > firewall.conf && echo -e '#!/bin/sh -e\niptables-restore < $(dirname $0)/firewall.conf' > iptables && chmod a+x iptables
echo 1 > /proc/sys/net/ipv4/tcp_syncookies echo 1 > /proc/sys/net/ipv4/ip_forward iptables -A FORWARD -p tcp ?syn -m limit -j ACCEPT
tail -f /var/www/logs/domain.com.log | grep "POST /scripts/blog-post.php" | grep -v 192.168. | awk '{print $1}' | xargs -I{} iptables -I DDOS -s {} -j DROP
2010-11-30 06:22:18
User: tehusr
Functions: awk grep iptables tail xargs

Takes IP from web logs and pipes to iptables, use grep to white list IPs.. use if a particular file is getting requested by many different addresses.

Sure, its already down pipe and you bandwidth may suffer but that isnt the concern. This one liner saved me from all the traffic hitting the server a second time, reconfigure your system so your system will work like blog-post-1.php or the similar so legitimate users can continue working while the botnet kills itself.

function clearIptables(){iptables -P INPUT ACCEPT; iptables -P FORWARD ACCEPT; iptables -P OUTPUT ACCEPT; iptables -F; iptables -X; iptables -L}
iptables-save > firewall.conf; rm -f /etc/network/if-up.d/iptables; echo '#!/bin/sh' > /etc/network/if-up.d/iptables; echo "iptables-restore < firewall.conf" >> /etc/network/if-up.d/iptables; chmod +x /etc/network/if-up.d/iptables
2010-11-13 23:58:28
Tags: sudo iptables

a simple command in order to make iptables rules permanent, run @ sudo!

iptables -A FORWARD -i br0 -m iprange --src-range 192.168.0.x-192.168.0.y -m iprange --dst-range 192.168.0.w-192.168.0.z -j DROP
2010-11-13 23:55:23
Functions: iptables
Tags: sudo iptables

Destination IPs will become invisible to source IPs!

dpkg -L iptables | perl -lne 'print if -f && -x'
sudo iptables -L -nv
for i in `cat /proc/net/ip_tables_names`; do iptables -nL -v --line-numbers -t $i ; done
2010-04-23 13:53:49
User: bw
Functions: iptables

show your current iptable rules from every available iptable table

iptables -L -n -v
2009-10-07 21:13:59
User: gpenguin
Functions: iptables

I was previously unaware of the -v switch. As a result I never got specifics about which interfaces the allowed or dropped applied to. Thought I'd share the wealth...

FYI, -n prevents DNS resolving of IPs.

iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source IP_TO_ROUTE_THROUGH
curl -s http://isc.sans.org/sources.html|grep "ipinfo.html"|awk -F"ip=" {'print $2'}|awk -F"\"" {'print $1'}|xargs -n1 sudo iptables -A OUTPUT -j DROP -d > 2&>1