Skip to content

Instantly share code, notes, and snippets.

@digitaljhelms
Created September 9, 2013 20:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitaljhelms/6501232 to your computer and use it in GitHub Desktop.
Save digitaljhelms/6501232 to your computer and use it in GitHub Desktop.
Vagrant cannot forward the specified ports...

The issue:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Fixed port collision for 22 => 2222. Now on port 2200.
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 4000 is already in use
on the host machine.

To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 4000, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.

Find out what processes are listening (and on what port).

$ lsof -i | grep LISTEN
GoogleTal  537 jhelms   29u  IPv4 0xffffff801ac71fa0      0t0  TCP localhost:49231 (LISTEN)
GoogleTal  537 jhelms   33u  IPv4 0xffffff801b2c6a40      0t0  TCP localhost:49232 (LISTEN)
Adium      565 jhelms    8u  IPv4 0xffffff8014cd44e0      0t0  TCP *:5298 (LISTEN)
Adium      565 jhelms    9u  IPv4 0xffffff8014cd44e0      0t0  TCP *:5298 (LISTEN)
VBoxHeadl 1503 jhelms   29u  IPv4 0xffffff802577bfa0      0t0  TCP localhost:rockwell-csp2 (LISTEN)
VBoxHeadl 1503 jhelms   30u  IPv4 0xffffff8026296c20      0t0  TCP *:terabase (LISTEN)

If there is a process listed on port 4000, kill it. If there are any headless processes, kill those as well.

$ kill <pid>

The in the above example would be 1503 as that process is in a headless state.

@1AndrewR
Copy link

1AndrewR commented Mar 4, 2022

i've tried the listen command to see what is on that port but it says command not found

@amandaalexandre
Copy link

I tried this command, but had no output

@digitaljhelms
Copy link
Author

If you're missing the command you should install the binary for it and try again. If you're on Windows maybe try netstat -b instead? Not sure what else to say, the gist is accurate. 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment