Friday, December 27, 2013

Creating custom SSH welcome messages with MOTD and ISSUE.NET File

One of the easiest way to protect and secure SSH logins by displaying warming message to UN-authorized users or display welcome or informational messages to authorized users.

Being a system administrator whenever configure Linux servers I always use to configure a security banners for ssh logins. The banner contains some security warning information or general information. See my example banner message which I used for my all servers.
ALERT! You are entering into a secured area! Your IP, Login Time, Username has been noted and has been sent to the server administrator!
This service is restricted to authorized users only. All activities on this system are logged.
Unauthorized access will be fully investigated and reported to the appropriate law enforcement agencies.
There are two way to display messages one is using issue.net file and second one is using MOTD file.
  1. issue.net : Display a banner message before the password login prompt.
  2. motd : Display a banner message after the user has logged in.
So, I strongly recommended all system administrator to display a banner messages before allowing users to log in to systems. Just follow below simple steps to enable SSH logging messages.

Display SSH Warning Message to Users Before Login

To display Welcome or Warning message for SSH users before login. We use issue.net file to display a banner massages. Open the following file with VI editor.
[root@thelinuxwiki ~]# vi /etc/issue.net
Add the following banner sample message and save the file. You can add any custom banner message to this file.
###################################################
# you are trying to login to gateway and webserver of thelinuxwiki # 
# All connections are monitored and recorded                                  #
# Disconnect IMMEDIATELY if you are not an authorized user!      #
###################################################
Open the master ssh configuration file and enable banners.
[root@thelinuxwiki ~]#vi /etc/ssh/sshd_config
Search for the word “Banner” and uncomment out the line and save the file.
#Banner none
It should be like this.
Banner /etc/issue.net (you can use any path you want)
Next, restart the SSH daemon to reflect new changes.
[root@thelinuxwiki ~]# /etc/init.d/sshd restart
[root@thelinuxwiki ~]# Stopping sshd:                                           [  OK  ]
[root@thelinuxwiki ~]# Starting sshd:                                           [  OK  ]
Now try to connect to server you will see banner message similar to below.

                                                      SSH Banner Messages Before Login




Display SSH Warning Message to Users After Login


To display banner messages after login, we use motd file, which is used to display banner massages after login. Now open it with VI editor.
vi /etc/motd
Place the following banner sample message and save the file.
####################################################
## you are  logged in to gateway and webserver of thelinuxwiki      # 
## All connections are monitored and recorded                                 #
## Disconnect IMMEDIATELY if you are not an authorized user!     #
####################################################


Now again try to login into server you will get both the banner messages. See the screenshot attached below.



How To Avoid SSH Time Out While Working On The Command Line

If you’ve worked on the command line for a long time, you would have encountered the session time out problem on more than one occasion. Before you start abusing it though, understand that this brief period of inactivity is good from security point of view. But, it can still be problematic when you are working with operations that take a long time to run. So, in this article, we will discuss how you can avoid the SSH time out problem when working on the command line.


What usually happens to cause the problem is that the connection with the server is reset. So, when the user has been idle for some time, the error produced is ‘Connection reset by peer’. In order to avoid this, we need to use the Keep Alive option on the client or on the server. This gives us two ways to avoid being times out. 

1. Keep Alive Server Side: Server side keep alive is the less secure of the two options. This is because you need to perform an action as root and also because its effect comes on all the client connections and not just your own. Still, if you want to use this method, then here’s how.

- Log in as root

- Edit file at /etc/ssh/sshd_config

- Add this to the file: ClientAliveInterval 60

- Save file

- Restart sshd on the server

2. Keep Alive Client Side: While this method is similar to the Server Side Keep Alive method, it is the more secure of the two. When using Linux, the Client Side method has minor differences to the Server Side method. To use this method,

On Linux:

- Log in as root

- Edit file at /etc/ssh/ssh_config

- Add this to the file: ServerAliveInterval 60

- Save file

On Windows: You have to use PuTTY,

- Open PuTTY

- Click on the Connection Category in the left menu

- Check the box for Enable TCP keepalives (SO_KEEPALIVE option)


Thursday, December 26, 2013

Ping multiple hotsts at once on Linux


fping – Ping multiple hotsts at once on Linux


