Cannot ping device IP (within local network) from dom0 script

For my automated minimal template script I want to pass this to my printer template:

...
lpadmin -p ${PRINTERNAME} -E -v ipp://${PRINTER_IP}/ipp/print -m everywhere
...

adapted to my dom0 script:

qvm-run --no-gui --pass-io --quiet --user root ${PRINTER_TPL} \
"lpadmin -p ${PRINTERNAME} -E -v ipp://${PRINTER_IP}/ipp/print -m everywhere"

I always get this dom0 error:

lpadmin: Unable to connect to "192. ...": Host is down

but when I launch the ${PRINTER_TPL} XTerm manually:

qvm-run --pass-io --user root ${PRINTER_TPL} xterm

and command the same:

lpadmin -p ${PRINTERNAME} -E -v ipp://${PRINTER_IP}[/ipp/print -m everywhere

it works.

To quickly reproduce the error a simple ping shows the same error.

qvm-run --pass-io --user root ${PRINTER_TPL} "ping -c 1 192.168...."

does not work.

And

qvm-run --pass-io --user root ${PRINTER_TPL} xterm

and command the same directly in the XTerm terminal:

ping -c 1 192.168....

works.

Could you please help me to fix this issue?

By default, templates don’t have networking. Did you add some network to your template?

I can’t reproduce your issue with the ping example, if I start an xterm in the template, which doesn’t have network, I obviously can’t ping anything.

Yes, I have installed qubes-core-agent-networking to my minimal Debian template.
But the Qube Settings Net qube is set to default (none).

[user@dom0 ~]$ qvm-run -p -u root xx "lpadmin -p myprinter -E -v ipp://192.168.1.42/ipp/print -m everywhere"

This works as expected and a newly created qube got the new myprinter device.
There is noting at 192.168.1.42, it’s just a random value.
My xx template doesn’t have network either and is fedora-38-minimal based.

Do you have this error when you only run lpadmin ?
I mean, not your script, just the single command.
i.e.

qvm-run --no-gui --pass-io --quiet --user root PRINTER_TPL \
"lpadmin -p printer -E -v ipp://192.168/ipp/print -m everywhere"

The ip doesn’t matter. It could be -v ipp://xxxxx/hello, the printer should be added anyway.

[user@dom0 ~]$ qvm-run -p -u root xx "ping -c 1 192.168.1.42"
ping: connect: Network is unreachable

You shouldn’t be able to ping anything in the xterm terminal if you don’t have any network assigned.
If I ping from dom0 with qvm-run or inside the template, the result are the same: I can’t.
As Solene mentioned it: it’s obvious as my template doesn’t have any network.

I would begin with that issue.

1 Like

Finally, I get the lpadmin configuration working with my automated script. :blush:

Now, I do the following: configure lpadmin in the < printer-appVM >

qvm-run --no-gui --pass-io --quiet --user user <printer-appVM>  \
"sudo lpadmin -p ${PRINTER_NAME} -E -v ipp://${PRINTER_IP}/ipp/print -m everywhere"

and afterwards (I would like to automated this):

# create /rw/config/qubes-bind-dirs.d/ directory
qvm-run --pass-io --user user <printer-appVM> \
"sudo mkdir --parents /rw/config/qubes-bind-dirs.d"
# make /rw/bind-dirs/ sub-directory for /etc/cups/ directory
qvm-run --pass-io --user user <printer-appVM> \
"sudo mkdir --parents /rw/bind-dirs/etc/cups/"
# copy entire contents of /etc/cups/ directory into the corresponding /rw/bind-dirs/etc/cups/ directory:
qvm-run --pass-io --user user <printer-appVM> \
"sudo cp --recursive /etc/cups/* /rw/bind-dirs/etc/cups/"
# create 50_user.conf file in /rw/config/qubes-bind-dirs.d/ directory and add the appropriate information for /etc/cups/ directory:
qvm-run --pass-io --user root <printer-appVM>  \
"sudo echo binds+=\( \'/etc/cups/\' \) > /rw/config/qubes-bind-dirs.d/50_user.conf"

Unfortunately, this does not work in the automated script. I need to open a user and a root Terminal and copy & paste the command lines manually:

as < printer-appVM > user:

sudo mkdir --parents /rw/config/qubes-bind-dirs.d
sudo mkdir --parents /rw/bind-dirs/etc/cups/
sudo cp --recursive /etc/cups/* /rw/bind-dirs/etc/cups/

as < printer-appVM > root:

echo binds+=\( \'/etc/cups/\' \) > /rw/config/qubes-bind-dirs.d/50_user.conf

So, my current implementation is to make a break in my script which allows me to do the above copy & paste operation manually and continue the automated script afterwards. I am wondering what is the difference between qvm-run --pass-io … and pass the command line vs. execute the command line directly in the terminal window. Is there an initialization of user files when opening the terminal the first time which does not happen with the qvm-run --pass-io command?

what’s failing in your current script when using qvm-run?