Senin, 02 November 2020

PRINTER CUPS-bad request

https://superuser.com/questions/90857/why-do-i-get-400-bad-request-in-ubuntu-9-10-cups-server  

have a cups server running on ubuntu 9.10 on my home network. Right now I can access it at 192.168.1.101:631, but when I try to access it at myservername.local:631, I get a 400 Bad Request. Here is the relevant section from my current cupsd.conf:

ServerName 192.168.1.101

# Only listen for connections from the local machine.
Listen localhost:631
Listen /var/run/cups/cups.sock

# any of the below 'Listen' directives all yield the same result
Listen 192.168.1.101:631
#Listen *:631
#Listen myservername.local:631

# Show shared printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseLocalProtocols CUPS dnssd
BrowseAddress 192.168.1.255

# Default authentication type, when authentication is required...
DefaultAuthType Basic

# Restrict access to the server...
<Location />
  Order deny,allow
  Deny from All
  Allow from 127.0.0.1
  Allow from 192.168.1.*
</Location>

# Restrict access to the admin pages...
<Location /admin>
  Order deny,allow
  Deny from All
  #Allow from 127.0.0.1
  #Allow from 192.168.1.*
</Location>

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order deny,allow
  Deny from All
  #Allow from 127.0.0.1
  #Allow from 192.168.1.*
</Location>

I get the following in /var/log/cups/error_log:

E [03/Jan/2010:18:33:41 -0600] Request from "192.168.1.100" using invalid Host: field "myservername.local:631"

What do I need to do to be able to access the cups server at both 192.168.1.101:631 and myservername.local:631?

   
4

As of Cups 1.3.10, the server does not attempt to lookup its own hostname on startup. The old behaviour can be restored by adding

HostNameLookups on

To your cupsd.conf file. More information is available in this Gentoo Bug Report as well as the CUPS 1.3.10 Release Notes.

You may also want to look into the ServerName and ServerAlias config directives. See the manpage (man cupsd.conf or available online here) for more information.

   
  • no, i've tried setting Listen to *:631 and several other settings, but none have worked – aaron Jan 4 '10 at 0:28
  • If you do ping myservername.local, is it able to resolve the IP address? – Adam Luchjenbroers Jan 4 '10 at 0:36
  • yeah, it pings at myservername.local, and i know the cups server is getting the request b/c it shows up in the log (see the error message i added to the question above) – aaron Jan 4 '10 at 1:15
  • Aha, as of Cups 1.3.10 it no longer attempts to lookup the local hostname by default, add HostNameLookups On to your config file to reinstawte the old behaviour. (bugs.gentoo.org/show_bug.cgi?id=266678) – Adam Luchjenbroers Jan 4 '10 at 2:04
  • unfortunately that doesn't work either. interestingly enough, when i add HostNameLookups On with Listen *:631, the server doesn't even respond, however i can have HostNameLookups On with Listen myservername.local:631, and it behaves as before – aaron Jan 4 '10 at 4:02
2

From your initial question, it appears that you may have tried (amongst others) a cupsd.conf variation containing the following statements:

ServerName 192.168.1.101

# Only listen for connections from the local machine.
Listen localhost:631
Listen /var/run/cups/cups.sock

# any of the below 'Listen' directives all yield the same result
#Listen 192.168.1.101:631
Listen *:631
#Listen myservername.local:631

This one certainly will have NOT worked, and likely, will have prevented the cupsd daemon from starting up. Because, the Listen localhost:631 statement will have bound it to the 127.0.0.1:631 socket. A few milliseconds later in its startup, the Listen *:631 statement would have asked for binding to all available sockets at port 631: that is, in your case at least 127.0.0.1:631 (again) and 192.168.1.101:631. When trying to bind a second time to 127.0.0.1:631cupsd would find the socket occupied already, log an error and exit.

Lesson: If you use multiple Listen: ... directives in cupsd.conf, make sure you have no overlapping.

   
1

Enabling Printing using CUPS from the Mac – How my Mac now prints to a printer plugged into a Machine running Ubuntu 9.10!

After MANY missteps, I followed these steps and the printer finally started to work using CUPS and the setup above. As a relative noob to Ubuntu and Linux, I don't know which of these steps were the magic ones that worked. It is likely that some of these steps can be changed or omitted, but they worked for me, and hopefully, for you as well.

