How to access service which is listening on the private IP range within Vagrant from the host?

by Pritzl   Last Updated July 21, 2019 08:00 AM - source

I have a Vagrant VM which is running Ubuntu 18.04/Bionic. In this VM, there is a DNS server (systemd resolve in this case) running. This can be seen here:

[email protected]:~$ netstat -peanut | grep :53
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
udp        0      0 *                           101        15442      -                   

As you see, the DNS server is bound on UDP. My goal is to use this DNS server (for certain hosts, this is quite easy to configure in dnsmasq) on the host.

Here, is within the private IP range (being, so the following Vagrant portforwarding rule will not work: "forwarded_port", guest: 53, host: 8125, protocol: "udp"

I know the default approach to fix this is by binding the DNS service to, instead of, but I am not (yet) able to find in the documentation how to do that. Maybe this is a bad idea as well?

So, for the scope of this question, I would like to assume that this is not possible and start from the pre-condition that the service is listening on the private IP range.

My question then is: which approaches can we apply to make the forwarding happen?

I found one approach, which I'll explain below, but I am wondering if there are more. Maybe some iptables trickery?


With socat, we can create a local tunnel from 8125 to 53 in the guest:

socat -T10 UDP4-LISTEN:8125,fork,reuseaddr UDP4:

Then, in Vagrantfile, we can do: "forwarded_port", guest: 8125, host: 8125, protocol: "udp"

This works, but introduces a (probably small) performance overhead.

Related Questions

socat udp packet forwarding with source address

Updated June 10, 2015 15:00 PM