Skip to content
jameshofstra edited this page Mar 8, 2017 · 4 revisions

ZNC is a program that maintains persistent connections to Internet Relay Chat (IRC) networks, receiving messages even when your computer is offline. You point your IRC client to the system running ZNC, and it automatically joins your preferred IRC channels and displays a transcript of what happened while you were away.

This page demonstrates how to quickly get started with ZNC. Additional information can be found in the ZNC wiki.

Installation

ZNC can only keep you connected to IRC if the machine it's running on is powered on and connected to the Internet. In other words, that laptop you take everywhere isn't a good candidate for running ZNC. (But you can run ZNC on a different machine and connect to it using an IRC client on your laptop.)

If you can afford a virtual private server (VPS), it's one of the best ways to use ZNC. If you have an energy-efficient desktop machine, a Raspberry Pi, or something similar that you can leave running 24/7, you can install ZNC on that machine and configure your router with a port-forwarding rule (plus Dynamic DNS if your router supports it). ZNC can serve multiple users concurrently, so you may be able to get a friend to run a shared ZNC server if you can't reliably run ZNC yourself.

Ubuntu 16.04 LTS

Ubuntu is commonly used among VPS providers, so it's good to know how to install ZNC on Ubuntu. Start by adding the ZNC Ubuntu PPA:

sudo apt-get install python-software-properties software-properties-common
sudo add-apt-repository ppa:teward/znc
sudo apt-get update

Then install the default ZNC packages:

sudo apt-get install znc znc-dbg znc-dev znc-perl znc-python znc-tcl

Slackware

ZNC is maintained in the SlackBuilds repository.

Other distros and source/development builds

See the ZNC wiki's Installation page.

Initial configuration

To configure ZNC for the logged-in user, run:

znc --makeconf

If you want to execute ZNC as a system service instead, make a new user account and use it to run the configuration:

sudo useradd --create-home -d /var/lib/znc --system --shell /sbin/nologin --comment "Account to run ZNC daemon" --user-group znc
sudo -u znc /usr/bin/znc --datadir=/var/lib/znc --makeconf

You'll be prompted for input several times. The following settings are recommended:

Prompt Recommended
Listen on port 6697 (but any valid port number will do)
Listen using SSL yes
Listen using both IPv4 and IPv6 yes

Next, you'll configure a ZNC user/admin. The username and password are used only for connecting to ZNC, and are not visible to IRC networks. The other fields (nick, alt. nick, ident, real name, bind host) are configured here as defaults for setting up new connections; you can just go with the default values and make adjustments later.

At this point, you can optionally use the wizard to configure a network and/or start the server; you can just type no for each prompt and perform those steps later.

Starting the server

If you configured ZNC as a standard user, start the server in the background by running:

znc

If you configured ZNC as a system service, you will want to set up init scripts so that you can easily start/stop/restart ZNC. The ZNC wiki has a page with examples for init.d and systemd.

systemd with automatic restarting

The following systemd unit executes ZNC as a system service, and automatically restarts ZNC if it is not running (e.g. following a system reboot). Save it as /etc/systemd/system/znc.service.

[Unit]
Description=ZNC, an advanced IRC bouncer
After=network-online.target
     
[Service]
ExecStart=/usr/bin/znc -f --datadir=/var/lib/znc
User=znc
Restart=always
     
[Install]
WantedBy=multi-user.target

Then enable it by running:

sudo systemctl start znc.service
sudo systemctl enable znc.service

Using the web interface

The webadmin module provides a web interface into ZNC's configuration. Just point your web browser to the domain/IP and port number of the ZNC instance and log in with your ZNC username and password. For instance: http://localhost:6667 or https://localhost:6697

ZNC generates a self-signed certificate if you previously enabled SSL. As a result, your web browser will warn you that the certificate isn't trusted; however, you can safely override the warning and connect anyway. (It's also possible to replace the self-signed certificate in order to avoid the warning in the first place.)

User settings

Click on the "Your Settings" link in the sidebar to edit your ZNC settings and add IRC networks. Here is a description of each section:

  • Authentication: You can change your ZNC username and password here.
  • IRC Information: You can change the default nick and other information shown to IRC users here. These items are explained further in the "Adding a network" section.
  • Networks: Lists the networks you have added (more information in the "Adding a network" section).
  • Modules: Lists available modules and allows you to enable or disable them. In addition to the defaults (chansaver, controlpanel), I like to enable log, which stores a copy of all messages in ZNC's data directory; I can then easily back up these messages with other Linux utilities.
  • Default Settings: You can change the default IRC channel settings here. These items are explained further in the "Adding a channel" section.
  • Flags: Miscellaneous settings. I like to disable Auto Clear Chan Buffer (so that I can log in with another IRC client and still see the old messages) and enable Multi Clients (self-explanatory) and Prepend Timestamps (adds a timestamp to messages replayed from the buffer).
  • ZNC Behavior: More miscellaneous settings. I like to change the Timestamp Format to contain %D, which displays the date along with the timestamp.

When you have made the desired changes, click the "Save and return" button or the "Save and continue" button to save your settings. No changes on the page will be saved unless you click either Save button.

Adding a network

