{"id":814,"date":"2008-05-29T07:00:59","date_gmt":"2008-05-29T14:00:59","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=814"},"modified":"2008-05-29T07:00:59","modified_gmt":"2008-05-29T14:00:59","slug":"how-to-banunban-ips-in-linux","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/how-to-banunban-ips-in-linux\/","title":{"rendered":"How to ban\/unban ips in linux"},"content":{"rendered":"<p>In case you&#8217;re not an iptables guru, you might want to create a couple scripts and put em somewhere on your $PATH. I&#8217;ve created two scripts called <strong>ban_ip<\/strong> and <strong>unban_ip<\/strong>. <\/p>\n<p>Create a file called ban_ip<\/p>\n<pre>\ntouch ban_ip\nchmod +x ban_ip\n<\/pre>\n<p>Edit it and copy the following code inside:<\/p>\n<pre>\n#!\/bin\/bash\nsudo iptables -A INPUT -s $1 -j DROP\necho IP Address $1 has been banned\necho\n<\/pre>\n<p>To ban an IP, you must invoke<\/p>\n<pre>ban_ip &lt;someIpAddressHere&gt;<\/pre>\n<p>e.g.<\/p>\n<pre>ban_ip 211.32.44.111<\/pre>\n<p>And the IP will be banned.<\/p>\n<p>Do the same now for the unban_ip script<\/p>\n<pre>\ntouch unban_ip\nchmod +x unban_ip\n<\/pre>\n<p>Open your fav. text editor and copy the following code inside:<\/p>\n<pre>\n#!\/bin\/bash\niptables -D INPUT -s $1 -j DROP\necho Unbanned ip $1\necho\n<\/pre>\n<p>Save it, and use it.<\/p>\n<p>To unban an IP, you must invoke<\/p>\n<pre>unban_ip &lt;someIpAddressHere&gt;<\/pre>\n<p>e.g.<\/p>\n<pre>unban_ip 211.32.44.111<\/pre>\n<p><strong>Requirements<\/strong><br \/>\nHave sudo access, have iptables installed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case you&#8217;re not an iptables guru, you might want to create a couple scripts and put em somewhere on your $PATH. I&#8217;ve created two scripts called ban_ip and unban_ip. Create a file called ban_ip touch ban_ip chmod +x ban_ip Edit it and copy the following code inside: #!\/bin\/bash sudo iptables -A INPUT -s $1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,30,43],"tags":[173,571,1449,1032,1054],"class_list":["post-814","post","type-post","status-publish","format-standard","hentry","category-code","category-geeklife","category-linux","tag-ban","tag-iptables","tag-linux","tag-unban","tag-utils"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-d8","jetpack-related-posts":[{"id":816,"url":"https:\/\/www.gubatron.com\/blog\/script-to-automatically-detect-and-ban-malicious-ips-that-try-to-brute-force-ssh-accounts\/","url_meta":{"origin":814,"position":0},"title":"Script to automatically detect and ban malicious IPs that try to brute force SSH accounts","author":"gubatron","date":"May 29, 2008","format":false,"excerpt":"We've noticed that most of our servers have been under heavy attack from random IP addresses to break via SSH. With the help of the last post on how to ban an IP, and the following python script, you'll be able to have a cronjob that runs once or twice\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2202,"url":"https:\/\/www.gubatron.com\/blog\/have-the-latest-haproxy-as-a-ubuntu-service\/","url_meta":{"origin":814,"position":1},"title":"Have the latest HAProxy as a Ubuntu Service","author":"gubatron","date":"April 6, 2011","format":false,"excerpt":"So you need to use HAProxy and you love the convenience of binary packages on repos, but when you install the version HAProxy available in the repos you realize that it is way too old for what you need. Then you download the latest HAProxy, compile it, configure it, but\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3453,"url":"https:\/\/www.gubatron.com\/blog\/command-line-speed-test-see-how-fast-is-your-servers-connection\/","url_meta":{"origin":814,"position":2},"title":"command line speed test, see how fast is your server&#8217;s connection","author":"gubatron","date":"January 6, 2016","format":false,"excerpt":"Save the following script in a file called speed_test #!\/bin\/bash # Requirements # sudo apt-get install lftp iperf lftp -e 'pget http:\/\/releases.ubuntu.com\/14.04.3\/ubuntu-14.04.3-desktop-amd64.iso; exit; ' make sure the file is executable: sudo chmod +x speed_test Once you have installed lftp and iperf make sure you have the script somewhere in your\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2016\/01\/Fiber-optics.jpg?fit=892%2C538&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1939,"url":"https:\/\/www.gubatron.com\/blog\/solved-eclipse-cant-see-my-android-device-on-ubuntu\/","url_meta":{"origin":814,"position":3},"title":"[SOLVED] Eclipse can&#8217;t see my Android Device on Ubuntu","author":"gubatron","date":"May 28, 2010","format":false,"excerpt":"Are you seeing this on eclipse when you plug your Android device to your Ubuntu box? Serial Number: ?????????? AVD Name: N\/A Target: unknown State: ?? Here's the solution: 1. Create a script to fix this next time it happens, let's call it \"android_device_reset\" and save it on a folder\u2026","rel":"","context":"In &quot;Android&quot;","block_context":{"text":"Android","link":"https:\/\/www.gubatron.com\/blog\/category\/android\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":570,"url":"https:\/\/www.gubatron.com\/blog\/check-if-your-phps-diff-syntax-isnt-breaking\/","url_meta":{"origin":814,"position":4},"title":"Check if your PHP&#8217;s diff syntax isn&#8217;t breaking","author":"gubatron","date":"August 11, 2007","format":false,"excerpt":"Say you're working on emacs, without any kind of syntax checking, and you don't want to commit your code cause you might have syntax errors. If you're smart, the best way to know what files you actually changed, is using svn diff | grep +++ (that is, if you're using\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2767,"url":"https:\/\/www.gubatron.com\/blog\/ubuntu-packages-for-a-kick-ass-web-server\/","url_meta":{"origin":814,"position":5},"title":"ubuntu packages for a kick ass web server","author":"gubatron","date":"September 7, 2012","format":false,"excerpt":"Copy and paste the following list on a file, say \"packages.txt\". To install all just do: sudo apt-get install $(cat packages.txt) accountsservice acpid adduser ant ant-optional apache2-utils apparmor apport apport-symptoms apt apt-transport-https apt-utils apt-xapian-index aptitude at base-files base-passwd bash bash-completion bc bind9-host bsdmainutils bsdutils busybox-initramfs busybox-static byobu bzip2 ca-certificates ca-certificates-java\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=814"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/814\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}