<?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>ServerAdmins.NET &#187; linux</title>
	<atom:link href="http://serveradmins.net/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://serveradmins.net</link>
	<description>Stuff for Server Admins...</description>
	<lastBuildDate>Fri, 09 Jul 2010 16:46:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Howto show the current runlevel in linux&#8230;</title>
		<link>http://serveradmins.net/howto-show-the-current-runlevel-in-linux/</link>
		<comments>http://serveradmins.net/howto-show-the-current-runlevel-in-linux/#comments</comments>
		<pubDate>Fri, 28 May 2010 12:51:17 +0000</pubDate>
		<dc:creator>chrism</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[init.d]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rc3.d]]></category>
		<category><![CDATA[runlevel]]></category>

		<guid isPermaLink="false">http://serveradmins.net/?p=76</guid>
		<description><![CDATA[How to detect and change the current runlevel in Linux]]></description>
			<content:encoded><![CDATA[<p>Quick one here, mostly for my own notes than anything else. <img src='http://serveradmins.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>An easy way to see the existing runlevel is with the &#8216;who -r&#8217; command.</p>
<p><code><br />
root@server:~ # who -r<br />
         run-level 3  May 22 03:54                   last=S<br />
</code></p>
<p>Here we show the last boot and current runlevel (3).   In order to modify this, you can open up /etc/inittab and look for the following line.</p>
<p><code><br />
id:3:initdefault:<br />
</code></p>
<p>This shows that runlevel 3 is the default one kicked off by init on a bootup.</p>
<p>For what it&#8217;s worth, this refers to the directories in /etc/rc.d/rcX.d/, where X is  #.  The number correlates to the runlevel of your machine, and all of the scripts stored in that directory are executed when that runlevel is enabled.</p>
<p>TMYK!</p>
]]></content:encoded>
			<wfw:commentRss>http://serveradmins.net/howto-show-the-current-runlevel-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Port to PID mappings, or What process is using that port?</title>
		<link>http://serveradmins.net/port-to-pid-mappings-or-what-process-is-using-that-port/</link>
		<comments>http://serveradmins.net/port-to-pid-mappings-or-what-process-is-using-that-port/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 00:59:37 +0000</pubDate>
		<dc:creator>chrism</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[fuser]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mapping]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[tcp]]></category>
		<category><![CDATA[udp]]></category>

		<guid isPermaLink="false">http://serveradmins.net/?p=54</guid>
		<description><![CDATA[fuser is awesome for port to pid mappings or what process is using a specific port.]]></description>
			<content:encoded><![CDATA[<p>Okay, I&#8217;m lazy.  I fully admit it.   Want proof?  Instead of writing up a huge long post articulating something with awesome analogies, I&#8217;m only going to talk about one command today. </p>
<p>Fuser.</p>
<p>Why? </p>
<p>fuser is awesome.  Not awesome in a &#8220;run it and it fixes everything&#8221; way, but awesome in a &#8220;What in the hell is binding to this port??&#8221; kind of way.   Two classic scenarios where this is handy&#8230;</p>
<p>1.  Apache won&#8217;t start, &#8220;Can&#8217;t bind to port ::80&#8243; or &#8220;Can&#8217;t bind to port ::443&#8243;, etc.  This typically means something else is already tied to that port, and won&#8217;t relinquish it&#8230; </p>
<p>2.  A security scan of your machine shows something funny running on port 6667&#8230; You didn&#8217;t start this or know what it is.  </p>
<p>What to do now? Well you can sift through netstat output, but that&#8217;s, well, boring and slightly annoying.</p>
<p>netstat output<br />
<code><br />
[root@vps ~]# netstat -anp |grep 80<br />
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      3266/httpd<br />
tcp        0      0 127.0.0.1:58725             127.0.0.1:80                TIME_WAIT   -<br />
tcp        0      0 10.10.10.10:2078          192.168.1.23:63024          ESTABLISHED 18088/cpdavd - acce<br />
unix  3      [ ]         STREAM     CONNECTED     49222880 11574/dovecot-auth  /var/run/dovecot/login/default<br />
unix  2      [ ]         DGRAM                    6804658 14078/named<br />
</code></p>
<p>Okay now we see that 3266/httpd is running on 80.  Then we do this to find the process..</p>
<p><code><br />
[root@vps ~]# ps auxwww |grep 3266<br />
nobody    3266  0.0  0.3  65704  3516 ?        S    17:05   0:00 /usr/local/apache/bin/httpd -k start -DSSL<br />
root     21665  0.0  0.0   6024   640 pts/2    S+   18:51   0:00 grep 3266<br />
[root@vps ~]#<br />
</code></p>
<p>Okay there we go&#8230; </p>
<p>Now for hacked systems, this could (and probably) is fully forged for a lot of remote shells.  Going back to my previous post at http://serveradmins.net/ssh-on-nonstandard-ports-how-to-not-do-it/ which talks about priveleged ports, you could in theory have trojaned &#8216;ps&#8217;, top, etc masking that real process.  It may *look* like httpd, but bound to a port like 23425&#8230;     So dont&#8217;t trust that too much, but a bit on that in a second. <img src='http://serveradmins.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The fuser approach&#8230;</p>
<p><code><br />
[root@vps ~]# fuser -n tcp 80<br />
80/tcp:               3266  3267  3268  3269  3271 16078 18274<br />
[root@vps ~]#<br />
</code></p>
<p>Oh look at that a list of all pids bound to that port.  Nice, clean, to the point and easily parsable.    fuser rocks. <img src='http://serveradmins.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now a bit more about the masked processes&#8230; To run those down, here&#8217;s a quick tip.  Forget ps/top and your other normal utilities, /proc/ is your friend here&#8230;</p>
<p>Proc looks like this on a linux box&#8230;<br />
<code><br />
[root@vps ~]# cd /proc/<br />
[root@vps proc]# ls -al<br />
total 1<br />
dr-xr-xr-x 78 root     root        0 Jan 26 09:58 .<br />
drwxr-xr-x 24 chrismm  chrismm  1024 Feb  4 22:06 ..<br />
dr-xr-xr-x  4 root     root        0 Feb  5 05:05 1<br />
dr-xr-xr-x  4 root     root        0 Feb  5 05:05 11573<br />
dr-xr-xr-x  4 root     root        0 Feb  5 05:05 11574<br />
dr-xr-xr-x  4 dovecot  dovecot     0 Feb  5 05:05 11575<br />
dr-xr-xr-x  4 dovecot  dovecot     0 Feb  5 05:05 11576<br />
...<br />
...<br />
</code></p>
<p>These directories match the pids of the running process&#8230;   So if you have something advertising itself as &#8216;httpd&#8217; on port 234234 and you know it&#8217;s pid 3266, you&#8217;d just do the following&#8230;</p>
<p><code><br />
[root@vps proc]# cd /proc/3266<br />
[root@vps 3266]# ls -al<br />
total 0<br />
dr-xr-xr-x  4 nobody nobody 0 Feb  5 17:08 .<br />
dr-xr-xr-x 78 root   root   0 Jan 26 09:58 ..<br />
-r--------  1 root   root   0 Feb  5 18:56 auxv<br />
-r--r--r--  1 root   root   0 Feb  5 17:08 cmdline<br />
-rw-r--r--  1 root   root   0 Feb  5 18:56 coredump_filter<br />
-r--r--r--  1 root   root   0 Feb  5 18:56 cpuset<br />
lrwxrwxrwx  1 root   root   0 Feb  5 18:54 cwd -> /<br />
-r--------  1 root   root   0 Feb  5 18:56 environ<br />
lrwxrwxrwx  1 root   root   0 Feb  5 17:10 exe -> /usr/local/apache/bin/httpd<br />
dr-x------  2 root   root   0 Feb  5 18:49 fd<br />
?r--r--r--  1 root   root   0 Feb  5 18:56 io<br />
-r--------  1 root   root   0 Feb  5 18:56 limits<br />
-rw-r--r--  1 root   root   0 Feb  5 18:56 loginuid<br />
-r--r--r--  1 root   root   0 Feb  5 18:54 maps<br />
-rw-------  1 root   root   0 Feb  5 18:56 mem<br />
-r--r--r--  1 root   root   0 Feb  5 18:56 mounts<br />
-r--------  1 root   root   0 Feb  5 18:56 mountstats<br />
-r--r--r--  1 root   root   0 Feb  5 18:56 numa_maps<br />
-rw-r--r--  1 root   root   0 Feb  5 18:56 oom_adj<br />
-r--r--r--  1 root   root   0 Feb  5 18:56 oom_score<br />
lrwxrwxrwx  1 root   root   0 Feb  5 18:54 root -> /<br />
-r--r--r--  1 root   root   0 Feb  5 18:56 schedstat<br />
-r--------  1 root   root   0 Feb  5 18:56 smaps<br />
-r--r--r--  1 root   root   0 Feb  5 17:08 stat<br />
-r--r--r--  1 root   root   0 Feb  5 17:10 statm<br />
-r--r--r--  1 root   root   0 Feb  5 17:08 status<br />
dr-xr-xr-x  3 nobody nobody 0 Feb  5 18:56 task<br />
-r--r--r--  1 root   root   0 Feb  5 18:56 wchan<br />
[root@vps 3266]#<br />
</code></p>
<p>Bam, there you go.  cwd and exe are the things you&#8217;re looking for  It shows you the dir it was spawned from (typically a users homedirectory on a shared hosting machine) and the full path/binary actually being executed (usually lame perl/php listeners)&#8230;   Also the ./fd/ folder is kind of neat as it shows you all the open file handles tied up by that pid as well.</p>
<p>Anyway, /proc/ examination too, is for another day, I just wanted to ramble on about one of my favorite, neat little single use utilities that no one else seems to know about. fuser.  Enjoy. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://serveradmins.net/port-to-pid-mappings-or-what-process-is-using-that-port/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->