fping is a ping like program which uses the Internet Control Message Protocol (ICMP) echo request to determine if a host is up. fping is different from ping in that you can specify any number of hosts on the command line, or specify a file containing the lists of hosts to ping.
Instead of trying one host until it timeouts or replies, fping will send out a ping packet and move on to the next host in a round-robin fashion. If a host replies, it is noted and removed from the list of hosts to check. If a host does not respond within a certain time limit and/or retry limit it will be considered unreachable.
Unlike ping, fping is meant to be used in scripts and its output is easy to parse.
Scanning a network should not be done without prior permission. Many networks and systems will view a network scan as an aggressive action regardless of how trivial and petty it might be. Please keep this in mind before utilizing this tool.
For CentOs 5.x/6.x this utility is provided from the EPEL repository , just install it with :
yum install fping

Let’s start with a very simple scan, our own system:
fping  192.168.1.1
Nice …. it return that our router is alive
192.168.1.1 is alive
fping -a < ip_list.txt
Let’s try scanning a larger chunk of our network using a file for input instead of typing in IP addresses at the command line:
192.168.1.1 is alive
192.168.1.3 is alive
fping -f ip_list.txt
e file “ip_table.txt” just contains the IP addresses from 192.168.1.0 to 192.168.1.10 with each IP address on its own line. In my above command line example I piped in the file. If you are logged into your system as root you can use this command instead:
fping -a -d < ip_list.txt
The -d flag will attempt to resolve host names for each IP address while the -a flag will only show alive hosts. Again I piped a list of IP addresses into fping.
fping -g 192.168.1.0/24
If you wanted to specify a range of IP addresses at the command line, say all 255 possible hosts of 192.168.1.*, you could use the -g flag


There are quite a few more options capable of being used with fping. I would recommend reading the man page for fping to learn more about this tool.
If you want to quickly scan a network for reachable hosts then fping will easily provide you with that capability. It is a simple tool that can be run while you work on other things should you need to scan a large network (but not as long as ping!). It is also worth learning because fping can be incorporated into your own custom scripts since it’s output is easy to parse. A drawback to using fping is that the perimeter of networks will often block ICMP traffic into the internal network. This is overcome by using nmap which we’ll look at another day. Happy scanning!

Saturday, November 16, 2013

How To Install Nagios and NRPE On CentOS 6

 Install Nagios and NRPE  On CentOS 6 and  Monitoring Windows with Nagios

In this tutorial we will learn How to install and configure nagios server  and install  nrpe on client pc's. We will also do some configuration changes in nagios server so that we could monitor the servers.
In this scenario we will add a server to monitor.
Operating System : CentOS 6.3
Nagios Server : hostname: nagios-server , ip-address: 192.168.18.1
Nagios Client : hostname: linuxw-server-1 , ip-address: 192.168.18.128
Nagios Client : hostname :  windows-server-1, ip-address: 192.168.18.129
First the install the prerequisites for Nagios Server(192.168.18.1)
[root@thelinuxwiki  ~]# yum install -y gd gd-devel httpd php gcc glibc glibc-common
By default nagios is not found in CentOS official repository, so add the EPEL repository to install nagios.
[root@thelinuxwiki  ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@thelinuxwiki  ~]# rpm -ivh epel-release-6-8.noarch.rpm
Now install nagios in 192.168.18.1 Server
[root@thelinuxwiki ~]# yum install -y nagios*

Configure Nagios

Add the admin mail address in the nagios contact file to receive alerts from nagios server.
[root@thelinuxwiki]# vi /etc/nagios/objects/contacts.cfg

### Line 35 - Edit the mail id ###
email                           admin@thelinuxwiki.in  ; 
[root@thelinuxwiki]# egrep -v '^#|^$' /etc/nagios/objects/contacts.cfg 
define contact{
        contact_name                    nagiosadmin  ; Short name of user
 use    generic-contact  ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin  ; Full name of user
        email                           UREMAILID@gmail.com  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
define contact{
        contact_name                    naveencontact             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        email                           naveen@thelinuxwiki.in   ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin,naveencontact
        }
Edit the following lines in nagios config file
[root@thelinuxwiki]#vi /etc/httpd/conf.d/nagios.conf

## Comment Lines 15 & 16 ##
#   Order allow,deny
#   Allow from all

## Uncomment and Change lines 17,18 & 19 as shown below ##
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.1.0/24
Set nagiosadmin password
[root@server ~]# htpasswd /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Updating password for user nagiosadmin
Start nagios and httpd services and let them to start automatically on every boot.
[root@thelinuxwiki]#/etc/init.d/nagios start
Starting nagios: done.
[root@thelinuxwiki]# /etc/init.d/httpd start
Starting httpd:                                            [  OK  ]
[root@thelinuxwiki]#chkconfig nagios on
[root@thelinuxwiki]#chkconfig httpd on
Open nagios administrator console and enter the nagiosadmin password as created before

Adding clients to Nagios server

Now we should add our hosts that will be monitored by Nagios. For example, we will use linux-server-1 (198.168.18.128) and windows-server-1 (198.168.18.129).
From public ports, we can monitor ping, any open ports such as webserver, e-mail server, etc.
For internal services that are listening on localhost, such as MySQL, memcached, system services, we will need to use NRPE.

 Install NRPE on Clients-192.168.18.128


[root@thelinuxwiki  ~] # rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@thelinuxwiki  ~] # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
[root@thelinuxwiki  ~] # yum -y install  nagios-plugins-all nrpe openssl
[root@thelinuxwiki  ~] # chkconfig nrpe on

This next step is where you get to specify any manual commands that Monitoring server can send via NRPE to these client hosts.
Make sure to change allowed_hosts to your own values. 

Edit /etc/nagios/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nrpe/nrpe.pid
server_port=5666
nrpe_user=nrpe
nrpe_group=nrpe
allowed_hosts=192.168.18.1 # This is the Nagios Server IP address
dont_blame_nrpe=1
debug=0
command_timeout=60
connection_timeout=300
include_dir=/etc/nrpe.d/
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
Note:
In above block you can see command are already defined.
for eg. command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
just keep a note of it.The nrpe will use only these commands or plugins in nagios client which are defined in nrpe.cfg file.
If you want to add any other command or plugin you have to edit the nrpe.cfg file in same manner.
for eg.
command[check_pluginName]=/usr/lib/nagios/plugins/check_pluginName -w <value>  -c <value>
In check_disk above, the partition being checked is /dev/sda1 - make sure your droplet has the same partition by running df -h /

You can also modify when to trigger warnings or critical alerts - above configuration sets Warning at 20% free disk space remaining, and Critical alert at 10% free space remaining.

If you want change any arguments you can change as per your requirement, but follow 
the same syntax while editing or creating new rule.
Now you can start NRPE on all of your client hosts:
[root@thelinuxwiki]# service nrpe start

 Install NRPE on Clients-192.168.18.129(Windows-Server-1)

Windows configuration
Install NSClient++ on the Windows host.
Download and install.
Also if you want to check for a newer version. Here’s the full list: http://nsclient.org/nscp/downloads
Here’s a screenshot of one part of the installation.

Those are the features that I chose. Enable at least common check plugins and nsclient server.



Look for these lines and add them if they’re missing:
allowed hosts = 192.168.18.1
password =
port = 12489

Restart the NSClient++ service:
Start > Administrative tools > Services 


Configuration in windows server has been completed 

Now goto Nagios Server and Add the Two Clients(Linux-192.168.18.128 and Windows-192. 168.18.129) in nagios configuration file 

Add Server Configurations on Monitoring Server


Back on our Monitoring server, we will have to create config files for each of our client servers: 
[root@thelinuxwiki]# echo "cfg_dir=/etc/nagios/servers" >> /etc/nagios/nagios.cfg
[root@thelinuxwiki]# cd /etc/nagios/servers
[root@thelinuxwiki]# touch linux-server-1.cfg
[root@thelinuxwiki]# touch windows-server-1.cfg
Edit each client's configuration file and define which services you would like monitored.
First We will configure linux-server-1(192.168.18.128)
[root@linux-servers]# vi /etc/nagios/servers/linux-server-1.cfg
[root@thelinuxwiki]# egrep -v '^#|^$' /etc/nagios/servers/linux-server-1.cfg 
define host {
        use                     linux-server
        host_name               linux-server-1
        alias                   server1
        address                 192.168.18.128
 max_check_attempts              5
 check_period                    24x7 
 notification_interval           30
 notification_period             24x7
        }
define service {
        use                             generic-service
        host_name                       server1
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }
define service {
        use                             generic-service
        host_name                       server1
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
define service {
        use                             generic-service
        host_name                       server1
        service_description             CPU Load
        check_command                   check_nrpe!check_load
        }
define service {
        use                             generic-service
        host_name                       server1
        service_description             login users
        check_command                   check_nrpe!check_users
        }
define service {
        use                             generic-service
        host_name                       server1
        service_description             hard disk space
        check_command                   check_nrpe!check_sda3
        }
[root@thelinuxwiki]# 
[root@thelinuxwiki]# vi /etc/nagios/servers/windows-server-1.cfg
[root@thelinuxwiki]# egrep -v '^#|^$' /etc/nagios/servers/windows-server-1.cfg 
define host{
 use  windows-server ; Inherit default values from a template
 host_name windows-server-1 ; The name we're giving to this host
 alias  My Windows Server ; A longer name associated with the host
 address  192.168.18.129 ; IP address of the host
 }
define hostgroup{
 hostgroup_name windows-servers ; The name of the hostgroup
 alias  Windows Servers ; Long name of the group
 }
define service{
 use   generic-service
 host_name  windows-server-1

 service_description NSClient++ Version
 check_command  check_nt!CLIENTVERSION
 }
define service{
 use   generic-service
 host_name  windows-server-1

 service_description Uptime
 check_command  check_nt!UPTIME
 }
define service{
 use   generic-service
 host_name  windows-server-1

 service_description CPU Load
 check_command  check_nt!CPULOAD!-l 5,80,90
 }
define service{
 use   generic-service
 host_name  windows-server-1

 service_description Memory Usage
 check_command  check_nt!MEMUSE!-w 80 -c 90
 }
define service{
 use   generic-service
 host_name  windows-server-1

 service_description C:\ Drive Space
 check_command  check_nt!USEDDISKSPACE!-l c -w 85 -c 90
 }
define service{
 use   generic-service
 host_name  windows-server-1

 service_description W3SVC
 check_command  check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
 }
define service{
 use   generic-service
 host_name  windows-server-1

 service_description Explorer
 check_command  check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
 }
[root@thelinuxwiki]# 
Finally, after you are done adding all the client configurations, you should set folder permissions correctly and restart Nagios on your Monitoring Server:
chown -R nagios. /etc/nagios
service nagios restart
Let’s see what our nagios web page tells us:
http://192.168.18.1/nagios
Go to the Services on left hand menu and you should see something similiar to this:
Note: You have to add following into commands.cfg of your nagios server
[root@thelinuxwiki.in]# vi /etc/nagios/objects/commands.cfg
# 'check_nt' command definition # This is for Windows Clients
define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
        }

# 'check_nrpe' command definition # This is for Linux Clients
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$



Monday, October 7, 2013

How read mail from /var/spool/postfix/deferred? or Diferred Emails


How read mail from /var/spool/postfix/deferred? or Diferred Emails



You need to get the message id first with postqueue -p
Then once you have the message id you read it with postcat -q messageid


Wednesday, September 18, 2013

How to install Huawei E220 USB Modem on Centos 5.4


You want to install Huawei E220 USB Modem on Centos 5.4 and use the modem to access internet? If you use Slackware 12.2 or Fedora 12 , clickhere for Slackware 12.2 or here for Fedora 12 to follow the tutorials

It is very easy to do this. CentOS 5.4 that using kernel 2.6.18-164 is smart enough to autodetect the device so you do not need huaweiAktBbo-i386.out tool to switch the modem to the correct mode for serial port. In my case, it is detected and attached to ttyUSB0 and ttyUSB1. When you connect the modem to your laptop or PC via USB port, you would see log messages in ‘dmesg’ command something like below:
usb 2-2: new full speed USB device using uhci_hcd and address 2
usb 2-2: configuration #1 chosen from 1 choice
Initializing USB Mass Storage driver...
scsi3 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 2
usb-storage: waiting for device to settle before scanning
usbcore: registered new driver usb-storage
USB Mass Storage support registered.
usb 2-2: USB disconnect, address 2
usb 2-2: new full speed USB device using uhci_hcd and address 3
usb 2-2: configuration #1 chosen from 1 choice
usb-storage: probe of 2-2:1.0 failed with error -5
usb-storage: probe of 2-2:1.1 failed with error -5
scsi6 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 3
usb-storage: waiting for device to settle before scanning
usbcore: registered new driver usbserial
drivers/usb/serial/usb-serial.c: USB Serial support registered for generic
usbcore: registered new driver usbserial_generic
drivers/usb/serial/usb-serial.c: USB Serial Driver core
drivers/usb/serial/usb-serial.c: USB Serial support registered for GSM modem (1-port)
option 2-2:1.0: GSM modem (1-port) converter detected
usb 2-2: GSM modem (1-port) converter now attached to ttyUSB0
option 2-2:1.1: GSM modem (1-port) converter detected
usb 2-2: GSM modem (1-port) converter now attached to ttyUSB1
usbcore: registered new driver option
drivers/usb/serial/option.c: USB Driver for GSM modems: v0.7.1
  Vendor: HUAWEI    Model: Mass Storage      Rev: 2.31
  Type:   CD-ROM                             ANSI SCSI revision: 02
scsi 6:0:0:0: Attached scsi generic sg1 type 5
usb-storage: device scan complete
As you can see above, Centos 5.4 already attached the modem to ttyUSB0 and ttyUSB1.
[ad#Chitika468x180]
Now build a configuration file for wvdial and stored it in /etc/wvdial.conf file by running wvdialconf command as below:
[root@fuad ~]# wvdialconf /etc/wvdial.conf
Scanning your serial ports for a modem.

Port Scan<*1>: S0   S1   S2   S3
WvModem<*1>: Cannot get information for serial port.
ttyUSB0<*1>: ATQ0 V1 E1 -- OK
ttyUSB0<*1>: ATQ0 V1 E1 Z -- OK
ttyUSB0<*1>: ATQ0 V1 E1 S0=0 -- OK
ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
ttyUSB0<*1>: Modem Identifier: ATI -- Manufacturer: huawei
ttyUSB0<*1>: Speed 4800: AT -- OK
ttyUSB0<*1>: Speed 9600: AT -- OK
ttyUSB0<*1>: Speed 19200: AT -- OK
ttyUSB0<*1>: Speed 38400: AT -- OK
ttyUSB0<*1>: Speed 57600: AT -- OK
ttyUSB0<*1>: Speed 115200: AT -- OK
ttyUSB0<*1>: Speed 230400: AT -- OK
ttyUSB0<*1>: Speed 460800: AT -- OK
ttyUSB0<*1>: Max speed is 460800; that should be safe.
ttyUSB0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
WvModem<*1>: Cannot get information for serial port.
ttyUSB1<*1>: ATQ0 V1 E1 -- OK
ttyUSB1<*1>: ATQ0 V1 E1 Z -- OK
ttyUSB1<*1>: ATQ0 V1 E1 S0=0 -- OK
ttyUSB1<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
ttyUSB1<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
ttyUSB1<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
ttyUSB1<*1>: Modem Identifier: ATI -- Manufacturer: huawei
ttyUSB1<*1>: Speed 4800: AT -- OK
ttyUSB1<*1>: Speed 9600: AT -- OK
ttyUSB1<*1>: Speed 19200: AT -- OK
ttyUSB1<*1>: Speed 38400: AT -- OK
ttyUSB1<*1>: Speed 57600: AT -- OK
ttyUSB1<*1>: Speed 115200: AT -- OK
ttyUSB1<*1>: Speed 230400: AT -- OK
ttyUSB1<*1>: Speed 460800: AT -- OK
ttyUSB1<*1>: Max speed is 460800; that should be safe.
ttyUSB1<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK

Found a modem on /dev/ttyUSB0.
Modem configuration written to /etc/wvdial.conf.
ttyUSB0: Speed 460800; init \"ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0\"
ttyUSB1: Speed 460800; init \"ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0\"
The command above will generate wvdial.conf after scanning the modem. You can check that file and should be like this:
[root@fuad ~]# cat /etc/wvdial.conf
[Dialer Defaults]
Modem = /dev/ttyUSB0
Baud = 460800
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = Analog Modem
; Phone = 
; Username = 
; Password =
You have to edit the Phone, Username and Password of the configuration above to meet your account.
For example, it should be like below:
[Dialer Defaults]
Modem = /dev/ttyUSB0
Baud = 460800
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ISDN = 0
Modem Type = Analog Modem
Phone = *99#
Username = fuadnahdi
Password = secret-eh
The next step is running ‘wvdial’ command as root. By default it will read /etc/wvdial.conf as we configured before.
[root@fuad ~]# wvdial
--> WvDial: Internet dialer version 1.54.0
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier.
ATDT*99#
CONNECT
--> Carrier detected.  Waiting for prompt.
--> Don\'t know what to do!  Starting pppd and hoping for the best.
--> Starting pppd at Mon Nov  1 19:51:01 2009
--> pid of pppd: 4206
--> Using interface ppp0
--> local  IP address 114.59.189.52
--> remote IP address 10.64.64.64
--> primary   DNS address 202.155.0.10
--> secondary DNS address 202.155.0.15
If successful you will get an IP address and DNS server assigned to you. For the DNS server, you need to manually write it into /etc/resolv.conf because the wvdial script will not automatically write it for you.

Installing and Configuring 3G DataCard on CentOS



Installation steps mentioned in the Documentation are tested on CentOS 6

Follow the steps mentioned in the following order.

1) Install CentOS 6.3.

2) Following are the prerequisite package for connecting 3G USB Dongle
   wvdial
   usb_modeswitch-data
   usb_modeswitch
