Thursday, February 27, 2014

MySQL, How to reset lost root password

Did you forget the root password of MySQL ? Here is how get it back.

The following steps tells you how to reset the root password in MySQL (this is specific to Linux environment, I understand the same process would also work in Windows)


1. Stop MySQL service:
# service mysqld stop
Stopping mysqld:                                           [  OK  ]


2. Start Mysql server with "--skip-grant-tables" option (user privileges table). You may optionally provide "--skip-networking" which would prohibit anyone from connecting the server from remote place;


Please note that, one need to start the server using "mysqld_safe" command. You need to send the process in the background by either pressing ctrl+z and send it to the background using "bg" or '&' at the end of the command;

# mysqld_safe --skip-grant-tables --skip-networking
140227 18:39:40 mysqld_safe Logging to '/var/log/mysqld.log'.
140227 18:39:40 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
^Z
[1]+  Stopped                 mysqld_safe --skip-grant-tables --skip-networking

3. Login to Mysql without password (this will not prompt you for password);

[root@Fedora-14 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.60 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

4. Update the password for "root" user with a new password;

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD("root") where user="root";
Query OK, 0 rows affected (0.01 sec)
Rows matched: 3  Changed: 0  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

5. Stop the MySQL server;

[root@Fedora-14 ~]# /etc/init.d/mysqld stop
Stopping mysqld:                                           [  OK  ]

6. Start back the MySQL server;

# service mysqld start
Starting mysqld:                                           [  OK  ]

7. Login to the server with root user and the new password;

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.60 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Wednesday, February 19, 2014

Accessing a Linux box in GUI mode

Here is how to setup a Linux system that would allow you to access it from a remote system using VNC client

A.       Login to the Linux box & switch to root user. Now, install and configure
           the packages stated below;

1.          yum groupinstall "Desktop"

2.         yum install xorg-x11-fonts-100dpi.noarch xorg-x11-fonts-ISO8859-1-100dpi.noarch
            xorg-x11-fonts-misc.noarch xorg-x11-fonts-Type1.noarch tigervnc-server

3.         Modify the /etc/inittab to set runlevel 5 (thus, the system would run
            in full GUI mode)

4.         Now, configure vnc password with the command "vncpasswd"

5.         Start the vncserver by running the command "vncserver"


B.       On the client system install VNC-Viewer-XXX from the link
           http://www.realvnc.com/download/viewer/

C.       Start the VNC-Viewer client and connect to the Linux box ( :5901 
           as the VNC Server value)

Note:    Just in case you are not able to access the System, check the iptables rules 
             (firewall) and allow the port 5901 to be accessed from outside.



Thursday, September 20, 2012

Configuring BIND as Domain Name Server (DNS) on CentOS – 6x system

What is DNS?

It is a well known fact that Human brains are more capable of remebering names compared to numbers. Simply put, a DNS or Domain Name System is an internet service that works as a translator. A translator that resolves Humen Readable names called Domains into IP address. As we all know every computer or device connected to internet is identified by a series of numbers known as IP (Internet Protocol) address. Thus, as we type in (eg.) www.google.com/www.yahoo.com in the address bar of our browsers, it is the DNS (or the Domain Naming Service) which resolves the Domain Name into their corresponding IP addresses  to connect to the appropriate servers of google/yahoo. BIND ( (Berkeley Internet Name Daemon) is by far the most widely used DNS software on the Internet.

The Root (.), story begins here

What happens when you type in www.google.com in your browser?

Do you really know the URL transforms itself to www.google.com. Notice the Dot (.) following the domain name. The mysterious dot or the Root !!

The sequence of events that take place thereafter;

1. Browser asks OS if it has the IP address of www.google.com.

2. OS looks its host (in Linux, it is determined by the entries in "/etc/host.conf", assuming the order is host
    bind) and Cache to find if it has the IP of www.example.com.

3. Then, it goes to the Resolving name server as specified in the system (in the file /etc/resolv.conf)

4. Resolving name server (local to your system) has the information about the root (the dot .) name server.         Asks the Root name sever about www.google.com

5. Root Name Server (the dot .) would reply with information about the details as where to find COM (TLD     or Top Level Domain) name server.

Resolver caches all these info and goes to TLD i.e. COM name server in this case to ask the same
    question about www.google.com

6. TLD or Top Level Domain name server would serve with details about where to find the Authoritative
     Name server or ANS for www.google.com)

(TLDs are updated with the details about which Authoritative Name server needs to used at the time of         Domain registration by the domain name registrar like godady etc.)

Resolver caches all these info and goes on to ask the Authoritative Name server or ANS, to ask the    
     same question about www.google.com

7. Authoritative Name server or ANS (google.com) contains the Address record or "A" record (IP)
    of the domanin www.google.com Thus, it returns the IP address of the www.google.com to the  
    Resolving Name server query.

Therefore, Authoritative Name server or ANS in this case "google.com" would return the resolving    
    name server an IP address like xxx.xx.xx.xxx

8. Resolving name server takes all these information and gives the information to the OS. The OS in turn
     gives the information to the browser.
 
     The browser then makes the connection to the IP address xxx.xx.xx.xxx !!

      Google page is served ! ;)