Printer attached to the parallel port on the Linux machine was installed, running, and set to shared over the local network from CUPS (http://localhost:631 typed into the firefox location bar).

On the Linux machine, I ran ifconfig from the terminal app. to discover the local IP address (starts with 192.168.xx.x) (Your xx.x will be different numbers).

From the Mac's Safari program's location bar, I went to the url of the Linux machine's CUPS port 631 (192.168.xx.x:631) where xx.x are numbers for the local address discovered using ifconfig above.

This brought up the CUPS system on the Linux machine (which was displayed on the screen of the Mac machine).

I then went to the printers tab on the Linux machine (through safari on the Mac) and copied the location for the printer onto the clipboard (http://192.168.xx.x:631/printers/Hewlett-Packard-HP-LaserJet-1100).

I then opened port 631 on the Mac machine (http://localhost:631) which brings up the CUPS system on the Mac. (If it doesn't bring up the Mac CUPS system, look elsewhere to figure this one out).

I went to Add Printer on the Mac CUPS system.

On the Mac, I gave the added printer a name of HP_LaserJet_1100 and “cut and pasted the location into both the location and the description fields.

For device I used IPP or internet printing protocol (http).

For Device URI, I pasted the location copied from the Linux machine yet again.

I selected the proper make and model for the driver on the next screen.

Worked! Hopefully this saves someone else the hour or two it took me to thread that needle.

   
1

it is intentional behaviour that CUPS rejects requests addressed to the FQDN of the host when received over the local loopback interface.

Solution: don't make the FQDN of the host resolve to 127.0.0.1, but instead to the correct external IP address for that FQDN.

   
  • That's not correct. What you indeed do have to avoid is multiple Listen ... statements with overlapping sockets. What is completely "legal" with CUPS is having 2 (or more) separate Listen ... statements, one with Listen 127.0.0.1:631, another one with Listen 192.168.1.101:631. These do not overlap. What will always overlap is to use wildcard statements, such as Listen *:631 and also add specific ones such as Listen 192.168.1.101:631. – Kurt Pfeifle Jul 1 '10 at 9:53 
0

The following cupsd.conf file settings allowed me to print using either the IP or the hostname of the cups server:

ServerName myservername
ServerAlias *

# Only listen for connections from the local machine.
Listen localhost:631
Listen /var/run/cups/cups.sock
Listen myservername.local:631

# Show shared printers on the local network.
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseLocalProtocols CUPS dnssd
BrowseAddress 192.168.1.255

# Default authentication type, when authentication is required...
DefaultAuthType Basic

# Restrict access to the server...
<Location />
  Order deny,allow
  Deny from All
  Allow from 127.0.0.1
  Allow from 192.168.1.*
</Location>

# Restrict access to the admin pages...
<Location /admin>
  Order deny,allow
  Deny from All
  #Allow from 127.0.0.1
  #Allow from 192.168.1.*
</Location>

# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order deny,allow
  Deny from All
  #Allow from 127.0.0.1
  #Allow from 192.168.1.*
</Location>

apparently i was missing the ServerAlias * line

-------------------------------------------------------------------------------------------

dbsa@dbsa-X406UA:~$ ssh root@172.16.10.82
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-91-generic x86_64)

* Documentation:  https://help.ubuntu.com
* Management:     https://landscape.canonical.com
* Support:        https://ubuntu.com/advantage
root@ubuntu:~# vi /var/log/cups/error_log

E [02/Nov/2020:08:03:28 +0000] [Client 5] Request from "172.16.13.20" using invalid Host: field "printer-cups.yogya.com".
root@ubuntu:~# vi /etc/cups/cupsd.conf

#
# Configuration file for the CUPS scheduler.  See "man cupsd.conf" for a
# complete description of this file.
#

# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn
PageLogFormat

# Deactivate CUPS' internal logrotating, as we provide a better one, especially
# LogLevel debug2 gets usable now
MaxLogSize 0

ServerName printer-cups.yogya.com
ServerAlias *
# Only listen for connections from the local machine.
# Listen 172.16.10.82:631
Listen *:631
Listen /run/cups/cups.sock



Tidak ada komentar:

Posting Komentar