How to configure ports on Vagrant and ruby-debug-ide - ruby

I’m trying to configure debugger for my web application, but I run into trouble with specifying correct ports for it.
Vagrantfile:
config.vm.network :private_network, ip: "192.168.68.8"
config.vm.network :forwarded_port, guest: 80, host: 8080
/etc/hosts (on my host machine)
192.168.68.8 mysite.com
I installed these two gems for debugging
gem 'ruby-debug-ide', group: [:development,:test]
gem 'debase', group: [:development,:test]
I read that in order to use ruby-debug-ide on vagrant, I should run
rdebug-ide --host 0.0.0.0 --port 80 --dispatcher-port 8080 -- bin/rails s
where --port should be guest port from Vagrantfile and host port for `--dispatcher-port``
But it says
Permission denied - bind(2) for "0.0.0.0" port 80
On the other side, if I try to change those ports in Vagrantfile, I lose the opportunity to reach my application from 127.0.0.1:specified_port, but still can do it from mysite.com, which is confusing

you already have something listening on port 80 (apache or nginx) so you cant bind on this port. You can do one of the following
start rails on another port like 3000
in your vagrant start rdebug-ide --host 0.0.0.0 --port 3000 --dispatcher-port 3000 -- bin/rails s
If you use a private network IP in your vagrantfile you dont need to forward port as you'll access your VM server using its own IP
check what is listening on port 80
run sudo netstat -nltp in your VM, check the process which binds the port 80 and kill it
For example
vagrant#precise32:/etc/init.d$ sudo netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 512/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1827/apache2
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 652/sshd
tcp 0 0 0.0.0.0:58397 0.0.0.0:* LISTEN 539/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 512/rpcbind
tcp6 0 0 :::22 :::* LISTEN 652/sshd
...
so you'll kill the apache2 process (PID 1827)

Related

How do I remove a forwarded port in Vagrant?

I downloaded a Vagrantfile and am running it on my CentOS 7 box. When I execute vagrant up, the process starts successfully and the machine is booted and ready. I'm able to access the process using the URL:
http://<IP_ADDRESS_OF_BOX>:8080
However, I don't want Vagrant to use port 8080 and would rather use an obscure port like 8601. So, I modified the Vagrantfile to include another entry for config.vm.network.
Before change - Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = 'ToraToraTora'
end
After change - Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = 'ToraToraTora'
config.vm.network "forwarded_port", guest: 80, host: 8601
end
Now I'm able to access the process using the new port:
http://<IP_ADDRESS_OF_BOX>:8601
However, the previous port continues to work too:
http://<IP_ADDRESS_OF_BOX>:8080
Executing sudo netstat -tulpn:
[ToraToraTora#andromeda ~]$ sudo netstat -tulpn | grep 26206
tcp 0 0 127.0.0.1:2222 0.0.0.0:* LISTEN 26206/VBoxHeadless
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 26206/VBoxHeadless
tcp 0 0 0.0.0.0:8601 0.0.0.0:* LISTEN 26206/VBoxHeadless
udp 0 0 0.0.0.0:40168 0.0.0.0:* 26206/VBoxHeadless
[ToraToraTora#andromeda ~]$
Output from running vagrant port:
[ToraToraTora#andromeda app]$ vagrant port
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)
80 (guest) => 8080 (host)
80 (guest) => 8601 (host)
[ToraToraTora#andromeda app]$
How do I stop the Vagrant process from using port 8080 and ONLY use port 8601?
You could explicitly disable the 8080 forwarded port...
Vagrant.configure(2) do |config|
config.vm.box = 'ToraToraTora'
config.vm.network "forwarded_port", guest: 80, host: 8601
config.vm.network "forwarded_port", guest: 80, host: 8080, disabled: true
end
If you make that change and do a vagrant reload, it will clear the 8080 forwarded port. At that point, you can remove the 8080 line from your Vagrantfile.
NOTE: Port forwarding in Vagrant can be compared to radio broadcasts. Guest ports are like radio stations while host ports are like radios. In the same way that a radio station can broadcast to any number of radios, a guest port on the Vagrant machine can be forwarded to multiple ports on the host machine. However, each host port can only receive forwarded traffic from one guest port at a time in the same way that a radio can only be tuned to one station at a time.
So in this case, two radios (ports 8601 and 8080 on the host) were tuned to the same station (port 80 on the guest). The solution was simply to switch off the radio at 8080.
if you are able to use http://<IP_ADDRESS_OF_BOX> it sounds to me you're using vagrant private network with a static IP, in such case, all ports are accessible on the IP and you do not necessarily need the forward_port option.
Also when netstat with your options run it with sudo netstat -tulpn so you'll find the PID/Program Name behind

cant use MAMP after laravel php artisan

Hi today i was able to run a laravel project of a client, was a big problem, i achieve that after a lot of tests doing a sudo
sudo php artisan serve --host=127.0.0.1 --port=80
After that I restart Apache and MAMP and MYsql and i thougth that everything was ok.... But i try to run MAMP after editing de virtualhost, and PDO is trying to work with ¿laravel project? wtf..
Im desperate, how can i reset ¿mysql?, ¿apache?, i try to reset both , apache at least can go into localhost , and i get yes it work
Pls someone help i have a lot of jobs to do in MAMP
How can i see if something of laravel is still running, how can i close it.
Hopefully I've understood your question correctly the below might help.
You can see what processes are running using the netstat command.
If you do netstat -tapn you should see something like
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 9046/php5
tcp 0 0 0.0.0.0:11300 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10231/nginx: worker
tcp 0 0 X.X.X.X:80 X.X.X.X:33801 TIME_WAIT -
tcp 0 0 X.X.X.X:80 X.X.X.X:44907 TIME_WAIT -
tcp 0 1012 X.X.X.X:22 X.X.X.X:61850 ESTABLISHED -
tcp 0 0 X.X.X.X:49308 X.X.X.X:443 TIME_WAIT -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::3306 :::* LISTEN -
tcp6 0 0 :::6379 :::* LISTEN -
my artisan is the second line down in this case running on port 8000 you can tell this by it being a php5 process. You can kill this by doing kill PID the PID in my case being 9046.
The reason your probably seeing problems in the first place is that depending on your MAMP configuration that probably runs on port 80 your then trying to run artisan serve also on port 80 instead run it on the default 8000 then you can have both running.

Cannot telnet to port 25 on EC2 instance

My security group has the following:
>22 (SSH) 0.0.0.0/0
>80 (HTTP) 0.0.0.0/0
>143 (IMAP) 0.0.0.0/0
>443 (HTTPS) 0.0.0.0/0
>995 (POP3S) 0.0.0.0/0
>465 (SMTPS) 0.0.0.0/0
>25 (SMTP) 0.0.0.0/0
Running a netstat on the server shows the following:
>Active Internet connections (servers and established)
>Proto Recv-Q Send-Q Local Address Foreign Address State
>tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
>tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
>tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
>tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN
>tcp 0 0 10.211.30.202:44025 194.14.0.125:6667 ESTABLISHED
>tcp6 0 0 :::995 :::* LISTEN
>tcp6 0 0 :::110 :::* LISTEN
>tcp6 0 0 :::143 :::* LISTEN
>tcp6 0 0 :::22 :::* LISTEN
>tcp6 0 0 :::25 :::* LISTEN
>tcp6 0 0 :::993 :::* LISTEN
And when I try and access the box from the outside world, I get nothing.
>thedude:~ root$ telnet mail.sd0a.com 25<br />
>Trying 107.20.235.215...<br />
>telnet: connect to address 107.20.235.215: Operation timed out<br />
>telnet: Unable to connect to remote host<br />
Anyone have any positive experiences with Amazon EC2 instances and getting mail to a state where it will work? Its worth noting that via command line, mail seems to go through. System is Ubuntu 12.04.1 LTS if that matters.
Might be your ISP filtering outbound connections to port 25/tcp in order to prevent botnet spam.
To eliminate the obvious: Have you tried
connect to another port other than 25?
connect to another new ec2 instance, port 25? (straightforward task to duplicate it on EC2)
connect from another machine (or your friend's PC) to sd0a.com:25?
traceroute to identify where the packets are dropped?
setup postfix on port 2525 (remember to add that into Security Groups)
ufw* on Ubuntu. (Default is off... but good to check)
As far as I can tell, all IP addresses on Amazon EC2 are blacklisted in spamhaus.com (and a lot of other anti-spam list). Hence most likely your ISP is blocking these packets, if so it is IP block or port block?

Binding memcached and beanstalk to external IP on an EC2 instance

I had a running EC2 server with an elastic IP address that was happily running memcached and beanstalkd listening on the external IP at port 11211 and 11300 respectively. I took a AMI of the server to upgrade the size and when the server restarted, neither memcached nor beanstalkd were running. Troubling for memcached as this was init.d to restart but beanstalkd was run as daemon from command line.
However, after several hours, I can't seem to figure out how to get them up and running again.
For memcached the config file reads:
# Default connection port is 11211
-p 11211
# Specify which IP address to listen on. The default is to listen on all IP addresses
-l <EXTERNAL IP ADDRESS>
When I try and run memcached as root from the command line:
memcached -d -m 1024 -u root -l <EXTERNAL IP ADDRESS> -v -p 11211
I get:
bind(): Cannot assign requested address
failed to listen on TCP port 11211: Cannot assign requested address
Yet when I look at netstat, nothing is bound to that port already:
netstat -ant | grep LIST
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
And if I grep the processlist, there is no other memcached running.
Iptables reports the following:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:11300 state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:11211 state ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
The EC2 instance is using the same security group as the original server, so the required ports are open.
Finally, maybe a hint is that the ifconfig IP address is different to the elastic IP address. If I try listening on either the inet adds: Bcast: the memcached service runs and binds however I can't seem to access memcached via the elastic IP.
I MUST be doing something stupid and obvious to you. Thanks for your help.
bind to 0.0.0.0 that should be public.

Unable to telnet on ec2 even when HTTPS /port 443 is open

Settings of my security group on EC2
TCP
Port(Service) Source Action
22 (SSH) 0.0.0.0/0 Delete
80 (HTTP) 0.0.0.0/0 Delete
443 (HTTPS) 0.0.0.0/0 Delete
Output: When I run the telnet
JP$ telnet passionate4.net
Trying 50.18.159.124...
telnet: connect to address 50.18.159.124: Operation timed out
telnet: Unable to connect to remote host
on ubuntu ec2 server
ubuntu#ip-10-166-185-18:~$ sudo netstat -nup -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:68 0.0.0.0:* 400/dhclient3
Telnet uses port 23, you don't have it in your security group.
type this:
JP$ telnet passionat4.net 80
80, 443, 3389, or whatever port you're testing for.
Windows example:
C:/> telnet www.google.com 80

Resources