Under the Networks section in the user settings, click the "Add" link to add a new network. Fill in the information as follows:

  • Network Info
    • Network Name: An alphanumeric name for the network you are adding; it will be used later when connecting with your IRC client.
    • Nickname (a.k.a. nick): The handle shown to other IRC users when you send a message. If a user wants your attention, they will typically prefix their message with your nick and a colon (e.g. jameshofstra: <message>).
    • Alt. Nickname: The users in an IRC room should have unique nicks. If the primary nick is already in use, ZNC will request the alt. nick instead.
    • Ident: Each computer connecting to IRC is identified in a "ident@host" format. This controls the "ident" portion of that string.
    • Realname: A verbose identifier that can hold just about any extra information. It could be your real name, email address, website, etc. If you don't care to put any extra info, you can just copy-paste your nick here.
    • BindHost: Each computer connecting to IRC is identified in a "ident@host" format. This controls the "host" portion of that string. Leave it blank to have it default to your IP address. (The ZNC wiki talks about how to properly configure a BindHost.)
    • Quit Message: Text that is shown to IRC users when you quit ZNC. It's not particularly important, so you can just leave the default setting.
    • Active: A flag that tells ZNC whether to connect you to the IRC network. Typically you want this enabled.
    • Servers of this IRC network: Here, you enter the domain name (or IP address), port number, and (optionally) password used to connect to the IRC network. It is possible to specify multiple servers (one line for each server) and whether a server uses SSL (put a + in front of the port number). For instance, I use the following entries for Freenode: chat.freenode.net +6697, chat.freenode.net +7000, chat.freenode.net +7070
    • Trusted SSL fingerprints of this IRC network: If the IRC network uses a self-signed certificate, you should add its fingerprint here to prevent spurious certificate errors.
    • Flood protection and Channel join delay: Congestion control mechanisms; the defaults should be fine.
    • Server encoding: Typically you want UTF-8, but you can customize this if you're dealing with a strange network.
  • Channels: Lists the channels you have added (more information in the "Adding a channel" section). If you're just adding a new network, you can't do anything here yet.
  • Modules: Lists available modules and allows you to enable or disable them. There are a couple of modules I use:
    • keepnick: This module automatically assigns you your primary nick when it becomes available. This is useful when network conditions cause ZNC to disconnect and quickly reconnect with your alt nick.
    • sasl: This module authenticates your ZNC user to NickServ (more information in a later section).
    • stickychan: This module prevents you from inadvertently leaving a channel. This is necessary if you use the Pidgin client, because Pidgin tries to /part channels before quitting.

When you have made the desired changes, click the "Save and return" button or the "Save and continue" button to save your settings. No changes on the page will be saved unless you click either Save button.

Adding a channel

Under the Channels section in the network settings, click the "Add" link to add a new channel. Fill in the information as follows:

  • Channel Info
    • Channel Name: The IRC channel you want to add (e.g. #linuxcsuf).
    • Key
    • Buffer Count: How many messages to buffer while you are away (if too many messages arrive, the oldest ones are dropped from the buffer).
    • Default Modes
  • Flags: Make sure Save to config is enabled and the others are disabled. Auto Clear Chan Buffer is inherited from your user settings by default, but you can enable or disable it as you wish.
  • Module stickychan: If you enabled the "stickychan" module earlier, you'll want to enable the Channel is sticky flag.

When you have made the desired changes, click the "Save and return" button or the "Save and continue" button to save your settings. No changes on the page will be saved unless you click either Save button.

Using your IRC client

In your IRC client, specify the following parameters:

  • Server: The domain/IP of the ZNC instance.
  • Port: The port number of the ZNC instance.
  • SSL: Enabled, if you previously enabled SSL in the initial configuration.
  • Username: Your ZNC username, plus /, plus your network name (e.g. james/freenode).
  • Password: Your ZNC password. If your IRC client doesn't have a separate username field, use the above username, plus :, plus your ZNC password (e.g. james/freenode:myzncpass).

Your IRC client should automatically "join" the channels you added earlier.

Authenticating with NickServ

If you want to reserve a particular nick on IRC so that you can always use it, you can register your nick with NickServ. The NickServ incantations differ between IRC networks, but in most cases you can start by giving your IRC client the following command:

/msg NickServ REGISTER <secret-password> <email-address>

In the case of Freenode, you'll get an email with a token that you send to NickServ in order to prove that you control the registered email address. Once you complete the registration, you will need to authenticate with NickServ each time you connect to IRC. ZNC can do this automatically with the sasl module (preferred) or with the nickserv module.

Make sure the sasl module is enabled, then go to your IRC client and enter the following commands:

/msg *sasl Mechanism EXTERNAL PLAIN
/msg *sasl Set <registered-nick> <secret-password>

If your IRC network doesn't support SASL for some reason, you can use the nickserv module instead. Enter the following IRC command:

/msg *nickserv Set <secret-password>

NOTE: In order for ZNC to authenticate with NickServ automatically, your NickServ password is stored in plain text. If it's your machine and you are the only ZNC user, this is fine as long as you restrict read access on the ZNC data directory from other non-root users. (This is a good reason to run ZNC as a system service.) If you are using someone else's ZNC server, you'll have to trust them with your NickServ password.