OS/Linux

centos(linux) 네트워크 프린터로 출력

노루아부지 2021. 11. 26. 09:57

CentOS에서 network printer로 출력을 하는 방법 중, lpr 명령어를 사용하는 방법이 있습니다.

 

출력을 하려면 아래 절차대로 진행해야 합니다.

 

  1. cups install
    yum install -y cups​
  2. foomatic install
    이것을 설치하지 않을 경우 lpadmin 명령어로 프린터 등록 시도 시 "Unable to connect to server" 에러 발생
    yum install -y foomatic​
  3. cups 설정
    # vi /etc/cups/cupsd.conf
    
    ----
    
    # Listen localhost:631
    Listen *:631
    
    <Location />
      Order allow,deny
      Allow 192.168.0.0/24 #프린트 허용IP대역
    </Location>
    
    <Location /admin>
      Order allow,deny
      Allow 192.168.0.0/24 # 관리페이지 허용IP대역
    </Location>
    
    .
    .
    .
    . 
    
    :wq


  4. 방화벽 설정
    - 방화벽 설정
    # firewall-cmd --permanent --add-service=ipp
    # firewall-cmd --reload
    
    - 방화벽(서비스)확인
    # firewall-cmd --list-service​
  5. cups 서비스 등록 및 재시작
    # systemctl enable cups
    # systemctl start cups
    # systemctl status cups​
  6. 프린터 등록
    lpadmin -v ipp://192.168.0.85 -p hp​
  7. 프린터 활성화
    1. printing을 enable로 변경
      cupsenable hp​
    2. queuing을 enable로 변경
      cupsaccept 명령어를 사용하지 않으면 출력 시 lpr: Destination "hp2" is not accepting jobs. 에러 발생
      cupsaccept hp​
  8. 프린터 상태 확인
    lpstat -p
    또는
    lpc status​
  9. 출력
    lpr -P [프린터명] -E [파일경로]
    lpr -P hp -E /root/ff.pdf​

 

[추가] 프린터 등록 없이 네트워크 프린터 출력 방법

  1. cat /root/ff.pdf | nc -w 1 192.168.0.85 9100
  2. cat /root/ff.pdf > /dev/tcp/192.168.0.85/9100

위 두가지 방법 모두 가능.

하지만 java에서 위 명령 실행 불가.

위 명령어를 java로 실행 하려면 아래와 같이 shell 파일을 만들어서 그 파일을 java로 실행해야 함.

 

1) mybash.sh 파일 내용

#!/bin/sh
cat $1 | nc $2 9100
exit 0

 

2) java 실행 명령어

Runtime
   .getRuntime()
   .exec("./mybash.sh /root/ff.pdf 192.168.0.85");

 

 

[참고사이트]

https://superuser.com/questions/280396/how-to-resume-cups-printer-from-command-line

 

How to resume CUPS printer from command line?

I have printer in CUPS that due to driver problems (HP 1010) from time to time goes into pause. I would like to write a shell script that will execute once per hour to resume a printer in CUPS. B...

superuser.com

https://zosystem.tistory.com/196

 

CentOS 7 + CUPS + HPLIP = 인쇄서버

네트워크 모듈이 포함되어 있지 않은 프린터를 여러명이 사용하기 위해선 보통 윈도우 공유방법을 사용합니다. 특정 컴퓨터에 USB프린터를 설치하고 프린터를 공유하는 방식으로 사용합니다.

zosystem.tistory.com

 

728x90
loading