<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SoftLayer Blog &#187; command line</title>
	<atom:link href="http://blog.softlayer.com/tag/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.softlayer.com</link>
	<description>A Behind the Scenes Look at the Best Hosting Provider in the World</description>
	<lastBuildDate>Thu, 23 May 2013 19:20:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>iptables Tips and Tricks: CSF Configuration</title>
		<link>http://blog.softlayer.com/2013/iptables-tips-and-tricks-csf-configuration/</link>
		<comments>http://blog.softlayer.com/2013/iptables-tips-and-tricks-csf-configuration/#comments</comments>
		<pubDate>Tue, 19 Mar 2013 18:10:39 +0000</pubDate>
		<dc:creator>Mark Ridlen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[APF]]></category>
		<category><![CDATA[blocking]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[CSF]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptab]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[tips and tricks]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=10812</guid>
		<description><![CDATA[In our last &#8220;iptables Tips and Tricks&#8221; installment, we talked about Advanced Policy Firewall (APF) configuration, so it should come as no surprise that in this installment, we&#8217;re turning our attention to ConfigServer Security &#38; Firewall (CSF). Before we get started, you should probably run through the list of warnings I include at the top [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://blog.softlayer.com/2013/iptables-tips-and-tricks-apf-advanced-policy-firewall-configuration/">our last &#8220;iptables Tips and Tricks&#8221; installment</a>, we talked about Advanced Policy Firewall (APF) configuration, so it should come as no surprise that in this installment, we&#8217;re turning our attention to <a href="http://configserver.com/cp/csf.html">ConfigServer Security &amp; Firewall</a> (CSF). Before we get started, you should probably run through the list of warnings I include at the top of the APF blog post and make sure you have your Band-Aid ready in case you need it.</p>
<p>To get the ball rolling, we need to download CSF and install it on our server. In this post, we&#8217;re working with a CentOS 6.0 32-bit server, so our (root) terminal commands would look like this to download and install CSF:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.configserver.com<span style="color: #000000; font-weight: bold;">/</span>free<span style="color: #000000; font-weight: bold;">/</span>csf.tgz <span style="color: #666666; font-style: italic;">#Download CSF using wget.</span>
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf csf.tgz <span style="color: #666666; font-style: italic;">#Unpack it.</span>
$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> perl-libwww-perl <span style="color: #666666; font-style: italic;">#Make sure perl modules are installed ...</span>
$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> perl-Time-HiRes  <span style="color: #666666; font-style: italic;">#Otherwise it will generate an error.</span>
$ <span style="color: #7a0874; font-weight: bold;">cd</span> csf
$ .<span style="color: #000000; font-weight: bold;">/</span>install.sh <span style="color: #666666; font-style: italic;">#Install CSF.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#MAKE SURE YOU HAVE YOUR BAND-AID READY</span>
&nbsp;
$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>csf start <span style="color: #666666; font-style: italic;">#Start CSF. (Note: You can also use '$ service csf start')</span></pre></div></div>

<p>Once you start CSF, you can see a list of the default rules that load at startup. CSF defaults to a DROP policy:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ iptables <span style="color: #660033;">-nL</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> policy
Chain INPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy DROP<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Chain FORWARD <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy DROP<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Chain OUTPUT <span style="color: #7a0874; font-weight: bold;">&#40;</span>policy DROP<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Don&#8217;t ever run &#8220;<code>iptables -F</code>&#8221; unless you want to lock yourself out. In fact, you might want to add &#8220;This server is running CSF &#8211; do not run &#8216;iptables -F&#8217;&#8221;  to your <code>/etc/motd</code>, just as a reminder/warning to others.</p>
<p>CSF loads on startup by default. This means that if you get locked out, a simple reboot probably won&#8217;t fix the problem. Runlevels 2, 3, 4, and 5 are all on:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ chkconfig <span style="color: #660033;">--list</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> csf
csf             <span style="color: #000000;">0</span>:off   <span style="color: #000000;">1</span>:off   <span style="color: #000000;">2</span>:on    <span style="color: #000000;">3</span>:on    <span style="color: #000000;">4</span>:on    <span style="color: #000000;">5</span>:on    <span style="color: #000000;">6</span>:off</pre></div></div>

<p>Some features of CSF will not work unless you have certain iptables modules installed. I believe they are installed by default in CentOS, but if you custom-built your iptables, they might not all be installed. Run this script to see if all modules are installed:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf<span style="color: #000000; font-weight: bold;">/</span>csftest.pl
Testing ip_tables<span style="color: #000000; font-weight: bold;">/</span>iptable_filter...OK
Testing ipt_LOG...OK
Testing ipt_multiport<span style="color: #000000; font-weight: bold;">/</span>xt_multiport...OK
Testing ipt_REJECT...OK
Testing ipt_state<span style="color: #000000; font-weight: bold;">/</span>xt_state...OK
Testing ipt_limit<span style="color: #000000; font-weight: bold;">/</span>xt_limit...OK
Testing ipt_recent...OK
Testing xt_connlimit...OK
Testing ipt_owner<span style="color: #000000; font-weight: bold;">/</span>xt_owner...OK
Testing iptable_nat<span style="color: #000000; font-weight: bold;">/</span>ipt_REDIRECT...OK
Testing iptable_nat<span style="color: #000000; font-weight: bold;">/</span>ipt_DNAT...OK
&nbsp;
RESULT: csf should <span style="color: #000000; font-weight: bold;">function</span> on this server</pre></div></div>

<p>As I mentioned, this is the default iptables installation on a minimal CentOS 6.0 image, so chances are good that these modules are already installed on your system. It never hurts to check, though.</p>
<h3>The CSF Configuration File</h3>
<p>The primary CSF configuration is stored in the well-documented <code>/etc/csf/csf.conf</code> file. CSF is <em>extremely</em> configurable, so there are a lot of options to read over. Let&#8217;s take a look over some of the more important features:</p>
<p><span id="more-10812"></span></p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Testing</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">TESTING = <span style="color: #ff0000;">&quot;1&quot;</span>
TESTING_INTERVAL = <span style="color: #ff0000;">&quot;5&quot;</span></pre></div></div>

<p>This TESTING cron job runs every &#8220;5&#8243; minutes so you don&#8217;t lock yourself out when you&#8217;re testing your rules. When you are satisfied with your rules (and confident that you won&#8217;t lock yourself out), you can set TESTING to &#8220;0&#8243;.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Globally Allowed Ports</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Allow incoming TCP ports</span>
TCP_IN = <span style="color: #ff0000;">&quot;20,21,22,25,53,80,110,143,443,465,587,993,995&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow outgoing TCP ports</span>
TCP_OUT = <span style="color: #ff0000;">&quot;20,21,22,25,53,80,110,113,443&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow incoming UDP ports</span>
UDP_IN = <span style="color: #ff0000;">&quot;20,21,53&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Allow outgoing UDP ports</span>
<span style="color: #666666; font-style: italic;"># To allow outgoing traceroute add 33434:33523 to this list</span>
UDP_OUT = <span style="color: #ff0000;">&quot;20,21,53,113,123&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Incoming Ping Requests</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Allow incoming PING</span>
ICMP_IN = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>Allowing ping is usually a good option for diagnostic purposes, so I don&#8217;t recommend turning it off. Disallowing ping is an example of &#8220;security through obscurity,&#8221; and it will not typically dissuade your attackers.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Ethernet Device</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ETH_DEVICE = <span style="color: #ff0000;">&quot;&quot;</span>
ETH6_DEVICE = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Here, you can configure iptables to ONLY use one Ethernet adapter. You might want to only guard your public network adapter in some situations.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>IP Limit in Permanent &#8220;Deny&#8221; File</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DENY_IP_LIMIT = <span style="color: #ff0000;">&quot;200&quot;</span></pre></div></div>

<p>A higher number here will obviously screen out more IP addresses in <code>csf.deny</code>, but higher numbers also may cause slowdowns.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>IP Limit in Temporary &#8220;Deny&#8221; File</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DENY_TEMP_IP_LIMIT = <span style="color: #ff0000;">&quot;100&quot;</span></pre></div></div>

<p>Similar to DENY_IP_LIMIT, the DENY_TEMP_IP_LIMIT represents the maximum number of IPs that can be stored in the temporary ban list.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>SMTP Blocking</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_BLOCK = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>When set to &#8220;1&#8243;, SMTP_BLOCK does not completely block outbound SMTP, but it does block it for most users. This will prevent malicious scripts and compromised users from making outbound connections from unauthorized mail clients on the server. SMTP_BLOCK doesn&#8217;t stop those scripts from running, but it does stop them from functioning. Mail sent through the proper channels will still be delivered normally.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Allowing SMTP on localhost</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_ALLOWLOCAL = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Custom Mail Port Designation</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_PORTS = <span style="color: #ff0000;">&quot;25,465,587&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Allowing SMTP Access to Users/Groups</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SMTP_ALLOWUSER = <span style="color: #ff0000;">&quot;&quot;</span>
SMTP_ALLOWGROUP = <span style="color: #ff0000;">&quot;mail,mailman&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>SYN Flood Protection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SYNFLOOD = <span style="color: #ff0000;">&quot;0&quot;</span>
SYNFLOOD_RATE = <span style="color: #ff0000;">&quot;100/s&quot;</span>
SYNFLOOD_BURST = <span style="color: #ff0000;">&quot;150&quot;</span></pre></div></div>

<p>Per the documentation, you should only enable SYN flood protection (SYNFLOOD= &#8220;1&#8243;) if you are currently under a SYN flood attack.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Concurrent Connections Limit</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CONNLIMIT = <span style="color: #ff0000;">&quot;22;5,80;20&quot;</span>
PORTFLOOD = <span style="color: #ff0000;">&quot;22;tcp;5;300,80;tcp;20;5</span></pre></div></div>

<p>These options allow you to add customized DoS protection. CONNLIMIT handles the number of concurrent connections, and in this example, we&#8217;re limiting port 22 to 5 connections and port 80 to 20 connections.</p>
<p>PORTFLOOD on deals with connections per second. In this example, we&#8217;re limiting the TCP connection on port 22 to 5 connections/second with a quiet period of 300 seconds before the connection is unblocked. Additonally, we&#8217;re limiting the TCP connection on port 80 to 20 connections/second with a quiet period of 5 seconds before the connection is unblocked.</p>
<p>Check the <code>readme.txt</code> file for more information about the syntax.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Logging to Syslog</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">SYSLOG = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>When enabled, this option logs lfd (Login Failure Daemon) messages to syslog as well as to <code>/var/log/lfd.log</code>.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Dropping v. Rejecting Packets</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DROP = <span style="color: #ff0000;">&quot;DROP&quot;</span></pre></div></div>

<p>This configuration allows you to either DROP or REJECT packets. REJECT tells the sender that the packet has been blocked by the firewall. DROP just drops the packet and does not send a response. I like DROP better for regular use, but REJECT might be more helpful if you need to diagnose a connectivity issue.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Logging Dropped Connections</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DROP_LOGGING = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>This option logs dropped connections to syslog. I don&#8217;t see any reason to turn this off unless your hard drive is getting full.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Port Exceptions When Logging Dropped Connections</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">DROP_NOLOG = <span style="color: #ff0000;">&quot;67,68,111,113,135:139,445,500,513,520&quot;</span></pre></div></div>

<p>These ports are specifically blocked from being logged either to conserve hard drive space or make the log file easier to read.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>&#8220;Watch Mode&#8221;</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">WATCH_MODE = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>If you are ever stuck trying to troubleshoot a large ruleset, you might consider turning this option on. You can use it to track the actions to watched IP addresses to see where they are getting blocked or accepted.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Login Failure Daemon Alert</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_ALERT_TO = <span style="color: #ff0000;">&quot;&quot;</span>
LF_ALERT_FROM = <span style="color: #ff0000;">&quot;&quot;</span>
LF_ALERT_SMTP = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>You can specify an email address to report errors from the Login Failure Daemon, which tracks and automatically blocks brute force login attempts.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Permanent Blocks and NetBlocks</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_PERMBLOCK = <span style="color: #ff0000;">&quot;1&quot;</span>
LF_PERMBLOCK_INTERVAL = <span style="color: #ff0000;">&quot;86400&quot;</span>
LF_PERMBLOCK_COUNT = <span style="color: #ff0000;">&quot;4&quot;</span>
LF_PERMBLOCK_ALERT = <span style="color: #ff0000;">&quot;1&quot;</span>
LF_NETBLOCK = <span style="color: #ff0000;">&quot;0&quot;</span>
LF_NETBLOCK_INTERVAL = <span style="color: #ff0000;">&quot;86400&quot;</span>
LF_NETBLOCK_COUNT = <span style="color: #ff0000;">&quot;4&quot;</span>
LF_NETBLOCK_CLASS = <span style="color: #ff0000;">&quot;C&quot;</span>
LF_NETBLOCK_ALERT = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>These settings control the permanent block and netblock blocking. You probably don&#8217;t need to touch these settings, but you might want some additional security or less security depending on your company needs. If something gets permablocked, it will require your intervention to clear it, which might create downtime for your clients. Likewise, if a legitimate IP address happens to be part of a netblock which has an attacking IP address on it, it will get blocked if you have that feature turned on. A class C network encompasses 256 IP addresses. You can set this to class B or A, but that could block thousands or millions of IP addresses, respectively. Unless you find yourself under constant attack, I would advise you to leave that LF_NETBLOCK off.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Additional Protection During Updates</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Safe Chain Update. If enabled, all dynamic update chains (GALLOW*, GDENY*,</span>
<span style="color: #666666; font-style: italic;"># SPAMHAUS, DSHIELD, BOGON, CC_ALLOW, CC_DENY, ALLOWDYN*) will create a new</span>
<span style="color: #666666; font-style: italic;"># chain when updating, and insert it into the relevant LOCALINPUT/LOCALOUTPUT</span>
<span style="color: #666666; font-style: italic;"># chain, then flush and delete the old dynamic chain and rename the new chain.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This prevents a small window of opportunity opening when an update occurs and</span>
<span style="color: #666666; font-style: italic;"># the dynamic chain is flushed for the new rules.</span>
SAFECHAINUPDATE = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>Activating this option will increase your system resource usage and will require more rules to be running at one time, but it provides an additional layer of protection during updates. Without this option turned on, your rules will be flushed for a short amount of time, leaving your server vulnerable.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Multi-Server Deployment Options</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_GLOBAL = <span style="color: #ff0000;">&quot;0&quot;</span>
GLOBAL_ALLOW = <span style="color: #ff0000;">&quot;&quot;</span>
GLOBAL_DENY = <span style="color: #ff0000;">&quot;&quot;</span>
GLOBAL_IGNORE = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Like APF, you can configure global lists for multiple server deployments. You&#8217;ll need to specify a URL of the text file with the IP addresses for the global lists.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>SPAMHAUSE Blocklist</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_SPAMHAUS = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This option enables the SPAMHAUS blocklist. Specify the number of seconds between refreshes. Recommended setting is 86400 (1 day).</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking TOR Exit IP Addresses</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_TOR = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>Enabling this option will block TOR exit IP addresses. If you are not familiar with <a href="https://www.torproject.org/">TOR</a>, it is a completely anonymous proxy network. This could block some legitimate users who are trying to protect their anonymity, so I would recommend only turning this on if you are already under attack from a TOR exit address.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Bogon Addresses</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_BOGON = <span style="color: #ff0000;">&quot;0&quot;</span>
LF_BOGON_URL = <span style="color: #ff0000;">&quot;http://www.cymru.com/Documents/bogon-bn-agg.txt&quot;</span>
LF_BOGON_SKIP = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Blocking bogon addresses (addresses that should not be possible) is usually a good decision. To enable, set the number of seconds between refreshes. I recommend enabling this option and setting the refresh at 86400 (1 day). If you do so, be sure to add your private network adapters to the skip list.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Country-Specific Access to Your Server</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CC_DENY = <span style="color: #ff0000;">&quot;&quot;</span>
CC_ALLOW = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>With these options, you can block or allow entire countries from accessing your server. To do so, enter the country codes in a comma separated list. Even though this generates a lot of additional rules, it&#8217;s valuable to some sysadmins.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CC_ALLOW_FILTER = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>Alternatively, you can set your server to exclusively accept traffic from a list of country codes. All other countries not listed will have their traffic dropped. There are many other settings related to these options that I don&#8217;t have time to cover in this blog.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Login Failures</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_TRIGGER = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This enables blocking of login failures (per service). There are a lot of great customization options in this section.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Scanning Directories for Malicious Files</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_DIRWATCH = <span style="color: #ff0000;">&quot;300&quot;</span></pre></div></div>

<p>This feature scans <code>/tmp</code> and <code>/dev/shm</code> for potentially malicious files and alerts you to their presence based on the interval you designate. You can also have CSF automatically quarantine malicious files with this option:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_DIRWATCH_DISABLE = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Distributed Attack Protection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LF_DISTATTACK = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>By enabling this option, you activate additional protection against distributed attacks.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Based on Abusive Email Usage</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LT_POP3D = <span style="color: #ff0000;">&quot;0&quot;</span>
LT_IMAPD = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>If a user checks email too many times per hour (more than the non-zero value specified), the user&#8217;s IP address is blocked.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Email Alert Following Block</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LT_EMAIL_ALERT = <span style="color: #ff0000;">&quot;1&quot;</span></pre></div></div>

<p>This will send you email when something is blocked. I&#8217;d recommend leaving it on.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking IP Addresses Based on Number of Connections</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">CT_LIMIT = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This feature tracks connections and blocks the IP if the number of connections is too high. Use caution because if you enable this option and set this value too low, it will block legitimate traffic.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Application-Level Protection</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PT_LIMIT = <span style="color: #ff0000;">&quot;60&quot;</span></pre></div></div>

<p>This feature provides application level protection against malicious scripts that take a long time to execute.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Blocking Port Scanners</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PS_INTERVAL = <span style="color: #ff0000;">&quot;300&quot;</span>
PS_LIMIT = <span style="color: #ff0000;">&quot;10&quot;</span></pre></div></div>

<p style="margin-bottom:0; padding-bottom:5px;"><strong>Enabling HTML User Interface for CSF</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">UI = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>CSF has a built-in HTML user interface. You can enable this by setting UI = &#8220;1&#8243;. There are a list of prerequisites for this option in the <code>readme.txt</code>.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Notifying Blocked IP Addresses</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">MESSENGER = <span style="color: #ff0000;">&quot;0&quot;</span></pre></div></div>

<p>This option will notify blocked IP addresses when they have been blocked by the firewall.</p>
<p style="margin-bottom:0; padding-bottom:5px;"><strong>Port Knocking</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">PORTKNOCKING = <span style="color: #ff0000;">&quot;&quot;</span></pre></div></div>

<p>CSF supports port knocking, which is a technique that provides an additional layer of security. See <a href="http://www.portknocking.org/">http://www.portknocking.org/</a> for details. </p>
<h3>Allow and Deny Lists</h3>
<p>As we walked through the CSF configuration file, you saw that I referenced the <code>csf.deny</code> file, so it should come as no surprise that CSF also includes <code>csf.allow</code> to customize &#8220;allow&#8221; rules as well. If you are familiar with APF, these files have a very similar syntax &#8230; Each entry is made up of the same four components: <code>protocol|flow|port|IP</code>. The only real difference being that APF uses the colon as a delimiter while CSF uses the pipe:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#APF Version</span>
tcp:<span style="color: #000000; font-weight: bold;">in</span>:<span style="color: #007800;">d</span>=<span style="color: #000000;">48000</span>_48020:<span style="color: #007800;">s</span>=10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#CSF Version</span>
tcp<span style="color: #000000; font-weight: bold;">|</span><span style="color: #000000; font-weight: bold;">in</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #007800;">d</span>=<span style="color: #000000;">48000</span>_48020<span style="color: #000000; font-weight: bold;">|</span><span style="color: #007800;">s</span>=10.0.0.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8</span></pre></div></div>

<p>Fortunately, replacing your colon with a pipe is a minimally invasive procedure that can be automated with a tool like vi.</p>
<h3>CSF Command Line Tool</h3>
<p>The command line tool for CSF is much more robust than the one for APF:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ csf <span style="color: #660033;">--help</span>
csf: v5.79 <span style="color: #7a0874; font-weight: bold;">&#40;</span>cPanel<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
ConfigServer Security <span style="color: #000000; font-weight: bold;">&amp;</span> Firewall
<span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000;">2006</span>-<span style="color: #000000;">2013</span>, Way to the Web Limited <span style="color: #7a0874; font-weight: bold;">&#40;</span>http:<span style="color: #000000; font-weight: bold;">//</span>www.configserver.com<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Usage: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>csf <span style="color: #7a0874; font-weight: bold;">&#91;</span>option<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>value<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Option              Meaning
-h, <span style="color: #660033;">--help</span>          Show this message
-l, <span style="color: #660033;">--status</span>        List<span style="color: #000000; font-weight: bold;">/</span>Show iptables configuration
-l6, <span style="color: #660033;">--status6</span>      List<span style="color: #000000; font-weight: bold;">/</span>Show ip6tables configuration
-s, <span style="color: #660033;">--start</span>         Start firewall rules
-f, <span style="color: #660033;">--stop</span>          Flush<span style="color: #000000; font-weight: bold;">/</span>Stop firewall rules <span style="color: #7a0874; font-weight: bold;">&#40;</span>Note: lfd may restart csf<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-r, <span style="color: #660033;">--restart</span>       Restart firewall rules
-q, <span style="color: #660033;">--startq</span>        Quick restart <span style="color: #7a0874; font-weight: bold;">&#40;</span>csf restarted by lfd<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-sf, <span style="color: #660033;">--startf</span>       Force CLI restart regardless of LF_QUICKSTART setting
-a, <span style="color: #660033;">--add</span> ip        Allow an IP and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.allow
-ar, <span style="color: #660033;">--addrm</span> ip     Remove an IP from <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.allow and delete rule
-d, <span style="color: #660033;">--deny</span> ip       Deny an IP and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-dr, <span style="color: #660033;">--denyrm</span> ip    Unblock an IP and remove from <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-df, <span style="color: #660033;">--denyf</span>        Remove and unblock all entries <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-g, <span style="color: #660033;">--grep</span> ip       Search the iptables rules <span style="color: #000000; font-weight: bold;">for</span> an IP match <span style="color: #7a0874; font-weight: bold;">&#40;</span>incl. CIDR<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-t, <span style="color: #660033;">--temp</span>          Displays the current list of temp IP entries and their TTL
-tr, <span style="color: #660033;">--temprm</span> ip    Remove an IPs from the temp IP ban and allow list
-td, <span style="color: #660033;">--tempdeny</span> ip ttl <span style="color: #7a0874; font-weight: bold;">&#91;</span>-p port<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>-d direction<span style="color: #7a0874; font-weight: bold;">&#93;</span>
                    Add an IP to the temp IP ban list. ttl is how long to
                    blocks <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>default:seconds, can use one suffix of h<span style="color: #000000; font-weight: bold;">/</span>m<span style="color: #000000; font-weight: bold;">/</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
                    Optional port. Optional direction of block can be one of:
                    <span style="color: #000000; font-weight: bold;">in</span>, out or inout <span style="color: #7a0874; font-weight: bold;">&#40;</span>default:<span style="color: #000000; font-weight: bold;">in</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
-ta, <span style="color: #660033;">--tempallow</span> ip ttl <span style="color: #7a0874; font-weight: bold;">&#91;</span>-p port<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>-d direction<span style="color: #7a0874; font-weight: bold;">&#93;</span>
                    Add an IP to the temp IP allow list <span style="color: #7a0874; font-weight: bold;">&#40;</span>default:inout<span style="color: #7a0874; font-weight: bold;">&#41;</span>
-tf, <span style="color: #660033;">--tempf</span>        Flush all IPs from the temp IP entries
-cp, <span style="color: #660033;">--cping</span>        PING all members <span style="color: #000000; font-weight: bold;">in</span> an lfd Cluster
-cd, <span style="color: #660033;">--cdeny</span> ip     Deny an IP <span style="color: #000000; font-weight: bold;">in</span> a Cluster and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-ca, <span style="color: #660033;">--callow</span> ip    Allow an IP <span style="color: #000000; font-weight: bold;">in</span> a Cluster and add to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.allow
-cr, <span style="color: #660033;">--crm</span> ip       Unblock an IP <span style="color: #000000; font-weight: bold;">in</span> a Cluster and remove from <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf.deny
-cc, <span style="color: #660033;">--cconfig</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>name<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>value<span style="color: #7a0874; font-weight: bold;">&#93;</span>
                    Change configuration option <span style="color: #7a0874; font-weight: bold;">&#91;</span>name<span style="color: #7a0874; font-weight: bold;">&#93;</span> to <span style="color: #7a0874; font-weight: bold;">&#91;</span>value<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">in</span> a Cluster
-cf, <span style="color: #660033;">--cfile</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Send <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #c20cb9; font-weight: bold;">file</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">in</span> a Cluster to <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>csf<span style="color: #000000; font-weight: bold;">/</span>
-crs, <span style="color: #660033;">--crestart</span>    Cluster restart csf and lfd
-w, <span style="color: #660033;">--watch</span> ip      Log SYN packets <span style="color: #000000; font-weight: bold;">for</span> an IP across iptables chains
-m, <span style="color: #660033;">--mail</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>addr<span style="color: #7a0874; font-weight: bold;">&#93;</span>   Display Server Check <span style="color: #000000; font-weight: bold;">in</span> HTML or email to <span style="color: #7a0874; font-weight: bold;">&#91;</span>addr<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">if</span> present
-lr, <span style="color: #660033;">--logrun</span>       Initiate Log Scanner report via lfd
-c, <span style="color: #660033;">--check</span>         Check <span style="color: #000000; font-weight: bold;">for</span> updates to csf but <span style="color: #000000; font-weight: bold;">do</span> not upgrade
-u, <span style="color: #660033;">--update</span>        Check <span style="color: #000000; font-weight: bold;">for</span> updates to csf and upgrade <span style="color: #000000; font-weight: bold;">if</span> available
<span style="color: #660033;">-uf</span>                 Force an update of csf
-x, <span style="color: #660033;">--disable</span>       Disable csf and lfd
-e, <span style="color: #660033;">--enable</span>        Enable csf and lfd <span style="color: #000000; font-weight: bold;">if</span> previously disabled
-v, <span style="color: #660033;">--version</span>       Show csf version</pre></div></div>

<p>The command line tool will also tell you if the testing mode is enabled (which is a very useful feature). If TESTING were enabled, we&#8217;d see this line at the bottom of the output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*</span>WARNING<span style="color: #000000; font-weight: bold;">*</span> TESTING mode is enabled - <span style="color: #000000; font-weight: bold;">do</span> not forget to disable it <span style="color: #000000; font-weight: bold;">in</span> the configuration</pre></div></div>

<p>Did you make it all the way through?! Great! I know it&#8217;s a lot to take in, but it&#8217;s not terribly complicated when we break it down and understand how each piece works. Next time, I&#8217;ll be back with some tips on integrating CSF into cPanel. </p>
<p>-Mark</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2013/iptables-tips-and-tricks-csf-configuration/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>UNIX Sysadmin Boot Camp: bash &#8211; Keyboard Shortcuts</title>
		<link>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-bash-keyboard-shortcuts/</link>
		<comments>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-bash-keyboard-shortcuts/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 15:50:17 +0000</pubDate>
		<dc:creator>Ryan Robson</dc:creator>
				<category><![CDATA[Customer Service]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[boot camp]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[excute]]></category>
		<category><![CDATA[keyboard shortcut]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[support]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=6476</guid>
		<description><![CDATA[On the support team, we&#8217;re jumping in and out of shells constantly. At any time during my work day, I&#8217;ll see at least four instances of PuTTY in my task bar, so one thing I learned quickly was that efficiency and accuracy in accessing ultimately make life easier for our customers and for us as [...]]]></description>
			<content:encoded><![CDATA[<p>On the support team, we&#8217;re jumping in and out of shells constantly. At any time during my work day, I&#8217;ll see at least four instances of <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a> in my task bar, so one thing I learned quickly was that efficiency and accuracy in accessing ultimately make life easier for our customers and for us as well. Spending too much time rewriting paths, commands, VI navigation, and history cycling can really bring you to a crawl. So now that you have had some time to study <a href="http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-bash/">bash</a> and practice a little, I thought I&#8217;d share some of the keyboard shortcuts that help us work as effectively and as expediently as we do. I won&#8217;t be able to cover <em>all</em> of the shortcuts, but these are the ones I use most:</p>
<h3>Tab</h3>
<p style="margin-top:0; padding-top: 0;">[Tab] is one of the first keyboard shortcuts that most people learn, and it&#8217;s ever-so-convenient. Let&#8217;s say you just downloaded <code>pckg54andahalf-5.2.17-v54-2-x86-686-Debian.tar.gz</code>, but a quick listing of the directory shows you ALSO downloaded <code>5.1.11</code>, <code>4.8.6</code> and <code>1.2.3</code> at some point in the past. What was that file name again? Fret not. You know you downloaded 5.2.<em>something</em>, so you just start with, say, <code>pckg</code>, and hit [Tab]. This autocompletes everything that it can match to a unique file name, so if there are no other files that start with &#8220;<code>pckg</code>,&#8221; it will populate the whole file name (and this can occur at any point in a command).</p>
<p>In this case, we&#8217;ve got <em>four</em> different files that are similar:<br />
<code style="background-color:yellow;">pckg54andahalf-5.2.17-v54-2-x86-686-Debian.tar.gz</code> <-- we want this one<br />
<code style="background-color:gray;">pckg54andahalf-5.1.11-v54-2-x86-686-Debian.tar.gz</code><br />
<code style="background-color:gray;">pckg54andahalf-4.8.6-v54-2-x86-686-Debian.tar.gz</code><br />
<code style="background-color:gray;">pckg54andahalf-1.2.3-v54-2-x86-686-Debian.tar.gz</code></p>
<p>So typing "<code>pckg</code>" and hitting [Tab] brings up:<br />
<code>pckg54andahalf-</code></p>
<p><em>NOW</em>, what you could do, knowing what files are there already, is type "<code>5.2</code>" and hit [Tab] again to fill out the rest. However, if you <em>didn't</em> know what the potential matches were, you could <strong>double-tap [Tab]</strong>. This displays all matching file names with that string.</p>
<p>Another fun fact: This trick also works in Windows. <img src='http://blog.softlayer.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h3>CTRL+R</h3>
<p style="margin-top:0; padding-top: 0;">[CTRL+R] is a very underrated shortcut in my humble opinion. When you've been working in the shell for untold hours parsing logs, moving files and editing configs, your bash history can get pretty immense. Often you'll come across a situation where you want to reproduce a command or series of commands that were run regarding a specific file or circumstance. You <em>could</em> type "<code>history</code>" and pore through the commands line by line, but I propose something more efficient: a reverse search.</p>
<p>Example: I've just hopped on my system and discovered that my SVN server isn't doing what it's supposed to. I want to take a look at any SVN related commands that were executed from bash, so I can make sure there were no errors. I'd simply hit [CTRL+R], which would pull up the following prompt:</p>
<p><code>(reverse-i-search)`':</code></p>
<p>Typing "<code>s</code>" at this point would immediately return the first command with the letter "<code>s</code>" in it in the history ... Keep in mind that's not just <em>starting</em> with s, it's <em>containing</em> an s. Finishing that out to "<code>svn</code>" brings up any command executed with those letters in that order. Pressing [CTRL+R] again at this point will cycle through the commands one by one.</p>
<p>In the search, I find the command that was run incorrectly ... There was a typo in it. I can edit the command <em>within</em> the search prompt before hitting enter and committing it to the command prompt. Pretty handy, right? This can quickly become one of your most used shortcuts.</p>
<h3>CTRL+W &#038; CTRL+Y</h3>
<p style="margin-top:0; padding-top: 0;">This pair of shortcuts is the one I find myself using the most. [CTRL+W] will basically take the word before your cursor and "cut" it, just like you would with [CTRL+X] in Windows if you highlighted a word. A "word" doesn't really describe what it cuts in bash, though ... It uses whitespace as a delimiter, so if you have an ultra long file path that you'll probably be using multiple times down the road, you can [CTRL+W] that sucker and keep it stowed away.</p>
<p>Example: I'm typing <code>nano /etc/httpd/conf/httpd.conf</code> (Related: The redundancy of this path always irked me just a little).<br />
Before hitting [ENTER] I tap [CTRL+W], which chops that path right back out and stores it to memory. Because I want to run that command right now as well, I hit [CTRL+Y] to <em>paste</em> it back into the line. When I'm done with that and I'm out referencing other logs or doing work on other files and need to come back to it, I can simply type "<code>nano </code>" and hit [CTRL+Y] to go right back into that file.</p>
<h3>CTRL+C</h3>
<p style="margin-top:0; padding-top: 0;">For the sake of covering most of my bases, I want to make sure that [CTRL+C] is covered. Not only is it useful, but it's absolutely essential for standard shell usage. This little shortcut performs the most invaluable act of killing whatever process you were running at that point. This can go for most anything, aside from the programs that have their own interfaces and kill commands (vi, nano, etc). If you start something, there's a pretty good chance you're going to want to stop it eventually.</p>
<p>I should be clear that this will terminate a process unless that process is otherwise instructed to trap [CTRL+C] and perform a different function. If you're compiling something or running a database command, generally you won't want to use this shortcut unless you know what you're doing. But, when it comes to everyday usage such as running a "<code>top</code>" and then quitting, it's essential.</p>
<h3>Repeating a Command</h3>
<p style="margin-top:0; padding-top: 0;">There are four simple ways you can easily repeat a command with a keyboard shortcut, so I thought I'd run through them here before wrapping up:</p>
<ol>
<li>The [UP] arrow will display the previously executed command.</li>
<li>[CTRL+P] will do the exact same thing as the [UP] arrow.</li>
<li>Typing "<code>!!</code>" and hitting [Enter] will execute the previous command. <em>Note that this actually runs it. The previous two options only display the command, giving you the option to hit [ENTER].</em></li>
<li>Typing "<code>!-1</code>" will do the same thing as "<code>!!</code>", though I want to point out how it does this: When you type "<code>history</code>", you see a numbered list of commands executed in the past <code>-1</code> being the most recent. What "<code>!-1</code>" does is instructs the shell to execute (<code>!</code>) the first item on the history (<code>-1</code>). This same concept can be applied for any command in the history at all ... This can be useful for scripting.</li>
</ol>
<h3>Start Practicing</h3>
<p style="margin-top:0; padding-top: 0;">What it really comes down to is finding what works for you and what suits your work style. There are a number of other shortcuts that are definitely worthwhile to take a look at. There are plenty of cheat sheets on the internet available to print out while you're learning, and I'd highly recommend checking them out. Trust me on this: You'll never regret honing your mastery of bash shortcuts, particularly once you've seen the lightning speed at which you start flying through the command line. The tedium goes away, and the shell becomes a much more friendly, dare I say <em>inviting</em>, place to be.</p>
<p style="margin-bottom:0; padding-bottom:0;"><strong>Quick reference for these shortcuts:</strong></p>
<ul style="margin-top:0; padding-top:0;">
<li><strong>[TAB]</strong> - Autocomplete to furthest point in a unique matching file name or path.</li>
<li><strong>[CTRL+R]</strong> - Reverse search through your bash history</li>
<li><strong>[CTRL+W]</strong> - Cut one "word" back, or until whitespace encountered.</li>
<li><strong>[CTRL+Y]</strong> - Paste a previously cut string</li>
<li><strong>[CTRL+P]</strong> - Display previously run command</li>
<li><strong>[UP]</strong> - Display previously run command</li>
</ul>
<p>-Ryan</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-bash-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>UNIX Sysadmin Boot Camp: bash</title>
		<link>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-bash/</link>
		<comments>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-bash/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 18:00:49 +0000</pubDate>
		<dc:creator>Ryan Robson</dc:creator>
				<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[boot camp]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[control panel]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=4508</guid>
		<description><![CDATA[Welcome back to UNIX Sysadmin Boot Camp. You&#8217;ve had a few days to get some reps in accessing your server via SSH, so it&#8217;s about time we add some weight to your exercise by teaching you some of the tools you will be using regularly to manage your server. As we mentioned earlier in this [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome back to UNIX Sysadmin Boot Camp. You&#8217;ve had a few days to get some reps in <a href="http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-an-intro-to-ssh/">accessing your server via SSH</a>, so it&#8217;s about time we add some weight to your exercise by teaching you some of the tools you will be using regularly to manage your server.</p>
<p>As we mentioned earlier in this series, customers with control panels from cPanel and Parallels might be tempted to rely solely on those graphical interfaces. They are much more user-friendly in terms of performing routine server administration tasks, but at some point, you might need to get down and dirty on the command line. It&#8217;s almost inevitable. This is where you&#8217;ll use <strong>bash</strong> commands.  </p>
<p>Here are some of the top 10 essential commands you should get to know and remember in bash. <em>Click any of the commands to go to its official &#8220;manual&#8221; page.</em></p>
<ol>
<li><a href="http://linuxmanpages.com/man1/man.1.php"><code>man</code></a> &ndash; This command provides a manual of other bash commands. Want more info on a command? Type <code>man commandname</code>, and you&#8217;ll get more information about &#8220;commandname&#8221; than you probably wanted to know. It&#8217;s extremely useful if you need a quick reference for a command, and it&#8217;s often much more detailed and readable than a simple <code>--help</code> or <code>--h</code> extension.</li>
<li><a href="http://www.computerhope.com/unix/uls.htm"><code>ls</code></a> &ndash; This command lets you list results. I showed you an example of this above, but the amount of options that are available to you with this command are worth looking into. Using the &#8220;manual&#8221; command above, run <code>man ls</code> and check out the possibilities. For example, if you&#8217;re in <code>/etc</code>, running <code>ls -l /etc</code> will get you a slightly more detailed list. My most commonly used list command is <code>ls -hal</code>. Pop quiz for you (where you can test your <code>man</code> skills): What does the <code>-hal</code> mean?</li>
<li><a href="http://www.computerhope.com/unix/ucd.htm"><code>cd</code></a> &ndash; This command lets you change directories. Want to go to <code>/etc/</code>? <code>cd /etc/</code> will take you there. Want to jump back a directory? <code>cd ..</code> does the trick.</li>
<li><a href="http://www.computerhope.com/unix/umv.htm"><code>mv</code></a> &ndash; This command enables you to move files and folders. The syntax is <code>mv originalpath/to/file newpath/to/file</code>. Simple! There are more options that you can check out with the <code>man</code> command.</li>
<li><a href="http://www.computerhope.com/unix/urm.htm"><code>rm</code></a> &ndash; This command enables you to remove a file or directory. In the same vein as the <code>mv</code> command, this is one of those basic commands that you just have to know. By running <code>rm filename</code>, you remove the &#8220;filename&#8221; file.</li>
<li><a href="http://www.computerhope.com/unix/ucp.htm"><code>cp</code></a> &ndash; This command enables you to copy files from one place to another. Want to make a backup of a file before editing it? Run <code>cp origfile.bla origfile.bak</code>, and you have a backup in case your edit of <code>origfile.bla</code> goes horrendously wrong and makes babies cry. The syntax is simply: <code>cp /source /destination</code>. As with the above commands, check out the manual by running <code>man cp</code> for more options.</li>
<li><a href="http://linuxmanpages.com/man1/tar.1.php"><code>tar</code></a> &ndash; On its own, <code>tar</code> is a command to group a bunch of files together, uncompressed. These files can then be compressed into .gzip format. The command can be used for creating or extracting, so it may be a good idea to familiarize yourself with the parameters, as you may find yourself using it quite often. For a GUI equivalent, think 7-zip or WinRAR for Windows.</li>
<li><a href="http://linuxmanpages.com/man1/wget.1.php"><code>wget</code></a> &ndash; I love the simplicity of this little command. It enables you to &#8220;get&#8221; or download a target file. Yes, there are options, but all you need is a direct link to a file, and you just pull one of these: <code>wget urlhere</code>. Bam! That file starts downloading. Doesn&#8217;t matter what kind of file it is, it&#8217;s downloaded.</li>
<li><a href="http://linuxmanpages.com/man1/top.1.php"><code>top</code></a> &ndash; This handy little binary will give you a live view of memory and CPU usage currently affecting your machine, and is useful for finding out where you need to optimize. It can also help you pinpoint what processes may be causing a slowdown or a load issue.</li>
<li><a href="http://linuxmanpages.com/man1/chmod.1.php"><code>chmod</code></a> &ndash; This little sucker is vital to make your server both secure and usable, particularly when you&#8217;re going to be serving for the public like you would with a web server. Combine good usage of permission and iptables, and you have a locked down server</li>
</ol>
<p>When you understand how to use these tools, you can start to monitor and track what&#8217;s actually happening on your server. The more you know about your server, the more effective and efficient you can make it. In our next installment, we&#8217;ll touch on some of the most common server logs and what you can do with the information they provide.</p>
<p>Did I miss any of your &#8220;essential&#8221; bash commands in my top 10 list? Leave a comment below with your favorites along with a quick explanation of what they do.</p>
<p>-Ryan</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-bash/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>UNIX Sysadmin Boot Camp: An Intro to SSH</title>
		<link>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-an-intro-to-ssh/</link>
		<comments>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-an-intro-to-ssh/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 20:13:24 +0000</pubDate>
		<dc:creator>Ryan Robson</dc:creator>
				<category><![CDATA[SoftLayer]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[boot camp]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[information]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[teach]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[walkthrough]]></category>

		<guid isPermaLink="false">http://blog.softlayer.com/?p=4488</guid>
		<description><![CDATA[You&#8217;ve got a &#8216;nix box set up. For some reason, you feel completely lost and powerless. It happens. Many a UNIX-related sob has been cried by confused and frustrated sysadmins, and it needs to stop. As a techie on the front lines of support, I&#8217;ve seen firsthand the issues that new and curious sysadmins seem [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve got a &#8216;nix box set up. For some reason, you feel completely lost and powerless. It happens. Many a UNIX-related sob has been cried by confused and frustrated sysadmins, and it needs to stop. As a techie on the front lines of support, I&#8217;ve seen firsthand the issues that new and curious sysadmins seem to have. We have a lot of customers who like to dive head-first into a new environment, and we even encourage it. But there&#8217;s quite a learning curve.</p>
<p>In my tenure at SoftLayer, I&#8217;ve come across a lot of customers who rely almost entirely on control panels provided by partners like cPanel and Parallels to administer their servers. While those panels simplify some fairly complex tasks to the touch of a button, we all know that one day you&#8217;re going to have to get down and dirty in that SSH (Secure Shell) interface that so many UNIX server newbies fear. </p>
<p>I&#8217;m here to tell you that SSH can be your friend, if you treat it right. Graphical user interfaces like the ones used in control panels have been around for quite a while now, and despite the fact that we are in &#8220;the future,&#8221; the raw power of a command line is still unmatched in its capabilities. It&#8217;s a force to be reckoned with.</p>
<p>If you&#8217;re accustomed to a UNIX-based interface, this may seem a little elementary, but you and I both know that as we get accustomed to something, we also tend to let those all-important &#8220;basics&#8221; slip from our minds. If you&#8217;re coming from a Windows background and are new to the environment, you&#8217;re in for a bit of a shell shock, no pun intended. The command line is fantastically powerful once you master it &#8230; It just takes a little time and effort to learn. </p>
<p>We&#8217;ll start slow and address some of the most common pain points for new sysadmins, and as we move forward, we&#8217;ll tackle advanced topics. Set your brain to &#8220;absorbent,&#8221; and visualize soaking up these UNIX tips like some kind of undersea, all-knowing, Yoda-like sea sponge.</p>
<h3>SSH</h3>
<p>SSH allows data to be exchanged securely between two networked devices, and when the &#8220;network&#8221; between your workstation and server is the Internet, the fact that it does so &#8220;securely&#8221; is significant. Before you can do any actual wielding of SSH, you&#8217;re going to need to know how to find this exotic &#8220;command line&#8221; we&#8217;ve talked so much about. </p>
<p>You can use a third-party client such as <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/">PuTTY</a>, <a href="http://winscp.net/eng/index.php">WinSCP</a> if your workstation is Windows-based, or if you&#8217;re on Linux or Mac, you can access SSH from your terminal application: <code>ssh user@ipaddress</code>. Once you&#8217;ve gotten into your server, you&#8217;ll probably want to find out where you are, so give the <code>pwd</code> command a try:</p>
<p><code>user@serv: ~$ pwd<br />
/home/user<br />
user@serv: ~$</code></p>
<p>It&#8217;s as easy as that. Now we know we&#8217;re in the <code>/home/user</code> directory. Most of the time, you&#8217;ll find yourself starting in your home directory. This is where you can put personal files and documents. It&#8217;s kind of like &#8220;My Documents&#8221; in Windows, just on your server.</p>
<p>Now that you know where you are, you&#8217;ll probably want to know what&#8217;s in there. Take a look at these commands (extracted from a RedHat environment, but also usable in CentOS and many other distributions):</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src $ ls &nbsp;&nbsp;&nbsp;</code><br />
This will give you a basic listing of the current directory.</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src $ ls /usr/src/redhat &nbsp;&nbsp;&nbsp;</code><br />
This will list the contents of another specified directory.</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src $ ls ./redhat &nbsp;&nbsp;&nbsp;</code><br />
Using a &#8220;relative pathname,&#8221; this will perform the same action as above.</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src $ ls redhat &nbsp;&nbsp;&nbsp;</code><br />
Most of the time, you&#8217;ll get the same results even without the &#8220;<code>./</code>&#8221; at the beginning.</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src $ cd /usr/src/redhat/ &nbsp;&nbsp;&nbsp;</code><br />
This is an example of using the <code>cd</code> command to change directories to an absolute pathname.</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src $ cd redhat &nbsp;&nbsp;&nbsp;</code><br />
This is an example of using the <code>cd</code> command to change directories to a relative pathname.</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src/redhat $ cd /usr/src &nbsp;&nbsp;&nbsp;</code><br />
To move back on directory from the working directory, you can use the destination&#8217;s absolute path.</p>
<p><code style="color:#FFFFFF; background-color: #000000;">&nbsp;&nbsp;&nbsp; user@serv: /usr/src/redhat $ cd .. &nbsp;&nbsp;&nbsp;</code><br />
Or, since the desired directory is one step down, you can use two dots to move back.</p>
<p>You&#8217;ll notice many similarities to the typical Windows DOS prompts, so it helps if you&#8217;re familiar with navigating through that interface: <code>dir</code>, <code>cd</code>, <code>cd ..</code>, <code>cd /</code>. Everything else on the other hand, will prove to be a bit different.</p>
<p>Now that you&#8217;re able to access this soon-to-be-powerful-for-you tool, you need to start learning the language of the natives: <strong>bash</strong>. In our next installment, we&#8217;ll take a crash course in bash, and you&#8217;ll start to get comfortable navigating and manipulating content directly on your server. </p>
<p>Bookmark the SoftLayer Blog and come back regularly to get the latest installments in our &#8220;UNIX Sysadmin Boot Camp&#8221; series!</p>
<p>-Ryan</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.softlayer.com/2011/unix-sysadmin-boot-camp-an-intro-to-ssh/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
