Adding 0.0.0.0 to /etc/hosts - ruby-on-rails

I see something like this in several Rails install guides. What exactly are we doing here?
Add default subdomain to /etc/hosts, for example:
"0.0.0.0 localhost.lan group1.localhost.lan group2.localhost.lan"

You could either bind a domain/subdomain to localhost 127.0.0.1 or 0.0.0.0 to have an address which you can use in your browser to access your app.
When a service is listening on 0.0.0.0 this means the service is listening on all the configured network interfaces, when listening on 127.0.0.1 the service is only bound to the loopback interface (only available on the local machine).
So "0.0.0.0 localhost.lan group1.localhost.lan group2.localhost.lan" means "Please make the domains localhost.lan, group1.localhost.lan and group2.localhost.lan browsable and point them to all my network adapters".

It means all the domains and its aliases will point to all the IP addresses assigned to this machine.
So If you machine has 3 IP NIC and IP is assigned to each one. Then that line will point all the names to all of those 3 IPs.

If you are developing an app which requires a valid subdomain, the rails guide talk about adding that subdomain to the hosts file. so that they can route that request to your localhost(127.0.0.1)
example:
127.0.0.1 sampleapp.heroku.com

Related

How can I access services via subdomain instead of ip + port?

I have a little server in my local network that provides several web services. Each service can be accessed by entering the ip of the server followed by the respective port.
Now I always have to remember which service is behind which port and it would be nicer to have specific subdomains forwarded to these ports. For example
ip:1234 -> foo.server.local
ip:4321 -> bar.server.local
How can this be done? I have pihole running on the server and had hoped to get this done using pihole but I was not successful.
What you are looking for is to set up a Domain Name Server (DNS). phoenixnap.com/kb/raspberry-pi-dns-server This guide should help.
You use a domain to direct to an IP:port combo. Like you could direct 123.12.12.12:8080 to some.thing and 123.12.12.12:8081 to any.address.
The domain name is arbitrary and masks the whole IP:port address.

How to change 0.0.0.0:8090 address to mastery.local in docker

I have a container called web, it contains my application and apache webserver. When I put to browser address 0.0.0.0:8090 i get my working application. But i need to change this address to mastery.local. How do I do that without using /etc/hosts file.
This can only be achieved via DNS resolution.
The simplest way would be to add this entry to the /etc/hosts.
As an alternative you could setup an dedicated DNS server on your machine which resolves this address to 0.0.0.0 and then configure your machine to use this DNS server.

Rails : ip addresses of subdomains

Say I usually make requests to my app using the local network ip address 192.168.1.26
I now have a new subdomain. How do I find the local network ip address of this new subdomain ?
With the Rails console or with a command line, either is good.
Add subdomain.example.com to your /etc/hosts file, pointing to the IP address.
example:
172.16.31.196 devwork subdomain.example.com
Then you can just type the subdomain.example.com in your url and you'll get what you want.

How do you host a Ruby on Rails application on a local network, so multiple people can access it?