You can download the above package from following site on your Pen Drive or other media.
   http://mirror.centos.org/centos/6/os/x86_64/Packages/wvdial
   http://pkgs.repoforge.org/usb_modeswitch-data
   http://pkgs.repoforge.org/usb_modeswitch
3) Connect the USB 3G Dongle on the system and check the device is detected using lsusb command or in /var/log/messages.
   lsusb
   Bus 001 Device 003: ID 12d1:140c Huawei Technologies Co., Ltd.
OR
   tail -f /var/log/messages

   Aug 1 11:09:04 localhost kernel: usb 1-7: Product: HUAWEI Mobile
   Aug 1 11:09:04 localhost kernel: usb 1-7: Manufacturer: HUAWEI Technology
4) Check the device type by which modem is connected using dmesg.
   dmesg | grep tty

   usb 1-8: GSM modem (1-port) converter now attached to ttyUSB0
   usb 1-8: GSM modem (1-port) converter now attached to ttyUSB1
   usb 1-8: GSM modem (1-port) converter now attached to ttyUSB2
   usb 1-8: GSM modem (1-port) converter now attached to ttyUSB3
5) Once USB is connected and detected, now is the time to configure wvdial.
   vi /etc/wvdial.conf 
   [Dialer Defaults]
   Init1 = ATZ
   Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
   Init3 = AT+CGDCONT=1,"IP","airtelgprs.com"
   stupid mode = 1
   Modem Type = USB Modem
   Baud = 460800
   New PPPD = yes
   Modem = /dev/ttyUSB0
   ISDN = 0
   Phone = *99#
   Carrier Check = no
   Password = airtel
   Username = airtel
   FlowControl=Hardware(CRTSCTS)
