Software & AppsOperating SystemLinux

How To Add Network Printer to Ubuntu Server via Command Line

Ubuntu 4

In this article, we will delve into the process of adding a network printer to an Ubuntu server via the command line. This is a useful skill for system administrators working with Ubuntu servers, particularly in environments where printers are shared across a network. We will be using the Common Unix Printing System (CUPS) for this purpose.

Quick Answer

To add a network printer to an Ubuntu server via the command line, you can use the lpadmin command. First, make sure you have CUPS installed on your server. Then, run the lpadmin command with the appropriate options to specify the printer name, IP address, and driver. Finally, restart the CUPS service and you can start printing files to the network printer.

What is CUPS?

CUPS, or the Common Unix Printing System, is a modular printing system that allows a computer to act as a print server. A computer running CUPS is a host that can accept print jobs from client computers, process them, and send them to the appropriate printer.

Installing CUPS

Before we can add a network printer, we need to ensure that CUPS is installed on our Ubuntu server. You can install CUPS by using the apt package manager. Here is the command to install CUPS:

sudo apt install cups

The sudo command is used to run the following command as a superuser, or root user. The apt command is the package manager for Ubuntu, and install cups tells it to install the CUPS package.

Adding a Network Printer

Once CUPS is installed, we can add a network printer using the lpadmin command. This command is used to create, modify, or delete printers in the CUPS system. The syntax for adding a new printer is as follows:

sudo lpadmin -p printername -E -v ipp://printer_ip_address/ipp/print -m everywhere

Let’s break down this command:

  • sudo: This command allows us to run the following command as the root user.
  • lpadmin: This is the command to administrate printers in CUPS.
  • -p printername: This option specifies the name of the printer. Replace printername with the desired name for your printer.
  • -E: This option enables the printer.
  • -v ipp://printer_ip_address/ipp/print: This option specifies the device URI (Uniform Resource Identifier). Replace printer_ip_address with the IP address of your network printer.
  • -m everywhere: This option specifies the model or driver for the printer. The ‘everywhere’ model is a generic driver that supports many printers.

Restarting the CUPS Service

After adding the printer, you may need to restart the CUPS service for the changes to take effect. You can do this using the following command:

sudo service cups restart

The sudo command runs the following command as the root user. The service command is used to run system services, cups is the name of the service, and restart tells the system to stop and then start the service again.

Printing a File

You can now print to the network printer using the lp command followed by the file you want to print. For example:

lp filename.txt

Replace filename.txt with the name of the file you want to print.

Conclusion

In this article, we have covered how to add a network printer to an Ubuntu server via the command line. This includes installing CUPS, adding a printer using the lpadmin command, restarting the CUPS service, and printing a file. For more information, you can refer to the CUPS documentation on setting up network printers at https://www.cups.org/doc/network.html.

Remember, it’s important to replace the placeholders in the commands with the actual values for your network printer. And as always, be careful when running commands as the root user, as it gives you the power to make significant changes to your system.

What is the purpose of CUPS?

CUPS allows a computer to act as a print server, accepting print jobs from client computers, processing them, and sending them to the appropriate printer.

How do I install CUPS on Ubuntu server?

You can install CUPS on Ubuntu server by using the apt package manager. Use the command sudo apt install cups to install CUPS.

How do I add a network printer using the command line?

To add a network printer via the command line, use the lpadmin command with the appropriate options. For example: sudo lpadmin -p printername -E -v ipp://printer_ip_address/ipp/print -m everywhere. Replace printername with the desired name, and printer_ip_address with the IP address of the network printer.

Do I need to restart the CUPS service after adding a printer?

Yes, you may need to restart the CUPS service for the changes to take effect. Use the command sudo service cups restart to restart the CUPS service.

How can I print a file to the network printer?

You can print a file to the network printer using the lp command followed by the file name. For example: lp filename.txt. Replace filename.txt with the name of the file you want to print.

Leave a Comment

Your email address will not be published. Required fields are marked *