How DNS works
Configuring BIND

Following are the steps to Configure BIND on CentOS-6 systems (it should work on other Linux based system as well )

Test Environment:
(I)   IPs:
Bind server IP: 172.16.20.174
Client IP: 172.16.20.175
(II) SeLinux and IPTables were turned off on both the systems.
Note: Name, IP Address are all used for test purpose only

A. On Bind server:
1. Install the following bind packages:
# yum install bind bind-libs bind-utils
# rpm -qa | grep ^bind
bind-utils-9.8.2-0.10.rc1.el6_3.2.i686
bind-9.8.2-0.10.rc1.el6_3.2.i686
bind-libs-9.8.2-0.10.rc1.el6_3.2.i686

2. Start the "named" service to check if it is working;
# service named start

3. Create the forward and reverse zone files under /var/named/ directory for the domain which
            needs to be set up:
# cd /var/named
A. Forward zone file (for test purpose eg; linuxdomain-tux.com)
# vim linuxdomain-tux.com.fwd
$ORIGIN linuxdomain-tux.com.
$TTL 3D
@       SOA     linuxdomain-tux.com.     admin.linuxdomain-tux.com. (12 4h 1h 1w 1h)
@       IN      NS          linuxdomain-tux.com.

linuxdomain-tux.com.     IN      A       172.16.20.174
www                      IN      A       172.16.20.174    ; you may exclude this. Tested to see if    domain name is resolved if preceded by "www"

B. Reverse zone file (for test purpose eg; linuxdomain-tux.com)
# vim linuxdomain-tux.com.rev
$ORIGIN 20.16.172.in-addr.arpa.
$TTL 3D
@       SOA     linuxdomain-tux.com.  admin.linuxdomain-tux.com. (12 4h 1h 1w 1h)
                @        IN      NS      linuxdomain-tux.com.

174     IN      PTR     linuxdomain-tux.com.   ;  used only the last octet of the IP

4. Change the group of zone files to "named" :
# chgrp named linuxdomain-tux.com.*

5. Now,  make changes/append the content in /etc/named.conf (defaults were commented. Keep rest of file intact);
// listen-on port 53 { 127.0.0.1; };   //You may use specific ip addresses as well
        listen-on port 53 { any; };
// allow-query     { localhost; };      //You may use specific ip addresses as well             
               allow-query     { any; };    

zone "linuxdomain-tux.com" {
type master;
file "linuxdomain-tux.com.fwd";
};
zone "20.16.172.in-addr.arpa" {
type master;
file "linuxdomain-tux.com.rev";
};

6. Restart the "named" service:
#  service named restart

7. Now, need to tell the resolver to resolve this domain "linuxdomain-tux.com". Edit
        /etc/resolve.conf and make the entry for this IP:
# vim /etc/resolv.conf
nameserver 172.16.20.174

B. Test (On Bind server; you may use any tool):
1. # host linuxdomain-tux.com
linuxdomain-tux.com has address 172.16.20.174

2. # nslookup linuxdomain-tux.com
Server: 172.16.20.174
Address: 172.16.20.174#53
Name: linuxdomain-tux.com
Address: 172.16.20.174

3. # nslookup 172.16.20.174
Server: 172.16.20.174
Address: 172.16.20.174#53
174.20.16.172.in-addr.arpa name = linuxdomain-tux.com.

4. # nslookup www.linuxdomain-tux.com       (This is since "www" entry was made in the zone file)
Server: 172.16.20.174
Address: 172.16.20.174#53
Name: www.linuxdomain-tux.com
Address: 172.16.20.174



5. # dig linuxdomain-tux.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.2 <<>> linuxdomain-tux.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11793
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;linuxdomain-tux.com. IN A
;; ANSWER SECTION:
linuxdomain-tux.com. 259200 IN A 172.16.20.174
;; AUTHORITY SECTION:
linuxdomain-tux.com. 259200 IN NS linuxdomain-tux.com.
;; Query time: 0 msec
;; SERVER: 172.16.20.174#53(172.16.20.174)
;; WHEN: Wed Aug 22 16:57:17 2012
;; MSG SIZE  rcvd: 70