6) Once we have prepared the config file now is the time to connect wvdial.
   wvdial
   --> WvDial: Internet dialer version 1.60
   --> Cannot get information for serial port.
   --> Initializing modem.
   --> Sending: ATZ
   OK
   --> Sending: ATQ0 V1 E1 S0=0 &C1 &D2
   ATQ0 V1 E1 S0=0 &C1 &D2
   OK
   --> Sending: AT+CGDCONT=1,"IP","airtelgprs.com"
   AT+CGDCONT=1,"IP","airtelgprs.com"
   OK
   --> Modem initialized.
   --> Sending: ATDT*99#
   --> Waiting for carrier.
   ATDT*99#
   CONNECT
   --> Carrier detected.  Starting PPP immediately.
   --> Starting pppd at Mon Aug  5 18:55:58 2013
   --> Pid of pppd: 3070
   --> Using interface ppp0
   --> pppd: ?
   --> pppd: ?
   --> pppd: ?
   --> pppd: ?
   --> pppd: ?
   --> local  IP address 223.228.201.19
   --> pppd: ?
   --> remote IP address 10.64.64.64
   --> pppd: ?
   --> primary   DNS address 125.22.47.102
   --> pppd: ?
   --> secondary DNS address 125.22.47.103
   --> pppd: ?
