<?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>Justin Lim</title>
	<atom:link href="http://www.gooksu.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gooksu.com</link>
	<description>walking in circles</description>
	<lastBuildDate>Wed, 16 May 2012 00:49:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Cool AWK trick &#8211; remove duplicate lines without sort</title>
		<link>http://www.gooksu.com/2012/05/15/cool-awk-trick-remove-duplicate-lines-without-sort/</link>
		<comments>http://www.gooksu.com/2012/05/15/cool-awk-trick-remove-duplicate-lines-without-sort/#comments</comments>
		<pubDate>Wed, 16 May 2012 00:48:22 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=290</guid>
		<description><![CDATA[I always do something like cat file &#124; sort -n &#124; uniq to get a unique listing of a file to remove duplicates. the only problem with this is that it sorts the list so the ordering of the file &#8230; <a href="http://www.gooksu.com/2012/05/15/cool-awk-trick-remove-duplicate-lines-without-sort/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I always do something like cat file | sort -n | uniq to get a unique listing of a file to remove duplicates.  the only problem with this is that it sorts the list so the ordering of the file is lost..</p>
<p>found a cool trick with AWK today of removing duplicate lines without destroying the order and yet its just a one liner!</p>
<p>awk &#8216;!a[$0]++&#8217; file</p>
<p>lets take an example<br />
$ cat abc<br />
ddd<br />
bbb<br />
eee<br />
fff<br />
aaa<br />
ccc<br />
bbb<br />
kkk<br />
aaa<br />
zzz<br />
xxx<br />
yyy</p>
<p>now :<br />
$ awk &#8216;!a[$0]++&#8217; abc<br />
ddd<br />
bbb<br />
eee<br />
fff<br />
aaa<br />
ccc<br />
kkk<br />
zzz<br />
xxx<br />
yyy</p>
<p>enjoy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2012/05/15/cool-awk-trick-remove-duplicate-lines-without-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DNSMASQ &#8211; home network changes</title>
		<link>http://www.gooksu.com/2012/04/04/dnsmasq-home-network-changes/</link>
		<comments>http://www.gooksu.com/2012/04/04/dnsmasq-home-network-changes/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 16:08:22 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[ad-block]]></category>
		<category><![CDATA[dhcp]]></category>
		<category><![CDATA[dnsmasq]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=281</guid>
		<description><![CDATA[Desided to make some changes to the home network using dnsmasq. dnsmasq is a light weight dns cache/dhcp/tftp server that is easy to configure and manage and does not require a large footprint as far as memory or cpu. In &#8230; <a href="http://www.gooksu.com/2012/04/04/dnsmasq-home-network-changes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Desided to make some changes to the home network using dnsmasq.  dnsmasq is a light weight dns cache/dhcp/tftp server that is easy to configure and manage and does not require a large footprint as far as memory or cpu.</p>
<p>In my home network I have a main router which acted as a wireless access point and dhcp server which plugs into my MOCA network and to the gigE switch for the wired machines.  I have another wireless AP on the MOCA network to extend my wireless footprint.</p>
<p>dnsmasq pretty much works right out of the box however I wanted to add some specific settings.</p>
<p><strong>DNS cache &#8211; with some ad blocking</strong><br />
used the services from <a href="http://pgl.yoyo.org/adservers/">yoyo.org</a> to create a block list of sites in dnsmasq format and update it weekly onto /etc/dnsmasq.d with a simple cronjob.</p>
<blockquote><p>wget -O /etc/dnsmasq.d/ad-block-list &#8220;http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&#038;showintro=0&#038;startdate%5Bday%5D=&#038;startdate%5Bmonth%5D=&#038;startdat<br />
e%5Byear%5D=&#038;mimetype=plaintext&#8221;</p></blockquote>
<p>this will help to block spam/ad sites and ads from appearing in various sites and also stop most popups.</p>
<p><strong>DHCP Server</strong><br />
dnsmasq allows you to bundle DHCP server with the same daemon. so i&#8217;ve moved the DHCP server from the main router to this server and set my router to DHCP relay.  DHCP server within dnsmasq is actually pretty robust and feature rich and the following was the config i&#8217;ve used</p>
<blockquote><p>expand-hosts<br />
domain=sullung.com<br />
dhcp-range=192.168.1.150,192.168.1.200,255.255.255.0,12h<br />
dhcp-option=3,192.168.1.1<br />
dhcp-option=42,0.0.0.0<br />
dhcp-option=6,192.168.1.29,209.18.47.61<br />
dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases</p></blockquote>
<p>you can also set static IP&#8217;s via DHCP by using the following :<br />
dhcp-host=MAC,HOSTNAME,IP,DURATION</p>
<p>Lastly you can add dns entries for your non routable servers using :<br />
address=/domain/IP</p>
<p>the config lines are pretty self explanatory but if you want more details you can always view the man pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2012/04/04/dnsmasq-home-network-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find deleted open files</title>
		<link>http://www.gooksu.com/2012/04/03/find-deleted-open-files/</link>
		<comments>http://www.gooksu.com/2012/04/03/find-deleted-open-files/#comments</comments>
		<pubDate>Tue, 03 Apr 2012 20:54:08 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lsof]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=278</guid>
		<description><![CDATA[When your disk usage does not match the usage summary or when you have a full filesystem yet you&#8217;ve removed the files you are most likely dealing with open files. To find open files use lsof +L1 and kill the &#8230; <a href="http://www.gooksu.com/2012/04/03/find-deleted-open-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When your disk usage does not match the usage summary or when you have a full filesystem yet you&#8217;ve removed the files you are most likely dealing with open files.</p>
<p>To find open files use lsof +L1 and kill the PID so that the space will be freedup</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2012/04/03/find-deleted-open-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Troubleshooting with the multipathd Interactive Console</title>
		<link>http://www.gooksu.com/2011/05/17/troubleshooting-with-the-multipathd-interactive-console/</link>
		<comments>http://www.gooksu.com/2011/05/17/troubleshooting-with-the-multipathd-interactive-console/#comments</comments>
		<pubDate>Tue, 17 May 2011 14:25:33 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[multipath]]></category>
		<category><![CDATA[multipathd]]></category>
		<category><![CDATA[san]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=274</guid>
		<description><![CDATA[The multipathd -k command is an interactive interface to the multipathd daemon. Entering this command brings up an interactive multipath console. After entering this command, you can enter help to get a list of available commands, you can enter a interactive command, &#8230; <a href="http://www.gooksu.com/2011/05/17/troubleshooting-with-the-multipathd-interactive-console/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">The multipathd -k command is an interactive interface to the multipathd daemon. Entering this command brings up an interactive multipath console. After entering this command, you can enter help to get a list of available commands, you can enter a interactive command, or you can enter CTRL-D to quit.</div>
<div id="_mcePaste"></div>
<div>The multipathd interactive console can be used to troubleshoot problems you may be having with your system. For example, the following command sequence displays the multipath configuration, including the defaults, before exiting the console.</div>
<blockquote>
<div id="_mcePaste"># multipathd -k</div>
<div id="_mcePaste">&gt; &gt; show config</div>
<div id="_mcePaste">&gt; &gt; CTRL-D</div>
</blockquote>
<div id="_mcePaste">The following command sequence ensures that multipath has picked up any changes to the</div>
<div id="_mcePaste">multipath.conf,</div>
<blockquote>
<div id="_mcePaste"># multipathd -k</div>
<div id="_mcePaste">&gt; &gt; reconfigure</div>
<div id="_mcePaste">&gt; &gt; CTRL-D</div>
</blockquote>
<div id="_mcePaste">Use the following command sequence to ensure that the path checker is working properly.</div>
<blockquote>
<div id="_mcePaste"># multipathd -k</div>
<div id="_mcePaste">&gt; &gt; show paths</div>
<div id="_mcePaste">&gt; &gt; CTRL-D</div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2011/05/17/troubleshooting-with-the-multipathd-interactive-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent yum from updating RHEL to a new release</title>
		<link>http://www.gooksu.com/2011/04/07/prevent-yum-from-updating-rhel-to-a-new-release/</link>
		<comments>http://www.gooksu.com/2011/04/07/prevent-yum-from-updating-rhel-to-a-new-release/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 13:27:12 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[rhel]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=270</guid>
		<description><![CDATA[Sometimes you will run into a scenario where you need to keep an OS at certain version due to vendor support. Such as EMC/IBM SAN powerpath etc.. You might also want to remain at a certain version due to change &#8230; <a href="http://www.gooksu.com/2011/04/07/prevent-yum-from-updating-rhel-to-a-new-release/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes you will run into a scenario where you need to keep an OS at certain version due to vendor support. Such as EMC/IBM SAN powerpath etc.. You might also want to remain at a certain version due to change management policies.</p>
<p>In this example I like to use yum to keep my RHEL guest current with security and bug fixes. The problem I ran into is that Red Hat has released a new minor version of it’s Enterprise Linux 5.x, and so yum wants to update to it. Well have no fear, as there is one line you need to add to yum.conf to solve your problem.</p>
<p># vi /etc/yum.conf</p>
<p>add this within [main]: exclude=redhat-release*</p>
<p>exit and save changes</p>
<p>Now you can run sudo yum update and you will still be at your RHEL 5.x version (issue cat /etc/redhat-release to double check)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2011/04/07/prevent-yum-from-updating-rhel-to-a-new-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Packet Analyzer: 15 TCPDUMP Command Examples</title>
		<link>http://www.gooksu.com/2010/12/27/packet-analyzer-15-tcpdump-command-examples/</link>
		<comments>http://www.gooksu.com/2010/12/27/packet-analyzer-15-tcpdump-command-examples/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 17:15:40 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[tcpdump]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=268</guid>
		<description><![CDATA[Thanks the geek stuff tcpdump command is also called as packet analyzer. tcpdump command will work on most flavors of unix operating system. tcpdump allows us to save the packets that are captured, so that we can use it for &#8230; <a href="http://www.gooksu.com/2010/12/27/packet-analyzer-15-tcpdump-command-examples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thanks <a href="http://www.thegeekstuff.com/2010/08/tcpdump-command-examples/">the geek stuff</a></p>
<p>tcpdump command is also called as packet analyzer. </p>
<p>tcpdump command will work on most flavors of unix operating system. tcpdump allows us to save the packets that are captured, so that we can use it for future analysis. The saved file can be viewed by the same tcpdump command. We can also use open source software like wireshark to read the tcpdump pcap files.</p>
<p>In this tcpdump tutorial, let us discuss some practical examples on how to use the tcpdump command.<br /> <br />
<span id="more-5676"></span></p>
<h3>1. Capture packets from a particular ethernet interface using tcpdump -i</h3>
<p>When you execute tcpdump command without any option, it will capture all the packets flowing through all the interfaces. -i option with tcpdump command, allows you to filter on a particular ethernet interface.</p>
<pre>$ tcpdump -i eth1
14:59:26.608728 IP xx.domain.netbcp.net.52497 &gt; valh4.lell.net.ssh: . ack 540 win 16554
14:59:26.610602 IP resolver.lell.net.domain &gt; valh4.lell.net.24151:  4278 1/0/0 (73)
14:59:26.611262 IP valh4.lell.net.38527 &gt; resolver.lell.net.domain:  26364+ PTR? 244.207.104.10.in-addr.arpa. (45)</pre>
<p>In this example, tcpdump captured all the packets flows in the interface eth1 and displays in the standard output.</p>
<p><strong>Note</strong>: <a href="http://www.thegeekstuff.com/2009/02/editcap-guide-11-examples-to-handle-network-packet-dumps-effectively/">Editcap</a> utility is used to select or remove specific packets from dump file and translate them into a given format.</p>
<h3>2. Capture only N number of packets using tcpdump -c</h3>
<p>When you execute tcpdump command it gives packets until you cancel the tcpdump command. Using -c option you can specify the number of packets to capture.</p>
<pre>$ tcpdump -c 2 -i eth0
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
14:38:38.184913 IP valh4.lell.net.ssh &gt; yy.domain.innetbcp.net.11006: P 1457255642:1457255758(116) ack 1561463966 win 63652
14:38:38.690919 IP valh4.lell.net.ssh &gt; yy.domain.innetbcp.net.11006: P 116:232(116) ack 1 win 63652
2 packets captured
13 packets received by filter
0 packets dropped by kernel</pre>
<p>The above tcpdump command captured only 2 packets from interface eth0.</p>
<p><strong>Note:</strong><a href="http://www.thegeekstuff.com/2009/03/mergecap-and-tshark-merge-packet-dumps-and-analyze-network-traffic/"> Mergecap and TShark</a>: Mergecap is a packet dump combining tool, which will combine multiple dumps into a single dump file. Tshark is a powerful tool to capture network packets, which can be used to analyze the network traffic. It comes with wireshark network analyzer distribution.</p>
<h3>3. Display Captured Packets in ASCII using tcpdump -A</h3>
<p>The following tcpdump syntax prints the packet in ASCII.</p>
<pre>$ tcpdump -A -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
14:34:50.913995 IP valh4.lell.net.ssh &gt; yy.domain.innetbcp.net.11006: P 1457239478:1457239594(116) ack 1561461262 win 63652
E.....@.@..]..i...9...*.V...]...P....h....E...&gt;{..U=...g.
......G..7\+KA....A...L.
14:34:51.423640 IP valh4.lell.net.ssh &gt; yy.domain.innetbcp.net.11006: P 116:232(116) ack 1 win 63652
E.....@.@..\..i...9...*.V..*]...P....h....7......X..!....Im.S.g.u:*..O&amp;....^#Ba...
E..(R.@.|.....9...i.*...]...V..*P..OWp........</pre>
<p><strong>Note:</strong> <a href="http://www.thegeekstuff.com/2009/03/ifconfig-7-examples-to-configure-network-interface/">Ifconfig</a> command is used to configure network interfaces</p>
<h3>4. Display Captured Packets in HEX and ASCII using tcpdump -XX</h3>
<p>Some users might want to analyse the packets in hex values. tcpdump provides a way to print packets in both ASCII and HEX format.</p>
<pre>$tcpdump -XX -i eth0
18:52:54.859697 IP zz.domain.innetbcp.net.63897 &gt; valh4.lell.net.ssh: . ack 232 win 16511
        0x0000:  0050 569c 35a3 0019 bb1c 0c00 0800 4500  .PV.5.........E.
        0x0010:  0028 042a 4000 7906 c89c 10b5 aaf6 0f9a  .(.*@.y.........
        0x0020:  69c4 f999 0016 57db 6e08 c712 ea2e 5010  i.....W.n.....P.
        0x0030:  407f c976 0000 0000 0000 0000            @..v........
18:52:54.877713 IP 10.0.0.0 &gt; all-systems.mcast.net: igmp query v3 [max resp time 1s]
        0x0000:  0050 569c 35a3 0000 0000 0000 0800 4600  .PV.5.........F.
        0x0010:  0024 0000 0000 0102 3ad3 0a00 0000 e000  .$......:.......
        0x0020:  0001 9404 0000 1101 ebfe 0000 0000 0300  ................
        0x0030:  0000 0000 0000 0000 0000 0000            ............</pre>
<h3>5. Capture the packets and write into a file using tcpdump -w</h3>
<p>tcpdump allows you to save the packets to a file, and later you can use the packet file for further analysis.</p>
<pre>$ tcpdump -w 08232010.pcap -i eth0
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
32 packets captured
32 packets received by filter
0 packets dropped by kernel</pre>
<p>-w option writes the packets into a given file. The file extension should be .pcap, which can be read by any network protocol<br /> <br />
analyzer.</p>
<h3>6. Reading the packets from a saved file using tcpdump -r</h3>
<p>You can read the captured pcap file and view the packets for analysis, as shown below.</p>
<pre>$tcpdump -tttt -r data.pcap
2010-08-22 21:35:26.571793 00:50:56:9c:69:38 (oui Unknown) &gt; Broadcast, ethertype Unknown (0xcafe), length 74:
        0x0000:  0200 000a ffff 0000 ffff 0c00 3c00 0000  ............&lt;...
        0x0010:  0000 0000 0100 0080 3e9e 2900 0000 0000  ........&gt;.).....
        0x0020:  0000 0000 ffff ffff ad00 996b 0600 0050  ...........k...P
        0x0030:  569c 6938 0000 0000 8e07 0000            V.i8........
2010-08-22 21:35:26.571797 IP valh4.lell.net.ssh &gt; zz.domain.innetbcp.net.50570: P 800464396:800464448(52) ack 203316566 win 71
2010-08-22 21:35:26.571800 IP valh4.lell.net.ssh &gt; zz.domain.innetbcp.net.50570: P 52:168(116) ack 1 win 71
2010-08-22 21:35:26.584865 IP valh5.lell.net.ssh &gt; 11.154.12.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADC</pre>
<h3>7. Capture packets with IP address using tcpdump -n</h3>
<p>In all the above examples, it prints packets with the DNS address, but not the ip address. The following example captures the packets and it will display the IP address of the machines involved.</p>
<pre>$ tcpdump -n -i eth0
15:01:35.170763 IP 10.0.19.121.52497 &gt; 11.154.12.121.ssh: P 105:157(52) ack 18060 win 16549
15:01:35.170776 IP 11.154.12.121.ssh &gt; 10.0.19.121.52497: P 23988:24136(148) ack 157 win 113
15:01:35.170894 IP 11.154.12.121.ssh &gt; 10.0.19.121.52497: P 24136:24380(244) ack 157 win 113</pre>
<h3>8. Capture packets with proper readable timestamp using tcpdump -tttt</h3>
<pre>$ tcpdump -n -tttt -i eth0

2010-08-22 15:10:39.162830 IP 10.0.19.121.52497 &gt; 11.154.12.121.ssh: . ack 49800 win 16390
2010-08-22 15:10:39.162833 IP 10.0.19.121.52497 &gt; 11.154.12.121.ssh: . ack 50288 win 16660
2010-08-22 15:10:39.162867 IP 10.0.19.121.52497 &gt; 11.154.12.121.ssh: . ack 50584 win 16586</pre>
<h3>9. Read packets longer than N bytes</h3>
<p>You can receive only the packets greater than n number of bytes using a filter &#8216;greater&#8217; through tcpdump command</p>
<pre>$ tcpdump -w g_1024.pcap greater 1024</pre>
<h3>10. Receive only the packets of a specific protocol type</h3>
<p>You can receive the packets based on the protocol type. You can specify one of these protocols &#8212; fddi, tr, wlan, ip, ip6, arp, rarp, decnet, tcp and udp. The following example captures only arp packets flowing through the eth0 interface.</p>
<pre>$ tcpdump -i eth0 arp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
19:41:52.809642 arp who-has valh5.lell.net tell valh9.lell.net
19:41:52.863689 arp who-has 11.154.12.1 tell valh6.lell.net
19:41:53.024769 arp who-has 11.154.12.1 tell valh7.lell.net</pre>
<h3>11. Read packets lesser than N bytes</h3>
<p>You can receive only the packets lesser than n number of bytes using a filter &#8216;less&#8217; through tcpdump command</p>
<pre>$ tcpdump -w l_1024.pcap  less 1024</pre>
<h3>12. Receive packets flows on a particular port using tcpdump port</h3>
<p>If you want to know all the packets received by a particular port on a machine, you can use tcpdump command as shown below.</p>
<pre>$ tcpdump -i eth0 port 22
19:44:44.934459 IP valh4.lell.net.ssh &gt; zz.domain.innetbcp.net.63897: P 18932:19096(164) ack 105 win 71
19:44:44.934533 IP valh4.lell.net.ssh &gt; zz.domain.innetbcp.net.63897: P 19096:19260(164) ack 105 win 71
19:44:44.934612 IP valh4.lell.net.ssh &gt; zz.domain.innetbcp.net.63897: P 19260:19424(164) ack 105 win 71</pre>
<h3>13. Capture packets for particular destination IP and Port</h3>
<p>The packets will have source and destination IP and port numbers. Using tcpdump we can apply filters on source or destination IP and port number. The following command captures packets flows in eth0, with a particular destination ip and port number 22.</p>
<pre>$ tcpdump -w xpackets.pcap -i eth0 dst 10.181.140.216 and port 22</pre>
<h3>14. Capture TCP communication packets between two hosts</h3>
<p>If two different process from two different machines are communicating through tcp protocol, we can capture those packets using tcpdump as shown below.</p>
<pre>$tcpdump -w comm.pcap -i eth0 dst 16.181.170.246 and port 22</pre>
<p>You can open the file comm.pcap using any network protocol analyzer tool to debug any potential issues.</p>
<h3>15. tcpdump Filter Packets &#8211; Capture all the packets other than arp and rarp</h3>
<p>In tcpdump command, you can give &#8220;and&#8221;, &#8220;or&#8221; and &#8220;not&#8221; condition to filter the packets accordingly.</p>
<pre>$ tcpdump -i eth0 not arp and not rarp
20:33:15.479278 IP resolver.lell.net.domain &gt; valh4.lell.net.64639:  26929 1/0/0 (73)
20:33:15.479890 IP valh4.lell.net.16053 &gt; resolver.lell.net.domain:  56556+ PTR? 255.107.154.15.in-addr.arpa. (45)
20:33:15.480197 IP valh4.lell.net.ssh &gt; zz.domain.innetbcp.net.63897: P 540:1504(964) ack 1 win 96
20:33:15.487118 IP zz.domain.innetbcp.net.63897 &gt; valh4.lell.net.ssh: . ack 540 win 16486
20:33:15.668599 IP 10.0.0.0 &gt; all-systems.mcast.net: igmp query v3 [max resp time 1s]</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2010/12/27/packet-analyzer-15-tcpdump-command-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Database Startup and Shutdown Procedure</title>
		<link>http://www.gooksu.com/2010/12/27/oracle-database-startup-and-shutdown-procedure/</link>
		<comments>http://www.gooksu.com/2010/12/27/oracle-database-startup-and-shutdown-procedure/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 17:13:58 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=265</guid>
		<description><![CDATA[thanks the geek stuff How To Startup Oracle Database 1. Login to the system with oracle username Typical oracle installation will have oracle as username and dba as group. On Linux, do su to oracle as shown below. $ su &#8230; <a href="http://www.gooksu.com/2010/12/27/oracle-database-startup-and-shutdown-procedure/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>thanks <a href="http://www.thegeekstuff.com/2009/01/oracle-database-startup-and-shutdown-procedure/">the geek stuff</a></p>
<h2>How To Startup Oracle Database</h2>
<h3>1. Login to the system with oracle username</h3>
<p>Typical oracle installation will have oracle as username and dba as group. On Linux, do su to oracle as shown below.</p>
<pre>$ su - oracle</pre>
<h3>2. Connect to oracle sysdba</h3>
<p>Make sure ORACLE_SID and ORACLE_HOME are set properly as shown below.</p>
<pre>$ env | grep ORA
ORACLE_SID=DEVDB
ORACLE_HOME=/u01/app/oracle/product/10.2.0</pre>
<p><code> </code><br /> <br />
You can connect using either &#8220;/ as sysdba&#8221; or an oracle account that has DBA privilege.</p>
<pre>$ sqlplus '/ as sysdba'
SQL*Plus: Release 10.2.0.3.0 - Production on Sun Jan 18 11:11:28 2009
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning and Data Mining options
SQL&gt;</pre>
<h3>3. Start Oracle Database</h3>
<p>The default SPFILE (server parameter file) is located under $ORACLE_HOME/dbs. Oracle will use this SPFILE during startup, if you don&#8217;t specify PFILE.<br /> <br />
<code> </code><br /> <br />
Oracle will look for the parameter file in the following order under $ORACLE_HOME/dbs. If any one of them exist, it will use that particular parameter file.</p>
<ol>
<li>spfile$ORACLE_SID.ora</li>
<li>spfile.ora</li>
<li>init$ORACLE_SID.ora</li>
</ol>
<p><code> </code><br /> <br />
Type &#8220;startup&#8221; at the SQL command prompt to startup the database as shown below.</p>
<pre>SQL&gt; startup
ORACLE instance started.

Total System Global Area  812529152 bytes
Fixed Size                  2264280 bytes
Variable Size             960781800 bytes
Database Buffers           54654432 bytes
Redo Buffers                3498640 bytes
Database mounted.
Database opened.
SQL&gt;</pre>
<p><code> </code><br /> <br />
If you want to startup Oracle with PFILE, pass it as a parameter as shown below.</p>
<pre>SQL&gt; STARTUP PFILE=/u01/app/oracle/product/10.2.0/dbs/init.ora</pre>
<h2>How To Shutdown Oracle Database</h2>
<p>Following three methods are available to shutdown the oracle database:</p>
<ol>
<li> Normal Shutdown</li>
<li> Shutdown Immediate</li>
<li> Shutdown Abort</li>
</ol>
<h3>1. Normal Shutdown</h3>
<p>During normal shutdown, before the oracle database is shut down, oracle will wait for all active users to disconnect their sessions.  As the parameter name (normal) suggest, use this option to shutdown the database under normal conditions.</p>
<pre>SQL&gt; shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL&gt;</pre>
<h3>2. Shutdown Immediate</h3>
<p>During immediate shutdown, before the oracle database is shut down, oracle will rollback active transaction and disconnect all active users. Use this option when there is a problem with your database and you don&#8217;t have enough time to request users to log-off.</p>
<pre>SQL&gt; shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL&gt;</pre>
<h3>3. Shutdown Abort</h3>
<p>During shutdown abort, before the oracle database is shutdown, all user sessions will be terminated immediately. Uncomitted transactions will not be rolled back. Use this option only during emergency situations when the &#8220;shutdown&#8221; and &#8220;shutdown immediate&#8221; doesn&#8217;t work.</p>
<pre>$ sqlplus '/ as sysdba'
SQL*Plus: Release 10.2.0.3.0 - Production on Sun Jan 18 11:11:33 2009
Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.
Connected to an idle instance.

SQL&gt; shutdown abort
ORACLE instance shut down.
SQL&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2010/12/27/oracle-database-startup-and-shutdown-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>9 Linux ethtool Examples to Manipulate Ethernet Card (NIC Card)</title>
		<link>http://www.gooksu.com/2010/12/27/9-linux-ethtool-examples-to-manipulate-ethernet-card-nic-card/</link>
		<comments>http://www.gooksu.com/2010/12/27/9-linux-ethtool-examples-to-manipulate-ethernet-card-nic-card/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 17:04:35 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[ethtool]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nic]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=262</guid>
		<description><![CDATA[Thanks to the geek stuff 1. List Ethernet Device Properties When you execute ethtool command with a device name, it displays the following information about the ethernet device. # ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported &#8230; <a href="http://www.gooksu.com/2010/12/27/9-linux-ethtool-examples-to-manipulate-ethernet-card-nic-card/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://www.thegeekstuff.com/2010/10/ethtool-command/">the geek stuff</a></p>
<h3>1. List Ethernet Device Properties</h3>
<p>When you execute ethtool command with a device name, it displays the following information about the ethernet device.<br /> <br />
<span id="more-6372"></span></p>
<pre># ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: d
        Wake-on: d
        Link detected: yes
</pre>
<p>This above ethtool output displays ethernet card properties such as speed, wake on, duplex and the link detection status. Following are the three types of duplexes available.</p>
<ul>
<li>Full duplex : Enables sending and receiving of packets at the same time. This mode is used when the ethernet device is connected to a switch.</li>
<li>Half duplex : Enables either sending or receiving of packets at a single point of time. This mode is used when the ethernet device is connected to a hub.</li>
<li>Auto-negotiation : If enabled, the ethernet device itself decides whether to use either full duplex or half duplex based on the network the ethernet device attached to.</li>
</ul>
<h3>2. Change NIC Parameter Using ethtool Option -s autoneg</h3>
<p>The above ethtool eth0 output displays that the &#8220;Auto-negotiation&#8221; parameter is in enabled state. You can disable this using autoneg option in the ethtool as shown below.</p>
<pre># ifdown eth0
    eth0      device: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
    eth0      configuration: eth-bus-pci-0000:0b:00.0

# ethtool  -s eth0 autoneg off

# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  Not reported
        Advertised auto-negotiation: No
        Speed: Unknown! (65535)
        Duplex: Unknown! (255)
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: g
        Wake-on: g
        Link detected: no
# ifup eth0
</pre>
<p>After the above change, you could see that the &#8220;link detection&#8221; value changed to down and auto-negotiation is in off state.</p>
<h3>3. Change the Speed of Ethernet Device</h3>
<p>Using ethtool you can change the speed of the ethernet device to work with the certain network devices, and the newly assign speed value should be within the limited capacity.</p>
<pre># ethtool -s eth0 speed 100 autoneg off

# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  Not reported
        Advertised auto-negotiation: No
        Speed: Unknown! (65535)
        Duplex: Unknown! (255)
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: g
        Wake-on: g
        Link detected: no
</pre>
<p>Once you change the speed when the adapter is online, it automatically goes offline, and you need to bring it back online using ifup command.</p>
<pre># ifup eth0
    eth0      device: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
    eth0      configuration: eth-bus-pci-0000:0b:00.0
Checking for network time protocol daemon (NTPD):                     running

# ethtool eth0
Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  Not reported
        Advertised auto-negotiation: No
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: g
        Wake-on: g
        Link detected: yes
</pre>
<p>As shown in the above output, the speed changed from 1000Mb/s to 100Mb/s and auto-negotiation parameter is unset.</p>
<p>To change the Maximum Transmission Unit (MTU), refer to our <a href="http://www.thegeekstuff.com/2009/03/ifconfig-7-examples-to-configure-network-interface/">ifconfig examples</a> article.</p>
<h3>4. Display Ethernet Driver Settings</h3>
<p>ethtool -i option displays driver version, firmware version and bus details as shown below.</p>
<pre># ethtool -i eth0
driver: bnx2
version: 2.0.1-suse
firmware-version: 1.9.3
bus-info: 0000:04:00.0
</pre>
<h3>5. Display Auto-negotiation, RX and TX of eth0</h3>
<p>View the autonegotiation details about the specific ethernet device as shown below.</p>
<pre># ethtool -a eth0
Pause parameters for eth0:
Autonegotiate:  on
RX:             on
TX:             on
</pre>
<h3>6. Display Network Statistics of Specific Ethernet Device</h3>
<p>Use ethtool -S option to display the bytes transfered, received, errors, etc, as shown below.</p>
<pre># ethtool -S eth0
NIC statistics:
     rx_bytes: 74356477841
     rx_error_bytes: 0
     tx_bytes: 110725861146
     tx_error_bytes: 0
     rx_ucast_packets: 104169941
     rx_mcast_packets: 138831
     rx_bcast_packets: 59543904
     tx_ucast_packets: 118118510
     tx_mcast_packets: 10137453
     tx_bcast_packets: 2221841
     tx_mac_errors: 0
     tx_carrier_errors: 0
     rx_crc_errors: 0
     rx_align_errors: 0
     tx_single_collisions: 0
     tx_multi_collisions: 0
     tx_deferred: 0
     tx_excess_collisions: 0
     tx_late_collisions: 0
     tx_total_collisions: 0
     rx_fragments: 0
     rx_jabbers: 0
     rx_undersize_packets: 0
     rx_oversize_packets: 0
     rx_64_byte_packets: 61154057
     rx_65_to_127_byte_packets: 55038726
     rx_128_to_255_byte_packets: 426962
     rx_256_to_511_byte_packets: 3573763
     rx_512_to_1023_byte_packets: 893173
     rx_1024_to_1522_byte_packets: 42765995
     rx_1523_to_9022_byte_packets: 0
     tx_64_byte_packets: 3633165
     tx_65_to_127_byte_packets: 51169838
     tx_128_to_255_byte_packets: 3812067
     tx_256_to_511_byte_packets: 113766
     tx_512_to_1023_byte_packets: 104081
     tx_1024_to_1522_byte_packets: 71644887
     tx_1523_to_9022_byte_packets: 0
     rx_xon_frames: 0
     rx_xoff_frames: 0
     tx_xon_frames: 0
     tx_xoff_frames: 0
     rx_mac_ctrl_frames: 0
     rx_filtered_packets: 14596600
     rx_discards: 0
     rx_fw_discards: 0
</pre>
<h3>7. Troubleshoot the Ethernet Connection Issues</h3>
<p>When there is a problem with the network connection, you might want to check (or change) the ethernet device parameters explained in the above examples, when you see following issues in the output of ethtool command.</p>
<ul>
<li>Speed and Duplex value is shown as Unknown</li>
<li>Link detection value is shown as No</li>
</ul>
<p>Upon successful connection, the three parameters mentioned above gets appropriate values. i.e Speed is assigned with known value, Duplex become either Full/Half, and the Link detection becomes Yes.</p>
<p>After the above changes, if the Link Detection still says &#8220;No&#8221;, check whether there are any issues in the cables that runs from the switch and the system, you might want to dig into that aspect further.</p>
<p>To capture and analyze packets from a specific network interface, use <a href="http://www.thegeekstuff.com/2010/08/tcpdump-command-examples/">tcpdump utility</a>.</p>
<h3>8. Identify Specific Device From Multiple Devices (Blink LED Port of NIC Card)</h3>
<p>Let us assume that you have a machine with four ethernet adapters, and you want to identify the physical port of a particular ethernet card. (For example, eth0).</p>
<p>Use ethtool option -p, which will make the corresponding LED of physical port to blink.</p>
<pre># ethtool -p eth0
</pre>
<h3>9. Make Changes Permanent After Reboot</h3>
<p>If you&#8217;ve changed any ethernet device parameters using the ethtool, it will all disappear after the next reboot, unless you do the following.</p>
<p>On ubuntu, you have to modify /etc/network/interfaces file and add all your changes as shown below.</p>
<pre># vim /etc/network/interfaces
post-up ethtool -s eth2 speed 1000 duplex full autoneg off
</pre>
<p>The above line should be the last line of the file. This will change speed, duplex and autoneg of eth2 device permanently.</p>
<p>On SUSE, modify the /etc/sysconfig/network/ifcfg-eth-id file and include a new script using POST_UP_SCRIPT variable as shown below. Include the below line as the last line in the corresponding eth1 adpater config file.</p>
<pre># vim /etc/sysconfig/network/ifcfg-eth-id
POST_UP_SCRIPT='eth1'
</pre>
<p>Then, create a new file scripts/eth1 as shown below under /etc/sysconfig/network directory. Make sure that the script has execute permission and ensure that the ethtool utility is present under /sbin directory.</p>
<pre># cd /etc/sysconfig/network/

# vim scripts/eth1
#!/bin/bash
/sbin/ethtool -s duplex full speed 100 autoneg off
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2010/12/27/9-linux-ethtool-examples-to-manipulate-ethernet-card-nic-card/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux modprobe Command Examples to View, Install, Remove Modules</title>
		<link>http://www.gooksu.com/2010/12/27/linux-modprobe-command-examples-to-view-install-remove-modules/</link>
		<comments>http://www.gooksu.com/2010/12/27/linux-modprobe-command-examples-to-view-install-remove-modules/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 17:00:07 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[modprobe]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=257</guid>
		<description><![CDATA[Thanks to the geek stuff modprobe utility is used to add loadable modules to the Linux kernel. You can also view and remove modules using modprobe command. Linux maintains /lib/modules/$(uname-r) directory for modules and its configuration files (except /etc/modprobe.conf and &#8230; <a href="http://www.gooksu.com/2010/12/27/linux-modprobe-command-examples-to-view-install-remove-modules/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://www.thegeekstuff.com/2010/11/modprobe-command-examples/">the geek stuff</a></p>
<p>modprobe utility is used to add loadable modules to the Linux kernel. You can also view and remove modules using modprobe command.</p>
<p>Linux maintains /lib/modules/$(uname-r) directory for modules and its configuration files (except /etc/modprobe.conf and /etc/modprobe.d).</p>
<p>In Linux kernel 2.6, the .ko modules are used instead of .o files since that has additional information that the kernel uses to load the modules. The example in this article are done with using modprobe on Ubuntu.<br /> <br />
<span id="more-6478"></span></p>
<h3>1. List Available Kernel Modules</h3>
<p>modprobe -l will display all available modules as shown below.</p>
<pre>$ modprobe -l | less
kernel/arch/x86/kernel/cpu/mcheck/mce-inject.ko
kernel/arch/x86/kernel/cpu/cpufreq/e_powersaver.ko
kernel/arch/x86/kernel/cpu/cpufreq/p4-clockmod.ko
kernel/arch/x86/kernel/msr.ko
kernel/arch/x86/kernel/cpuid.ko
kernel/arch/x86/kernel/apm.ko
kernel/arch/x86/kernel/scx200.ko
kernel/arch/x86/kernel/microcode.ko
kernel/arch/x86/crypto/aes-i586.ko
kernel/arch/x86/crypto/twofish-i586.ko</pre>
<h3>2. List Currently Loaded Modules</h3>
<p>While the above modprobe command shows all available modules, lsmod command will display all modules that are currently loaded in the Linux kernel.</p>
<pre>$ lsmod | less
soundcore          7264   1 snd
ppdev                6688   0
snd_page_alloc   9156    1 snd_pcm
psmouse            56180  0
lp                     8964    0</pre>
<h3>3. Install New modules into Linux Kernel</h3>
<p>In order to insert a new module into the kernel, execute the modprobe command with the module name.</p>
<p>Following example loads vmhgfs module to Linux kernel on Ubuntu.</p>
<pre>$ sudo modprobe vmhgfs</pre>
<p>Once a module is loaded, verify it using lsmod command as shown below.</p>
<pre>$ lsmod | grep vmhgfs
vmhgfs                 50772  0</pre>
<p>The module files are with .ko extension. If you like to know the full file location of a specific Linux kernel module, use modprobe command and do a grep of the module name as shown below.</p>
<pre>$ modprobe | grep vmhgfs
misc/vmhgfs.ko

$ cd /lib/modules/2.6.31-14-generic/misc

$ ls vmhgfs*
vmhgfs.ko</pre>
<p>Note: You can also use insmod for installing new modules into the Linux kernel.</p>
<h3>4. Load New Modules with the Different Name to Avoid Conflicts</h3>
<p>Consider, in some cases you are supposed to load a new module but with the same module name another module got already loaded for different purposes.</p>
<p>If for some strange reasons, the module name you are trying to load into the kernel is getting used (with the same name) by a different module, then you can load the new module using a different name.</p>
<p>To load a module with a different name, use the modprobe option -o as shown below.</p>
<pre>$ sudo modprobe vmhgfs -o vm_hgfs

$ lsmod  | grep vm_hgfs
vm_hgfs                   50772  0</pre>
<h3>5. Remove the Currently Loaded Module</h3>
<p>If you&#8217;ve loaded a module to Linux kernel for some testing purpose, you might want to unload (remove) it from the kernel.</p>
<p>Use modprobe -r option to unload a module from the kernel as shown below.</p>
<pre>modprobe -r vmhgfs</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2010/12/27/linux-modprobe-command-examples-to-view-install-remove-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UNIX / Linux: 10 Netstat Command Examples</title>
		<link>http://www.gooksu.com/2010/12/27/unix-linux-10-netstat-command-examples/</link>
		<comments>http://www.gooksu.com/2010/12/27/unix-linux-10-netstat-command-examples/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 16:57:49 +0000</pubDate>
		<dc:creator>jlim0930</dc:creator>
				<category><![CDATA[System Stuff]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.gooksu.com/?p=254</guid>
		<description><![CDATA[Thanks to the geek stuff Netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc., In this article, let us review 10 practical unix netstat command examples. 1. List All &#8230; <a href="http://www.gooksu.com/2010/12/27/unix-linux-10-netstat-command-examples/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Thanks to <a href="http://www.thegeekstuff.com/2010/03/netstat-command-examples/">the geek stuff</a></p>
<p>Netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.,</p>
<p>In this article, let us review 10 practical unix <strong>netstat command</strong> examples.<br /> <br />
<span id="more-3596"></span></p>
<h3>1. List All Ports (both listening and non listening ports)</h3>
<h4>List all ports using netstat -a</h4>
<pre># netstat -a | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
udp        0      0 *:bootpc                *:*                                

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     6135     /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     5140     /var/run/acpid.socket</pre>
<h4>List all tcp ports using netstat -at</h4>
<pre># netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
tcp        0      0 localhost:ipp           *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN</pre>
<h4>List all udp ports using netstat -au</h4>
<pre># netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 *:bootpc                *:*
udp        0      0 *:49119                 *:*
udp        0      0 *:mdns                  *:*</pre>
<h3>2. List Sockets which are in Listening State</h3>
<h4>List only listening ports using netstat -l</h4>
<pre># netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:ipp           *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN
udp        0      0 *:49119                 *:*</pre>
<h4>List only listening TCP Ports using netstat -lt</h4>
<pre># netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:30037         *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN</pre>
<h4>List only listening UDP Ports using netstat -lu</h4>
<pre># netstat -lu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 *:49119                 *:*
udp        0      0 *:mdns                  *:*</pre>
<h4>List only the listening UNIX Ports using netstat -lx</h4>
<pre># netstat -lx
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     6294     private/maildrop
unix  2      [ ACC ]     STREAM     LISTENING     6203     public/cleanup
unix  2      [ ACC ]     STREAM     LISTENING     6302     private/ifmail
unix  2      [ ACC ]     STREAM     LISTENING     6306     private/bsmtp</pre>
<h3>3. Show the statistics for each protocol</h3>
<h4>Show statistics for all ports using netstat -s</h4>
<pre># netstat -s
Ip:
    11150 total packets received
    1 with invalid addresses
    0 forwarded
    0 incoming packets discarded
    11149 incoming packets delivered
    11635 requests sent out
Icmp:
    0 ICMP messages received
    0 input ICMP message failed.
Tcp:
    582 active connections openings
    2 failed connection attempts
    25 connection resets received
Udp:
    1183 packets received
    4 packets to unknown port received.
.....</pre>
<h4>Show statistics for TCP (or) UDP ports using netstat -st (or) -su</h4>
<pre># netstat -st

# netstat -su</pre>
<h3>4. Display PID and program names in netstat output using netstat -p</h3>
<p>netstat -p option can be combined with any other netstat option. This will add the &#8220;PID/Program Name&#8221; to the netstat output. This is very useful while debugging to identify which program is running on a particular port.</p>
<pre># netstat -pt
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        1      0 ramesh-laptop.loc:47212 192.168.185.75:www        CLOSE_WAIT  2109/firefox
tcp        0      0 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox</pre>
<h3>5. Don&#8217;t resolve host, port and user name in netstat output</h3>
<p>When you don&#8217;t want the name of the host, port or user to be displayed, use netstat -n option. This will display in numbers, instead of resolving the host name, port name, user name.</p>
<p>This also speeds up the output, as netstat is not performing any look-up.</p>
<pre># netstat -an</pre>
<p>If you don&#8217;t want only any one of those three items ( ports, or hosts, or users ) to be resolved, use following commands.</p>
<pre># netsat -a --numeric-ports

# netsat -a --numeric-hosts

# netsat -a --numeric-users</pre>
<h3>6. Print netstat information continuously</h3>
<p>netstat will print information continuously every few seconds.</p>
<pre># netstat -c
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 ramesh-laptop.loc:36130 101-101-181-225.ama:www ESTABLISHED
tcp        1      1 ramesh-laptop.loc:52564 101.11.169.230:www      CLOSING
tcp        0      0 ramesh-laptop.loc:43758 server-101-101-43-2:www ESTABLISHED
tcp        1      1 ramesh-laptop.loc:42367 101.101.34.101:www      CLOSING
^C</pre>
<h3>7. Find the non supportive Address families in your system</h3>
<pre>netstat --verbose</pre>
<p>At the end, you will have something like this.</p>
<pre>	netstat: no support for `AF IPX' on this system.
	netstat: no support for `AF AX25' on this system.
	netstat: no support for `AF X25' on this system.
	netstat: no support for `AF NETROM' on this system.</pre>
<h3>8. Display the kernel routing information using netstat -r</h3>
<pre># netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.1.0     *               255.255.255.0   U         0 0          0 eth2
link-local      *               255.255.0.0     U         0 0          0 eth2
default         192.168.1.1     0.0.0.0         UG        0 0          0 eth2</pre>
<p><strong>Note:</strong> Use netstat -rn to display routes in numeric format without resolving for host-names.</p>
<h3>9. Find out on which port a program is running</h3>
<pre># netstat -ap | grep ssh
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        1      0 dev-db:ssh           101.174.100.22:39213        CLOSE_WAIT  -
tcp        1      0 dev-db:ssh           101.174.100.22:57643        CLOSE_WAIT  -</pre>
<p>Find out which process is using a particular port:</p>
<pre># netstat -an | grep ':80'</pre>
<h3>10. Show the list of network interfaces</h3>
<pre># netstat -i
Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0         0      0      0 0             0      0      0      0 BMU
eth2       1500 0     26196      0      0 0         26883      6      0      0 BMRU
lo        16436 0         4      0      0 0             4      0      0      0 LRU</pre>
<p>Display extended information on the interfaces (similar to ifconfig) using netstat -ie:</p>
<pre># netstat -ie
Kernel Interface table
eth0      Link encap:Ethernet  HWaddr 00:10:40:11:11:11
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Memory:f6ae0000-f6b00000</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gooksu.com/2010/12/27/unix-linux-10-netstat-command-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

