在 Fedora 17 建立虛擬 PDF 列印機,透過 CUPS 共享給 VirtualBox 虛擬機 (Windows XP) 使用,實現跨平台無實體印表機的文件輸出。
yum install -y cups cups-pdf tunctl
systemctl enable --now cups
https://localhost:631
# /etc/sysctl.conf
net.ipv4.ip_forward = 1
# /etc/rc.d/rc.local (需可執行權限 +x)
#!/bin/bash
tunctl -t tap0
ifconfig tap0 10.0.2.2 netmask 255.255.255.0 up
# 假設實體網卡為 p35p1 (ip link 查看)
iptables -t nat -A POSTROUTING -o p35p1 -s 10.0.2.0/24 -j MASQUERADE
重啟宿主機使 rc.local 生效。
tap010.0.2.x (x>2)、掩碼 255.255.255.0、閘道 10.0.2.2https://10.0.2.2:631 確認 CUPS 網頁可達Printers → cups-pdf → 複製該 URL (如 https://10.0.2.2:631/printers/cups-pdf)
# 宿主機輸出目錄
/var/spool/cups-pdf/ANONYMOUS/
# Samba 共享給虛擬機存取
# /etc/samba/smb.conf
[pdf-output]
path = /var/spool/cups-pdf/ANONYMOUS
browseable = yes
read only = yes
guest ok = yes
虛擬機對應網路磁碟機即可直接取得 PDF 檔案。
Out ${HOME}/PDFs # 變更輸出目錄 (預設 /var/spool/cups-pdf/${USER})
Label 1 # 在 PDF 加入標籤資訊
TitlePref 1 # 使用文件標題作為檔名
lp -d cups-pdf /etc/passwd → 檢查輸出目錄setsebool -P cups_pdf_write 1 允許 cups-pdf 寫入家目錄此架構適用於「Linux 宿主機 + Windows 虛擬機」無實體印表機環境,亦可延伸為網路列印伺服器服務多台虛擬機/實體機。