6) Check the logs (/var/log/messages) and try to make entry of Primary and Secondary DNS server in /etc/resolv.conf, if it is not updated.
   Aug 1 14:35:40 localhost pppd[3794]: pppd 2.4.5 started by root, uid 0
   Aug 1 14:35:40 localhost pppd[3794]: Using interface ppp0
   Aug 1 14:35:40 localhost pppd[3794]: Connect: ppp0 <--> /dev/ttyUSB0
   Aug 1 14:35:40 localhost pppd[3794]: CHAP authentication succeeded
   Aug 1 14:35:40 localhost pppd[3794]: CHAP authentication succeeded
   Aug 1 14:35:43 localhost pppd[3794]: Could not determine remote IP address: defaulting to 10.64.64.64
   Aug 1 14:35:43 localhost pppd[3794]: local IP address 106.200.21.246
   Aug 1 14:35:43 localhost pppd[3794]: remote IP address 10.64.64.64
   Aug 1 14:35:43 localhost pppd[3794]: primary DNS address 125.22.47.102
   Aug 1 14:35:43 localhost pppd[3794]: secondary DNS address 125.22.47.103
   Aug 1 14:35:45 localhost ntpd[2903]: Listening on interface #5 ppp0, 106.200.21.246#123 Enabled
Resolv file will look like
   vi /etc/resolv.conf 
   nameserver 125.22.47.102
   nameserver 125.22.47.103
