-1

I’m using Vagrant 2.2.18 on Mac and creating a local Ubuntu 14.04 virtual machine. I want to expose port 1234 in my VM, so I have configured this

  config.vm.define "dev" do |dev|
    dev.vm.hostname = 'dev'
    dev.vm.network 'forwarded_port', guest: 1234, host: 1234
    dev.vm.network 'forwarded_port', guest: 3306, host: 3306
    dev.vm.network 'forwarded_port', guest: 3000, host: 3000
    dev.vm.network 'forwarded_port', guest: 3500, host: 3500
    dev.vm.network 'forwarded_port', guest: 4444, host: 4444
    dev.vm.network 'forwarded_port', guest: 8080, host: 8080

When I start up my virtual machine, I see this reported

$ vagrant reload
…
==> dev: Preparing network interfaces based on configuration...
    dev: Adapter 1: nat
    dev: Adapter 2: host-only
==> dev: Forwarding ports...
    dev: 1234 (guest) => 1234 (host) (adapter 1)
    dev: 3306 (guest) => 3306 (host) (adapter 1)
    dev: 3000 (guest) => 3000 (host) (adapter 1)
    dev: 3500 (guest) => 3500 (host) (adapter 1)
    dev: 4444 (guest) => 4444 (host) (adapter 1)
    dev: 8080 (guest) => 8080 (host) (adapter 1)

And when I am within my VM, I can connect to my “1234” port via telnet

myusername@dev:/var/$ telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

But from outside my VM, I don’t seem to be able to connect to that port

$ telnet localhost 1234
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

When I run “vagrant port dev” it reveals this

$ vagrant port dev
The forwarded ports for the machine are listed below. Please note that
these values may differ from values configured in the Vagrantfile if the
provider supports automatic port collision detection and resolution.

    22 (guest) => 2222 (host)
  1234 (guest) => 1234 (host)
  3000 (guest) => 3000 (host)
  3306 (guest) => 3306 (host)
  3500 (guest) => 3500 (host)
  4444 (guest) => 4444 (host)
  8080 (guest) => 8080 (host)

So I’m confused about what other configurations I need to do to allow a connection to port 1234 from outside my virtual machine.

Dave
  • 15,639
  • 133
  • 442
  • 830
  • Questions about operating systems, their utilities, networking and hardware, are off topic here. [What topics can I ask about here?](https://stackoverflow.com/help/on-topic). Please delete this and ask, instead, on [Unix & Linux Stack Exchange](https://unix.stackexchange.com/) or, in this case, https://askubuntu.com/ – Rob Oct 14 '21 at 09:31

1 Answers1

0

Uncomplicated Firewall

Did you try checking the firewall, you can try installing the ufw package. Usually the firewall seems to be the culprit. You could try installing.

sudo apt install ufw

Then expose the port you want.

ufw allow 1234
SeekNDstroy
  • 302
  • 2
  • 6