An IRC server with ircd-hybrid and hybserv on Ubuntu 12.04LTS

I setup a private IRC server today on an Ubuntu 12.04LTS machine, but ran into some frustrations in the process. Hopefully, this can simplify the process for you.

I've never had a reason to create an IRC server, so first I researched a bit. I settled on using the common ircd-hybrid IRC server with hybserv2 to provide nickserv and chanserv. The intial ircd-hybrid setup was simple; getting hybserv2 to talk to ircd-hybrid was the difficult part. I found some good information here and here, but further details were required.

Installing ircd-hybrid

First install ircd-hybrid from the repos:

sudo apt-get update
sudo apt-get install ircd-hybrid

Use mkpasswd to generate an encrypted password for the configuration files. The password is used by the administrator to gain operator privileges and by hybserv to add bots.

mkpasswd MyNewSecurePassword
hSRshwZirOrK2

Open the IRC server configuration and adjust to suit your needs. The following contains the minimum configuration required, feel free to change anything else as needed:

sudo nano /etc/ircd-hybrid/ircd.conf

The first section to change is the serverinfo. Change the name, description, network_name, and network_description as needed.

 /* serverinfo {}:  Contains information about the server. (OLD M:) */
serverinfo {
  /* name: the name of our server */
  name = "irc.example.com";

  /* description: the description of our server.  '[' and ']' may not
   * be used here for compatibility with older servers.
   */
  description = "Example.com IRC Server";

  /* network info: the name and description of the network this server
   * is on.  Shown in the 005 reply and used with serverhiding.
   */
  network_name = "example";
  network_desc = "example.com irc";

Change admin section to have some useful information:

/* admin {}: contains admin information about the server. (OLD A:) */
admin {
  name = "Example Admin";
  description = "Example Server Administrator";
  email = "<email@example.com>";
};

Next comes the listen section. Comment out the host line to bind to all available IP addresses.

/* listen {}: contain information about the ports ircd listens on (OLD P:) */
listen {
  /* port: the specific port to listen on.  if no host is specified
   * before, it will listen on all available IPs.
   *
   * ports are separated via a comma, a range may be specified using ".."
   */

  /* port: listen on all available IPs, ports 6665 to 6669 */
  #host = "127.0.0.1"; # change this!
  port = 6665 .. 6669;
};

Scroll down to the operator section. Note the user is set to *@127.0.0.1, which means any localhost user can connect as root. Set the password to the encrypted password generated above. If you set the password incorrectly here or in the hybserv configuration, you'll receive a Closing Link: Invalid password. error in the hybserv logs.

/* operator {}: defines ircd operators. (OLD O:)
 * ircd-hybrid no longer supports local operators, privileges are
 * controlled via flags.
 */
operator {
  /* name: the name of the oper */
  name = "root";

  /* user: the user@host required for this operator.  CIDR is not
   * supported.  multiple user="" lines are supported.
   */
  user = "*@127.0.0.1";

  /* password: the password required to oper.  By default this will
   * need to be encrypted using '/usr/bin/mkpasswd'.
   * WARNING: Please do not mix up the 'mkpasswd' program from
         * /usr/sbin with this one. If you are root, typing 'mkpasswd'
   * will run that one instead and you will receive a strange error.
   *
   * MD5 is supported. If you want to use it, use mkpasswd -Hmd5.
   */
  password = "hSRshwZirOrK2";

Scroll down to the connect section and add the following code to specify how hybserv2 will connect to ircd-hybrid. Note that the name of the server is different than the name of the IRC server above. If it is the same you'll receive Closing Link: Invalid servername. or Closing Link: Server ID Exists. errors in the hybserv logs.

connect {
  /* name: the name of the server */
  name = "ircservices.example.com";
  /* host: the host or IP to connect to. If a hostname is used it * must match the reverse dns of the server. */
  host = "127.0.0.1";
  /* passwords: the passwords we send (OLD C:) and accept (OLD N:). * The remote server will have these passwords rev$
  send_password = "password";
  accept_password = "password";
  /* compressed: controls whether traffic is compressed via ziplinks. * By default this is disabled */
  compressed = no;
  hub_mask = "*";
  class = "server";
};

Now save and close the configuration file, then restart ircd-hybrid:

sudo /etc/init.d/ircd-hybrid restart

Installing hybserv
Hybserv is not available in the Ubuntu repos, so you'll need to download and compile it yourself. Don't worry, the process is straightforward. Go to this page to download Hybrid2 IRC Services, copy the direct link URL and perform the following commands:

# Make sure you've got the tools required to compile software.
sudo apt-get install build-essential
# Paste the download URL after the wget command.
wget $url
# Uncompress the newly downloaded file.
tar xvfz $filename
# Change to the newly created hybserv directory.
cd hybserv
# If you don't need to configure specific settings, you can simply run the install.fast script. Refer to the INSTALL file for details.
./install.fast
# Change to the hybserv install directory (this is the default, change if you installed it elsewhere.)
cd /usr/local/hybserv
# Make the irc user (created by the ircd-hybrid install) the owner of the files for additional security.
sudo chown -R irc:irc .

Open the configuration file for hybserv to configure how it will connect to ircd-hybrid:

sudo nano /usr/local/hybserv/hybserv.conf

The current hybserv configuration is set up for older IRC servers, so it is more difficult to read. A, N, S, and O lines need to be changed or added. Adjust the file to make them match settings specified above:

# Set the Administrator name/email.
A:Example Admin <admin@example.com>
# Set the hostname for the IRC services.
N:ircservices.example.com:Example IRC services.
# Set the password (which is actually the word password), IP, and port of the IRC server to connect to.
S:password:127.0.0.1:6667
# Set the user, encrypted password, nickname and privileges for the connection.
O:*@*:hSRshwZirOrK2:root:segj

Save and close the configuration file, then start hybserv as the irc user:

sudo su irc -c /usr/local/hybserv/hybserv

Log in to the IRC server with the irc program. Apt-get install epic4, epic5, or ircii to get the an irc program if you do not have one.

irc 127.0.0.1

Now you should be able to confirm that nickserv is available by typing:

/msg nickserv help

Everything work? If so there are many additional options to configure for both ircd-hybrid and hybserv.

  • Adjust the number_per_ip and max_number in /etc/ircd-hybrid/ircd.conf for regular users.
  • Adjust the /etc/ircd-hybrid/ircd.motd file to change the message of the day.
  • Setup hybserv as a service to run automatically on startup. Following is for Ubuntu 12.04 LTS YMMV.
    Create a service file:

    sudo nano /etc/init.d/hybserv

    Add the following to the file.

    #!/bin/bash
    # Kill the current hybserv, and start a new one.
    kill `cat /usr/local/hybserv/hybserv.pid`
    su irc -c /usr/local/hybserv/hybserv

    Save and close the file. Then make it executable and add it to the startup scripts.

    sudo chmod u+x /etc/init.d/hybserv
    sudo update-rc.d hybserv defaults
  • If you have a firewall setup (and you should!), you can open port 6667 with the following command:
    sudo ufw allow 6667
  • Plus many more.

Everything doesn't work? The following commands can partially automate your debugging process.

# Close the current hybserv instance.
sudo kill `cat /usr/local/hybserv/hybserv.pid`
# Edit the hybserv configuration.
sudo pico /usr/local/hybserv/hybserv.conf
# Restart hybserv
sudo su irc -c /usr/local/hybserv/hybserv
# Tail the hybserv log file
sudo tail /usr/local/hybserv/logs/hybserv.log 
# Tail the ircd-hybrid log file
sudo tail /var/log/ircd/ircd-hybrid.log

Comments

So this is an awesome guide, and thanks for making it. Currently I'm banging my head against the wall though.. I think perhaps it's in my ircservices name. if my server name is server.test.host.com, would it be ircservices.test.host.com? And do I have to create that to exist elsewhere?

Yes, your ircservices name is correct. You need to make sure DNS works for the host name.

Thanks for you good tutorial! But I've a little problem. When I try to start hybserv, it says that it couldn't find the pid file. Can you maybe send me the content of the pid file, so I can create it myself?

Thanks
Renzo

Hi, when I'm really confused... When I run the following command:
sudo su irc -c /usr/local/hybserv/hybserv

I get:
Hybserv2 TS services version 1.9.4-release by Hybserv2 team
Compiled at May 20 2013, 01:11:52
WARNING: Unable to read pid file hybserv.pid
Running in background (pid: 1788)

Then when I try to log in to the IRC server with the irc program using epic5 and the command:
irc 127.0.0.1

I get:
EPIC Version 5 -- Trencherman
EPIC Software Labs (2006)
Version (EPIC5-1.1.2), Commit Id (1638) -- Date (20100430)
Compiled by buildd@allspice on Sun May 8 2011 at 06:46:36 UTC
Process [1833] connected to tty [/dev/pts/0]
Using terminal type [xterm]
*** I can't find your mailbox.
File not found: tc
*** Performing DNS lookup for [127.0.0.1] (server 0)
*** DNS lookup for server 0 [127.0.0.1] returned (1) addresses
*** Connecting to server refnum 0 (127.0.0.1), using address 1 (127.0.0.1:6667)
*** INFO -- Could not connect to server [0] address [1] because of error: Connection
+refused
*** I'm out of addresses for server 0 so I have to stop.
*** Unable to connect to server 0 at 127.0.0.1:6667

Please help, I guess mail would be the fastest... :(

Hmm, I was a bit too quick when it came to reading. I had a look at the log and saw two errors in the ircd config file. I fixed those and managed to start the ircd server. Now I can connect to it. There are still some problems.

When I do:
sudo su irc -c /usr/local/hybserv/hybserv

I still get:
Hybserv2 TS services version 1.9.4-release by Hybserv2 team
Compiled at May 20 2013, 01:11:52
WARNING: Unable to read pid file hybserv.pid
Running in background (pid: 2768)

And.... It makes one of the CPU cores go at 100% usage, using 99%.

Then when I connect to the IRC and run
/msg nickserv help

I get:
*** nickserv: No such nick/channel
*** nickserv :There was no such nickname
*** nickserv :End of WHOWAS

I don't think that's right.

In my experience, the CPU use goes to 100% when ircservices cannot connect to the irc server. Confirm that the ircservices configuration is correct.

What I don't understand though is that the name of the server is different than the name of the IRC server under serverinfo. Could you help me out? I'm going to reinstall this whole thing because it's breaking my balls.

Open two more SSH connections to your server and tail both log files. There will be more details and hopefully useful error messages. I documented all the errors I encountered, but I'm sure there are others to discover.

# Tail the hybserv log file
sudo tail -f /usr/local/hybserv/logs/hybserv.log 
# Tail the ircd-hybrid log file
sudo tail -f /var/log/ircd/ircd-hybrid.log

I kind of ragequitted so I decided to re-install the whole thing because I had to do something wrong. I'll report back on about 30-60 minutes and let you know. Also, everything under "connect" had a number sign (#) at the beginning. Removed it and still the same problem though.

Okay, I reinstalled the whole thing and re-configured everything.

# Tail the hybserv log file
sudo tail /usr/local/hybserv/logs/hybserv.log
Sun Jun 2 16:02:00 2013 FATAL: Unable to bind port tcp/5656: Address already in use
Sun Jun 2 16:02:00 2013 FATAL: Unable to bind port tcp/5656: Address already in use
Sun Jun 2 16:02:00 2013 FATAL: Unable to bind port tcp/5555: Address already in use
Sun Jun 2 16:02:00 2013 FATAL: Unable to bind port tcp/5555: Address already in use
Sun Jun 2 16:02:00 2013 FATAL: Unable to bind port tcp/6900: Address already in use
Sun Jun 2 16:02:00 2013 FATAL: Unable to bind port tcp/6900: Address already in use
Sun Jun 2 16:02:29 2013 Received SIGTERM, shutting down
Sun Jun 2 16:02:29 2013 Shutting down services
Sun Jun 2 16:02:29 2013 DIE [SIGTERM Received] (authorized by ?)
Sun Jun 2 16:02:29 2013 Closing log file

Any idea what's going on?

According to the Hybserv log, you are attempting to run it twice or a different program is already bound to those ports. Kill all hybserv processes. Tail -f the log file, then start hybserv again to find the relevant error messages. I suspect it cannot connect to ircd-hybrid.

I restarted the server and tailed the hybserv logfile.
sudo su irc -c /usr/local/hybserv/hybserv

Mon Jun 3 17:32:42 2013 Databases loaded (0 registered nicknames, 0 registered channels, 0 memo entries)
Mon Jun 3 17:32:42 2013 Listener successfully started on host [*] port tcp/5656
Mon Jun 3 17:32:42 2013 FATAL: Unable to bind port tcp/5656: Address already in use
Mon Jun 3 17:32:42 2013 Listener successfully started on host [*] port tcp/5555
Mon Jun 3 17:32:42 2013 FATAL: Unable to bind port tcp/5555: Address already in use
Mon Jun 3 17:32:42 2013 Listener successfully started on host [*] port tcp/6900
Mon Jun 3 17:32:42 2013 FATAL: Unable to bind port tcp/6900: Address already in use
Mon Jun 3 17:32:42 2013 Connecting to 127.0.0.1[127.0.0.1] tcp/6667
Mon Jun 3 17:32:42 2013 Connected to 127.0.0.1 tcp/6667
Mon Jun 3 17:32:42 2013 Server Error: Closing Link: localhost (Invalid servername.)

Continuing this via email. I'll add another comment if resolved.

I actually managed to get it working. First of I had forgot one quotation mark on the server name. Fixed that one but still not worked. Then I changed server name from irc2.*.* to ircservices.*.* then it worked, or maybe I did something else too. I don't really remember, but it's working. One question though, I can't manage to get OP in my channel by auto. Why?

This error message means that you need to set the server name in the server section of ircd.conf and hybserv.conf. See details at: http://www.gila.org/blog/2010/06/connecting-ircd-hybrid-to-hybserv

Excerpt from ircd.conf:

connect {
  name = "irc-services.mydomain.com";
  host = "127.0.0.1";
  send_password = "plaintextpass";
  accept_password = "plaintextpass";
  hub_mask = "*";
  class = "server";
};

Excerpt from hybserv.conf:
N:irc-services.mydomain.com:Hybrid services
S:plaintextpass:127.0.0.1:6667

me@ terminal:~$ sudo su irc -c /usr/local/hybserv/hybserv
Hybserv2 TS services version 1.9.4-release by Hybserv2 team
Compiled at Jun 6 2013, 02:02:06
WARNING: Unable to read pid file hybserv.pid
Running in background (pid: 31883)

Root can cat it, user 'irc' can cat it. Still digging to see what's going on here... Bug?

me@ terminal:~$ sudo tail /usr/local/hybserv/logs/hybserv.log
Thu Jun 6 04:22:07 2013 Hybserv2 TS services version 1.9.4-release started
Thu Jun 6 04:22:07 2013 Databases loaded (0 registered nicknames, 0 registered channels, 0 memo entries)
Thu Jun 6 04:22:07 2013 Listener successfully started on host [*] port tcp/5656
Thu Jun 6 04:22:07 2013 FATAL: Unable to bind port tcp/5656: Address already in use
Thu Jun 6 04:22:07 2013 Listener successfully started on host [*] port tcp/5555
Thu Jun 6 04:22:07 2013 FATAL: Unable to bind port tcp/5555: Address already in use
Thu Jun 6 04:22:07 2013 Listener successfully started on host [*] port tcp/6900
Thu Jun 6 04:22:07 2013 FATAL: Unable to bind port tcp/6900: Address already in use
Thu Jun 6 04:22:07 2013 Connecting to 127.0.0.1[127.0.0.1] tcp/6667
Thu Jun 6 04:22:07 2013 Connected to 127.0.0.1 tcp/6667

Yes, it does look like everything's happening twice. I have no idea why this is happening and I see I'm not the only one. Do you have any idea why this would happen?

Despite the errors, everything is running fine. All of my difficulties were typo-derived (except i had to enable the passwords you commented out, and set hybserv to use "anotherpassword").

You could look at the hybserv code to determine why the pid file warning is occurring, but II have no idea. It may expect the pid to always exist on start up.

This log shows each TCP port listener starting, then failing. It isn't happening twice. The connection to the IRC server is successful.

-rw------- 1 irc irc 6 Jun 6 04:31 hybserv.pid
*shrugs* posting in case anyone thinks this may have anything to do with the problem. It shouldn't, since hybserv is started with sudo su irc... *shrugs again*

Thank you so much! This literally saved me days of irc agony!