C. On Client:
1. Edit /etc/resolv.conf to have one entry that points to "linuxdomain-tux.com"
vim /etc/resolv.conf
nameserver 172.16.20.174

D. Test (On client; you may use any tool):
1. # host linuxdomain-tux.com
linuxdomain-tux.com has address 172.16.20.174

2. # nslookup linuxdomain-tux.com
Server: 172.16.20.174
Address: 172.16.20.174#53
Name: linuxdomain-tux.com
Address: 172.16.20.174

3. # nslookup 172.16.20.174
Server: 172.16.20.174
Address: 172.16.20.174#53
174.20.16.172.in-addr.arpa name = linuxdomain-tux.com.

4. # nslookup www.linuxdomain-tux.com
Server: 172.16.20.174
Address: 172.16.20.174#53
Name: www.linuxdomain-tux.com
Address: 172.16.20.174

Tuesday, August 10, 2010

IPTABLES, Custom IP Chains in Linux

Creating a custom IP Chain, adding rules to that and creating a rule which would bring the Custom Chain into play:

1. Create a New Rule:
[root@rhel5 ~]# iptables -N MYCHAIN

2. Add a rule to that chain eg. to disallow an IP (192.168.1.10) from accessing the SMTP port (25) on (192.168.1.20):
[root@rhel5 ~]# iptables -A MYCHAIN -s 192.168.1.10 -d 172.168.1.20 -p tcp --dport 25 -j REJECT

(The destination IP is an alias to the network interface eth0, eg. eth0:1)


3. Creating a rule in the default INPUT chain which would jump to the custom rule whenever any request comes on the eth+ interface:
[root@rhel5 ~]# iptables -A INPUT -i eth+ -j MYCHAIN

4. Save the iptables rules:
[root@rhel5 ~]# service iptables save

5. Restart the iptables service
[root@rhel5 ~]# service iptables restart

6. To list all the rules;
[root@rhel5 ~]# iptables -L

Saturday, July 31, 2010

Trouble setting up wireless for the network card type BCM4312 802.11b/g on Dell Inspiron-1525 running Fedora-13 ?

This piece of information is for all those who might face some issue in setting up of wireless network for Fedora release 13 (Goddard) on your "Dell Inspiron - 1525" laptop having BCM4312 802.11b/g card. The default driver which Fedora-13 provided for BCM4312 802.11b/g didn't work for me, thus I had look for a driver that would have served my purpose of going wireless. Following are the steps by which I could make wireless working for me, hope it helps you too...


So let's get started;
1. Check if you have wireless connection;
[root@Fedora-13 ~]# iwconfig
lo no wireless extensions.

eth0 no wireless extensions.

wlan0 IEEE 802.11bg Mode:Managed Access Point: Not-Associated
Tx-Power=0 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
pan0 no wireless extensions.


(Well, it shows wlan0 since it has the driver installed for wireless device, but for me unfortunately this did work when I tried to connect it with my wireless modem). Thus the workaround is to remove the driver installed and find an appropriate one and hook it up with the Broadcom network card.

2. Locate the Device ID's of Broadcom cards on your system by:
[root@Fedora-13 ~]# lspci -n | grep 14e4

3. Locate the installed driver;

[root@Fedora-13 ~]# lspci -v
0b:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g LP-PHY (rev 01)
Subsystem: Dell Wireless 1395 WLAN Mini-Card
Flags: bus master, fast devsel, latency 0, IRQ 17
Memory at fe7fc000 (64-bit, non-prefetchable) [size=16K]
Capabilities: [40] Power Management version 3
Capabilities: [58] Vendor Specific Information: Len=78
Capabilities: [e8] MSI: Enable- Count=1/1 Maskable- 64bit+
Capabilities: [d0] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [13c] Virtual Channel
Capabilities: [160] Device Serial Number 41-d9-4d-ff-ff-a9-00-23
Capabilities: [16c] Power Budgeting
Kernel driver in use: b43-pci-bridge
Kernel modules: ssb

