Why don't I have a database connection?

If you did not install Metasploit Framework using the binary installer, you may want to consider setting up a database. You don't need a database to run the Framework, but it's pretty useful if you want to store and view the data you've collected.

To set up a database, take a look at this awesome wiki created by the Fedora Project.

After you've set up the database, you need to connect to it. You will need to manually connect to the database each time you launch msfconsole.

To connect to the database, run the following command in msfconsole:

msf > db_connect your_msfdb_user:your_msfdb_pswd@127.0.0.1:5432/msf_database

If you configured your PostgreSQL database to run on a port other than 5432, or you have named your database something other than msf_database, you will need to replace those values in the previous command with the correct values.

To make sure that the database is connected, you can run the db_status command, which should return the following:

msf > db_status
[*] postgresql connected to msf_database

Now, you need to modify the database configuration file to store your database settings. To modify the database configuration file, you will need to edit database.yml, which is located in /path/to/framework/config. If you don't have this file, you will need to modify database.yml.example and save it as database.yml.

Open a text editor, like vim, and enter the following:

$ vim /opt/framework/config/database.yml

When the editor appears, the following information needs to be added to the database configuration file:

development:
adapter: "postgresql"
database: "msf_database"
username: "msf_user"
password: "123456"
port: 5432
host: "localhost"
pool: 256
timeout: 5

production:
adapter: "postgresql"
database: "msf_database"
username: "msf_user"
password: "123456"
port: 5432
host: "localhost"
pool: 256
timeout: 5

The database, username, password, and port attributes need to be updated with the values you've chosen for your database.

Now, you can run the following command to start the database:

msf > db_connect -y /opt/metasploit/config/database.yml