Saturday, April 17, 2010

Netstat Command Fedora/Centos/RedHat/

1. List All Ports (both listening and non listening ports)

List all ports using netstat -a
# 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
List all tcp ports using netstat -at
# 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
List all udp ports using netstat -au
# 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 *:*
2. List Sockets which are in Listening State

List only listening ports using netstat -l
# 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 *:*
List only listening TCP Ports using netstat -lt
# 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
List only listening UDP Ports using netstat -lu
# 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 *:*
List only the listening UNIX Ports using netstat -lx
# 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
3. Show the statistics for each protocol

Show statistics for all ports using netstat -s
# 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.
.....
Show statistics for TCP (or) UDP ports using netstat -st (or) -su
# netstat -st

# netstat -su
4. Display PID and program names in netstat output using netstat -p

netstat -p option can be combined with any other netstat option. This will add the “PID/Program Name” to the netstat output. This is very useful while debugging to identify which program is running on a particular port.

# 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
5. Don’t resolve host, port and user name in netstat output

When you don’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.

This also speeds up the output, as netstat is not performing any look-up.

# netstat -an
If you don’t want only any one of those three items ( ports, or hosts, or users ) to be resolved, use following commands.

# netsat -a --numeric-ports

# netsat -a --numeric-hosts

# netsat -a --numeric-users
6. Print netstat information continuously

netstat will print information continuously every few seconds.

# 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
7. Find the non supportive Address families in your system

netstat --verbose
At the end, you will have something like this.

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.
8. Display the kernel routing information using netstat -r

# 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
Note: Use netstat -rn to display routes in numeric format without resolving for host-names.

9. Find out on which port a program is running

# 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 -
Find out which process is using a particular port:

# netstat -an | grep ':80'
10. Show the list of network interfaces

# 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
Display extended information on the interfaces (similar to ifconfig) using netstat -ie:

# 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

Thursday, April 8, 2010

Using bridged networking with Virt-manager

To do this, we install the package bridge-utils...

yum install bridge-utils

... and configure a bridge. Create the file /etc/sysconfig/network-scripts/ifcfg-br0 (please use the BOOTPROTO, BROADCAST, IPADDR, NETMASK and NETWORK values from the /etc/sysconfig/network-scripts/ifcfg-eth0 file):

vi /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
BROADCAST=192.168.0.255
IPADDR=192.168.0.100
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes

Modify /etc/sysconfig/network-scripts/ifcfg-eth0 as follows (comment out BOOTPROTO, BROADCAST, IPADDR, NETMASK, and NETWORK and add BRIDGE=br0):

vi /etc/sysconfig/network-scripts/ifcfg-eth0

# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
#BOOTPROTO=static
#BROADCAST=192.168.0.255
HWADDR=00:10:A7:05:AF:EB
#IPADDR=192.168.0.100
#NETMASK=255.255.255.0
#NETWORK=192.168.0.0
ONBOOT=yes
BRIDGE=br0

Restart the network...

/etc/init.d/network restart

... and run

ifconfig

It should now show the network bridge (br0):

[root@rajat1 ~]# ifconfig
br0 Link encap:Ethernet HWaddr 00:10:A7:05:AF:EB
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::210:a7ff:fe05:afeb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:17 errors:0 dropped:0 overruns:0 frame:0
TX packets:53 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1160 (1.1 KiB) TX bytes:14875 (14.5 KiB)

eth0 Link encap:Ethernet HWaddr 00:10:A7:05:AF:EB
inet6 addr: fe80::210:a7ff:fe05:afeb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13662 errors:7 dropped:160 overruns:4 frame:0
TX packets:11646 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15144608 (14.4 MiB) TX bytes:1379942 (1.3 MiB)
Interrupt:74 Base address:0xcc00

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:38 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4308 (4.2 KiB) TX bytes:4308 (4.2 KiB)

virbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:35 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:9987 (9.7 KiB)

[root@rajat1 ~]# brctl show

bridge name bridge id STP enabled interfaces
pan0 8000.000000000000 no
virbr0 8000.000000000000 yes
br0 8000.0019b97ec863 yes eth0