4. Note the Kernel module from above output and if you are interested to get the details;
[root@Fedora-13 ~]# modinfo ssb
filename: /lib/modules/2.6.33.3-85.fc13.i686/kernel/drivers/ssb/ssb.ko
license: GPL
description: Sonics Silicon Backplane driver
srcversion: B67624D9C93DCB668DC35D2
alias: pci:v000014E4d0000432Bsv*sd*bc*sc*i*
alias: pci:v000014E4d00004329sv*sd*bc*sc*i*
alias: pci:v000014E4d00004328sv*sd*bc*sc*i*
alias: pci:v000014E4d00004325sv*sd*bc*sc*i*
alias: pci:v000014E4d00004324sv*sd*bc*sc*i*
alias: pci:v000014E4d00004321sv*sd*bc*sc*i*
alias: pci:v000014E4d00004320sv*sd*bc*sc*i*
alias: pci:v000014E4d00004319sv*sd*bc*sc*i*
alias: pci:v000014E4d00004318sv*sd*bc*sc*i*
alias: pci:v000014E4d00004315sv*sd*bc*sc*i*
alias: pci:v000014E4d00004312sv*sd*bc*sc*i*
alias: pci:v000014E4d00004311sv*sd*bc*sc*i*
alias: pci:v000014E4d00004307sv*sd*bc*sc*i*
alias: pci:v000014E4d00004306sv*sd*bc*sc*i*
alias: pci:v000014E4d00004301sv*sd*bc*sc*i*
depends: mmc_core
vermagic: 2.6.33.3-85.fc13.i686 SMP mod_unload 686
5. Download the driver files:
Downloaded the file hybrid-portsrc-x86_32-v5.60.48.36.tar.gz from

6. Extract it under a folder like /home/bijit/Downloads/hybrid_wl;
[root@Fedora-13 hybrid_wl]# tar -xvzf hybrid-portsrc-x86_32-v5.60.48.36.tar.gz

7. Now, you can refer to the installation manual that comes with package which was downloaded. But,
let me continue with how that was done on my system...
To build the driver I did the following;

8. Check the version of the installed Kernel;

[root@Fedora-13 hybrid_wl]# uname -r
2.6.33.3-85.fc13.i686

9. To make sure if I have the all the tools available, tried the following command only to encounter the
error :-)

make: *** /lib/modules/"release"/build: No such file or directory. Stop.

10. So, I would require the Kernel-devel package since it would not have thrown the above
error and there would have been the directory (/lib/modules/2.6.33.3-85.fc13.i686/build)
created by that package.

11. Installed the following Development package for building kernel modules to match the kernel;
kernel-devel-2.6.33.3-85.fc13.i686

12. Now, check for the directory which was missing earlier;
[root@Fedora-13 hybrid_wl]# ll /lib/modules/2.6.33.3-85.fc13.i686/build
lrwxrwxrwx. 1 root root 46 May 13 06:58 /lib/modules/2.6.33.3-85.fc13.i686/build
-> ../../../usr/src/kernels/2.6.33.3-85.fc13.i686

13. Building the driver as a loadable kernel module (LKM);
[root@Fedora-13 hybrid_wl]# make clean
[root@Fedora-13 hybrid_wl]# make
(Well, here I had to install gcc with all/any of its dependencies. This was necessary since compilers were
missing on my system)

14. In the above steps, the build process completes to generate "wl.ko" file.

15. I need to remove the previous non-fuctional "ssb" drivers;
[root@Fedora-13 hybrid_wl]# lsmod | grep "b43\|ssb"
[root@Fedora-13 hybrid_wl]# rmmod ssb; rmmod b43

16. As a precaution blacklisted the drivers to prevent it from getting loaded in future;
[root@Fedora-13 hybrid_wl]# echo "blacklist ssb" >> /etc/modprobe.d/blacklist.conf;
[root@Fedora-13 hybrid_wl]# echo "blacklist b43" >> /etc/modprobe.d/blacklist.conf;

17. Insmod the driver that was built in the previous steps;
Since, no "wl" drivers were prior to this one on my system, i had to add a security module before using the "wl" module.
[root@Fedora-13 hybrid_wl]# modprobe lib80211
then;
[root@Fedora-13 hybrid_wl]# insmod wl.ko

Wireless driver (wl.co) is now operational. Needed to wait for couple of seconds since
the Network Manager would take few seconds to detect the presence of a new network
driver and show the surrounding wireless networks.

18. Make the driver Boot time loadable.
[root@Fedora-13 hybrid_wl]# cp wl.ko /lib/modules/`uname -r`/kernel/drivers/net/wireless/

Lets generate modules.dep and map files
[root@Fedora-13 hybrid_wl]# depmod -a
[root@Fedora-13 hybrid_wl]# echo modeprobe wl >> /etc/rc.local

Note: I ignored the license warning that I received at the time of module insertion. I don't think its going to make any difference. Well, the whole setup also works for Fedora-10 instalations if you have network card is the one mentioned above...

My wireless network on Fedora-13 is working smoothly like any other wireless on any other devices :-)