Ubuntu – How to configure vboxweb to listen on specific adress on Ubuntu 16.04

16.04systemdvirtualbox

By default vboxweb.service is only listening on the ipv6 local address ::1. I need this service to listen on all ipv4 addresses so I can use the service remotely.

user@vboxhost:~$ netstat -nl |grep 18083 tcp6       0      0 ::1:18083
:::*                    LISTEN

Editing the /etc/default/virtualbox config file as per Virtualbox documentation (chapter 9.21.1) does not seem to work:

user@vboxhost:~$ cat /etc/default/virtualbox 
# Defaults for virtualbox initscript
# sourced by /etc/init.d/virtualbox
# installed at /etc/default/virtualbox by the maintainer scripts

#
# This is a POSIX shell fragment
#

# Set this to 1 if you would like the virtualbox modules to be loaded by
# the init script.
LOAD_VBOXDRV_MODULE=1

# SHUTDOWN_USERS="foo bar"  
#   check for running VMs of user 'foo' and user 'bar'
#   'all' checks for all active users
# SHUTDOWN=poweroff
# SHUTDOWN=acpibutton
# SHUTDOWN=savestate
#   select one of these shutdown methods for running VMs
#   acpibutton and savestate causes the init script to wait
#   30 seconds for the VMs to shutdown
SHUTDOWN_USERS=""
SHUTDOWN=poweroff

# Custom vboxweb config
VBOXWEB_USER=vbox
VBOXWEB_HOST=0.0.0.0
VBOXWEB_PORT=18083

No change after restarting the service:

user@vboxhost:~$ sudo systemctl restart vboxweb.service 
user@vboxhost:~$ netstat -nl |grep 18083
tcp6       0      0 ::1:18083               :::*                    LISTEN 

I've also tried to change the port via /etc/default/virtualbox, this also does not work.

Note: I edited the /lib/systemd/system/vboxweb.service startscript to pass the '–host 0.0.0.0' argument. this works, but I don think this is the right approach.

Best Answer

I think your change to /etc/init.d/virtualbox does not work because that is not sourced by systemd. Try this.

  1. Create a directory named `/etc/systemd/service/vboxweb.service.d
  2. In it, create a file named custom-host.conf.

The contents of the file would be:

[Service]
Environment=VBOXWEB_HOST=0.0.0.0

Then:

systemctl daemon-reload
systemctl restart vboxweb

Using these kinds of files is described at in man systemd.unit:

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix ".conf" from this directory will be parsed after the file itself is parsed. This is useful to alter or add configuration settings for a unit, without having to modify unit files. Each drop-in file must have appropriate section headers. Note that for instantiated units, this logic will first look for the instance ".d/" subdirectory and read its ".conf" files, followed by the template ".d/" subdirectory and the ".conf" files there. Also note that settings from the "[Install]" section are not honoured in drop-in unit files, and have no effect.

Setting environment variables is documented in man systemd.exec

Related Question