Tuesday, March 23, 2010

Free OS and Software

Debian, Kubuntu, Ubuntu, Xandros, SUSE, Red Hat, Fedora, CentOS, Linspire, Mandriva, Slackware, Open BSD, Gnome, KDE, MySQL, PostgreSQL, PostGIS, Slony, Zarafa, eGroupware, Kolab Groupware, Scalix, SugarCRM, vTiger, CITADEL, Mozilla-Firefox, Mozilla-Suite, OpenOffice, LibreOffice, Thunderbird, Wine, Apache, hadoop, Nginx Drupla, Joomla, Jboss, Wordpress, WebGUI,  Tomcat, TiKi WiKi, Wikimedia, Asterisk, OpenSER, FreePBX, OpenPBX, CallWeaver, SpamAssassin, ClamAV, OpenLDAP, OTRS, RT, Samba, Cyrus, Dovecot, Exim, Postfix, sendmail, Amanda, Bacula, DRBD, Heartbeat, Keepalived, Nagios, Zabbix, Zenoss, Open Security Filter, Ferm, FAI, Moodle, Squid, XEN, KVM, OpenVZ, Xenserver, Eucalyptus, OpenQRM, Opennebula, VirtualBox, Mondorescue, Spacewalk, Convirture, OpenVPN, VLC, PiTiVi, XBMC, dimdim, Puppet, osclass, Django, Affelio, AROUNDMe, BuddyPress, Elgg, iSocial, Mahara, Xoops, Magento, Jcow, Jinzora, OpenStack.

All Above product support available free of cost :D

Monday, March 8, 2010

Fedora Talking to you

# [root@rajat Rajat]# yum install espeak
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package espeak.x86_64 0:1.40.02-3.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
espeak x86_64 1.40.02-3.fc12 fedora 605 k

Transaction Summary
================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)

Total download size: 605 k
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 605 k
espeak-1.40.02-3.fc12.x86_64.rpm | 605 kB 00:14
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : espeak-1.40.02-3.fc12.x86_64 1/1

Installed:
espeak.x86_64 0:1.40.02-3.fc12

Complete!

Example 1: Speak the words specified in command line

This is the default usage.

# espeak --stdout 'words to speak' | aplay

Note: The above may also display the following message: “Playing WAVE ’stdin’ : Signed 16 bit Little Endian, Rate 22050 Hz, Mono”
Example 2: Speak the words specified in stdin

This will take the words interactively from the standard input and convert it to speech.

# espeak --stdout | aplay

Example 3: Speak your document

This will convert the text from the mydocument.txt to speech.

# espeak --stdout -t mydocument.txt | aplay

Example 4: Generate voice file from text document

Convert your text file to an audio file as shown below.

# espeak -t mydocument.txt -w myaudio.wav

Customizing espeak

If you find the default speech synthesizing is not good, you can try to customize it as explained below.
Example 5: List all available voice languages

# espeak --voices
Pty Language Age/Gender VoiceName File Other Langs
5 af M afrikaans af
5 bs M bosnian bs
5 ca M catalan ca
5 cs M czech cs
5 cy M welsh-test cy
5 de M german de
5 el M greek el
5 en M default default
5 en-sc M en-scottish en/en-sc (en 4)
.......

Example 6: Choose a different voice language

The following will use “en-uk” – British english to translate the text to speech.

# espeak -v en-uk --stdout 'reading tips & tricks in TGS' | aplay

Example 7: Increase or Decrease the number of spoken words per minute.

The default is 160 words per minute. You can reduce it using option -s as shown below.

# espeak -s 140 -f mydocument.txt | aplay

Example 8: List the available espeak voices in specific language

The following example will display all possible english language variation that you can use for your text to speech conversion.

# espeak --voice=en
Pty Language Age/Gender VoiceName File Other Langs
2 en-uk M english en/en (en 2)
3 en-uk M english-mb-en1 mb/mb-en1 (en 2)
2 en-us M english-us en/en-us (en-r 5)(en 3)
5 en-sc M en-scottish en/en-sc (en 4)
5 en M default default
.....