I'm brand new to RoR and have pretty much 0 experience with it. I have been handed down somebody else's project and I need to find a way to host the application, so people can just access it locally. The application is a spider script/walker script/web scraper whatever you call it. Basically it connects to a website, logs in, retrieves certain data each day and maps it with the previous data. While on the local machine, you use it, go to localhost:3000, and you get the webpage the previous person designed. I was just wondering how I could get that page to be public for the people on our local network, so they could connect to some arbitrary IP and see the same page (it updates daily)?
What I tried doing is making the folder containing the application public to the network, but in order to use it, I would have to make everybody on the network allowed to write to it and each person would have to install RoR to use it. I want to avoid that since it doesn't seem logical, nor is it what I'm trying to do.
Looking at the code, I can reverse engineer and understand what it does, but when it comes to hosting web apps locally or something of that sort, I have never done this before. Please help!
Thanks in advance!
**EDIT
-This is all being done on a Windows 7 machine.
Since you're on Windows, open up a command line and run ipconfig to find out your local IP. It will be listed under 'IP Address'.
Tell people in your LAN to access http://192.168.x.x:3000 replacing 192.168.x.x by your IP address from step 1.
EDIT: One major thing that I missed, you are windows. On windows u could use thin and put it behind a load balancer. Although i would suggest hosting it on a UNIX machine :)
Although Running it in webrick(webrick is the application server for development i.e when u run rails s) will let other users access the website NEVER do the same for a production application. If you want to run this application in production, u need more powerful application servers like passenger. I would suggest you use it with Apache or Nginx instead of stand alone passenger. Once all this is setup others can use your application by entering the IP(xx.xx.xx.xx) also u can ask your system admin to setup a local DNS so your users need not remember the IP address always.
Description:
While starting Rails Server, we can also setup some options to configure the IP address and also the port number of the site under development environment to host the website in local network. So if we want to change the IP from http://127.0.0.1:3000 to http://192.168.x.x:port (x= 0 to 255 any one number), we can set that in Rails server command! But for this, we will need to find out our current IP address at our current network which will help us to serve the website in local network.
So at first step:
We will open our terminal on our PC. For Android user, we need to open Termux app. Then simply type ifconfig to get the IP address of our device in the current network. We will get an output like this one (Here I'm using Android device for development. So output might be something different than this one on your PC terminal but the process is same):
$ ifconfig
Warning: cannot open /proc/net/dev (Permission denied). Limited output.
lo: flags=XX<UP,LOOPBACK,RUNNING> mtu XXXXX
inet 127.0.0.1 netmask 255.XXX.XXX.XXX
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)
wlan0: flags=XXXX<UP,BROADCAST,RUNNING,MULTICAST> mtu XXXX
inet 192.168.1.103 netmask 255.XXX.XXX.XXX broadcast 192.168.1.255
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)
X= some numbers with our device credentials which is dummied with this variable
If you are using a WiFi router then we will need the wlan0 part to get our device IP. Under wlan0 section there is a subsection of inet showing our current IP! YUP, we need that IP address 192.168.1.103! This might be different for your device and network. This is the key of this mission! Now we're going to the second important step.
So the Second Step is:
That required input command to configure the IP address.
rails s -b 192.168.1.103 -p 8080
Here:
rails s for rails server
-b 192.168.1.103 for bidding the IP address for customisation from the default IP http://127.0.0.1 which is our localhost address.
-p 8080 for port setup. This part is optional. Default port is 3000.
This is the process of changing the localhost IP (http://127.0.0.1) to local network IP which will be available for other device of the same network user.
Now our rails app is available in our local network! Other users in the same network will also be able to visit the website while the server command is running. And the link will be http://192.168.1.103:8080 if you also configure the port number. Otherwise if you have used the command rails s -b 192.168.1.103 without port configuration the link will be: http://192.168.1.103:3000
Again: 192.168.1.103 was for my case, your IP address will be different for your device. That will be needed to use for your server and link address.

How to find Port number of IP address?

We can find out IP address of a domain name or URL. But how to find out Port number on which a domain name is hosted?
Unfortunately the standard DNS A-record (domain name to IP address)
used by web-browsers to locate web-servers does not include a port
number. Web-browsers use the URL protocol prefix (http://) to
determine the port number (http = 80, https = 443, ftp = 21, etc.)
unless the port number is specifically typed in the URL (for example
"http://www.simpledns.com:5000" = port 5000).
Can I specify a TCP/IP port number for my web-server in DNS? (Other than the standard port 80)
Quite an old question, but might be helpful to somebody in need.
If you know the url,
open the chrome browser,
open developer tools in chrome ,
Put the url in search bar and hit enter
look in network tab, you will see the ip and port both
DNS server usually have a standard of ports used. But if it's different, you could try nmap and do a port scan like so:
> nmap 127.0.0.1
The port is usually fixed, for DNS it's 53.
If it is a normal
then the port number is always 80
and may be written as http://www.somewhere.com:80
Though you don't need to specify it as :80 is the default of every web browser.
If the site chose to use something else then they are intending to hide from anything not sent by a "friendly" or linked to.
Those ones usually show with https
and their port number is unknown and decided by their admin.
If you choose to runn a port scanner trying every number nn from say 10000 to 30000 in https://something.somewhere.com:nn
Then your isp or their antivirus will probably notice and disconnect you.
Use of the netstat -a command will give you a list of connections to your system/server where you are executing the command.
For example it will display as below, where 35070 is the port number
TCP 10.144.0.159:**52121** sd-s-fgh:35070 ESTABLISHED
Port numbers are defined by convention. HTTP servers generally listen on port 80, ssh servers listen on 22. But there are no requirements that they do.
domain = self.env['ir.config_parameter'].get_param('web.base.url')
I got the hostname and port number using this.

Resources