7) Congratulation now you are connected, grap a glass of bear and enjoy surfing the Net. Debugging steps *) Check device is in Storage or Modem Mode.
**) Use usb-devices or lsusb command to check.
   usb-devices
   T: Bus=01 Lev=01 Prnt=01 Port=07 Cnt=01 Dev#= 9 Spd=480 MxCh= 0
   D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
   P: Vendor=12d1 ProdID=1446 Rev=00.00
   S: Manufacturer=HUAWEI Technology
   S: Product=HUAWEI Mobile
   C: #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=500mA
   I: If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
   I: If#= 1 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
OR
   lsusb
   Bus 001 Device 003: ID 12d1:1446 Huawei Technologies Co., Ltd. E1552/E1800/E173 (HSPA modem)
"1446" is the product id for the file mode of this dongle. (It is in Storage mode).
   lsusb
   Bus 001 Device 003: ID 12d1:140c Huawei Technologies Co., Ltd.
"140c" is the product id for the file mode of this dongle. (It is in USB mode). **) Load the usbserial kernel module using following command.
   modprobe usbserial vendor=0x12d1 product=0x140c
**) usb_modeswitch package is used to switch the USB dongle from CDROM file system to Modem mode (→ flip flop). Create the following file.
   cat /etc/usb_modeswitch.conf
   DefaultVendor= 0x12d1 
   DefaultProduct=0x1446 

   TargetVendor= 0x12d1 
   TargetProductList="1001,1406,140b,140c,141b,14ac" 

   CheckSuccess=20 MessageContent="55534243123456780000000000000011060000000000000000000000000000" 
**) Now run the following command to switch from storage to modem mode.
   usb_modeswitch -c /etc/usb_modeswitch.conf
   Check the /var/log/message it will show something like
   Aug 1 14:35:08 localhost kernel: usb 1-8: configuration #1 chosen from 1 choice
   Aug 1 14:35:08 localhost kernel: option 1-8:1.0: GSM modem (1-port) converter detected
   Aug 1 14:35:08 localhost kernel: usb 1-8: GSM modem (1-port) converter now attached to ttyUSB0
   Aug 1 14:35:08 localhost kernel: option 1-8:1.1: GSM modem (1-port) converter detected
   Aug 1 14:35:08 localhost kernel: usb 1-8: GSM modem (1-port) converter now attached to ttyUSB1
   Aug 1 14:35:08 localhost kernel: option 1-8:1.2: GSM modem (1-port) converter detected
   Aug 1 14:35:08 localhost kernel: usb 1-8: GSM modem (1-port) converter now attached to ttyUSB2
   Aug 1 14:35:08 localhost kernel: option 1-8:1.3: GSM modem (1-port) converter detected
   Aug 1 14:35:08 localhost kernel: usb 1-8: GSM modem (1-port) converter now attached to ttyUSB3
   Aug 1 14:35:08 localhost kernel: scsi23 : SCSI emulation for USB Mass Storage devices
   Aug 1 14:35:08 localhost kernel: scsi24 : SCSI emulation for USB Mass Storage devices
   Aug 1 14:35:09 localhost modem-manager: (ttyUSB0) opening serial device...
**) Now try the steps mentioned from Steps 5 onwards. *) Also try to remove any other mounted usb storage media and try the steps mentioned above once again.

NOTE: Converting Storage Mode to Modem Mode)
http://bytefish.de/blog/huawei_e352s5/

   Reference for further reading
   *) https://wiki.archlinux.org/index.php/3G_and_GPRS_modems_with_pppd
   *) https://wiki.archlinux.org/index.php/USB_3G_Modem

Ref:1