Installing and upgrading help

moodle link from Ip to Dns

 
Picture of Anderson Hsu
moodle link from Ip to Dns
 

Dear partners,

When we change ip to dns name, if we still connect ip address, it will show the message as shown as below: Would it be possible to make it invisible when user connect ip address? Thanks a lot.


 
Average of ratings: -
Picture of Matteo Scaramuccia
Re: moodle link from Ip to Dns
Core developersParticularly helpful MoodlersPlugin developers

Hello Anderson,
shortly: no, Moodle uses a unique point of access defined in the config.php file.

If you want your Moodle instance to be both accessible via FQDN and IP address you should add a rewrite rule on your web server to automatically move the IP address based requests into FQDN based ones so users will be wrong once when using IP address and Moodle will not complain about it being the user redirected to the proper "Moodle address".

HTH,
Matteo

 
Average of ratings: Useful (2)
Picture of Anderson Hsu
回應: Re: moodle link from Ip to Dns
 

Dear Matteo,

Is there rule example which we can refer it ? Thanks a lot.

 
Average of ratings: -
Picture of Matteo Scaramuccia
Re: moodle link from Ip to Dns
 
Average of ratings: Useful (1)
Picture of Anderson Hsu
回應: Re: moodle link from Ip to Dns
 

Dear Matteo,

Thanks for your kindly assistance. I use centos6.6 server+ apache . But I don't find the path of /var/www/example.com/public ( refer to the link of https://www.digitalocean.com/community/questions/redirect-ip-address-to-domain-name-apache?answer=19074 )

My screenshot is as shown as below:

path of /etc/httpd/


path of /var/www/ 


 
Average of ratings: -
Picture of Ken Task
Re: 回應: Re: moodle link from Ip to Dns
Particularly helpful Moodlers

Pardon intrusion ...

One cannot use FAQ's, Docs etc. from providers verbatim.
Especially if the Dig Ocean doc is showing CentOS 7 - NOT 6.

First, check to see if the Apache server has the rewrite module installed
and Loaded:

grep -i LoadModule /etc/httpd/conf/httpd.conf | grep rewrite

If that command returns nothing ... stop.

Your main config file in CentOS 6.x is in:
/etc/httpd/conf/
and is called httpd.conf

What's defined in there applies to anything apache.

I see by your screen shots that you have a 'moodle' directory at
/etc/httpd/

Am guessing that it contains a .conf files in there that pertains specifically
to the moodle.  So it's probably that config file where one needs to
use the Rewrite rules - if going that route for rewrites.

And that the moodle code actually resides in /var/www/html/

Also, a couple more things ....

6.6 is 3 Kernel updates behind .. highest/most secure version 6 is 6.9
Veryify please your version:

cat /etc/redhat-release

You might need to do a yum  check-update followed by a yum -y update to get up to date!


Now for the redirect ... IP to FQDN
There's another way .... .htaccess files IF mod_rewrite is loaded.
at the root of the code for moodle an .htaccess file ... note the 'dot' in front of the filename.

Below is example ... change IP address and FQDN below before using:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^12\.34\.56\.78$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
</IfModule>

Advantages to .htaccess ... supposedly, it's immediate ... requires no restart of apache server.   If one messes up an .htaccess file and don't have time to fix it, one can rename it ... mv .htaccess htaccess ... and it's no longer in affect ... again ... no restart of services.


One dis-advantage to .htaccess ... it's hierarchal ... meaning whatever .htaccess file
Apache server sees at the document root applies to all subdirectories, etc. below the root.

And a thought ... since you are doing this now ... future versions of Moodle check for https:// and recommend it.  
Might be a good time to consider moving site from http:// to https://

'spirit of sharing', Ken


 
Average of ratings: -
Picture of Anderson Hsu
回應: Re: 回應: Re: moodle link from Ip to Dns
 

Dear Ken, 

I try as shown as below at httpd.conf



But it got some error message, it can not start httpd service normally. What happen to it ? Thanks for your kindly assistance.


 
Average of ratings: -
Picture of Ken Task
Re: 回應: Re: 回應: Re: moodle link from Ip to Dns
Particularly helpful Moodlers

I had suggested you use an .htaccess file not the main config file for apache server (httpd.conf).

The .htaccess file to be located in the directory where your moodle code resides.

One of the reasons for .htaccess file was exactly the issue you have now ... if one uses httpd.conf file, changes to that *requires* restart of Apache service.   And if mis-configured, Apache won't launch.

.htaccess files *do not require* restart of the service.

This is a specific situation ... the redirect would only apply to/for the private IP 192.168.0.x of your server which can only be used to access the server while inside your  private network/LAN/WAN.  No one in the entire globe can access your server by 192.168.0.x ... they *must* use the FQDN (if they try the public IP address, they will see the Moodle screen that tells them the can only access via FQDN.

Using .htaccess file and attempting to access the moodle by http://192.168.0.x/ might fail if the file isn't right but server still up and accessible by FQDN.

Your host IP isn't 12.34.56.78 inside your LAN/WAN ... what I shared wasn't meant to be copied and pasted - it was an example for you to edit/change the IP address, etc.  Your server's IP address is whatever 192.168.9.x IP address you asked about in your first posting.

So ... remove those lines from httpd.conf.   Restart apache so moodle is up.

And **in the code directory for moodle**, create an .htaccess file with the same lines *and* the correct IP address.

The Rewrite base rule should then apply to the code directory (moodle) where the .htaccess file is located.

Now there is no reason to restart your apache service at all.  Apache looks for .htaccess files on every browser request and if it finds an .htaccess file (that's correct), it redirects the 192.168.0.x request to your FQDN.

Hope that clears it up. ;)

'spirit of sharing',Ken

 
Average of ratings: -
Picture of Anderson Hsu
回應: Re: 回應: Re: 回應: Re: moodle link from Ip to Dns
 

Dear Ken, 

Thanks for your kindly assistance.

http://chamilo.ft.ftg.com is fake address which I try in my lab moodle in the intranet. So we can not connect in the internet.

I try two way as shown as below:

 1. create /etc/apache2/sites-available/default , but it can not saved as shown as below


2. create .htaccess file as shown as below, Httpd service can run normally, but still can not use ip address to connect it.


 
Average of ratings: -
Picture of Ken Task
Re: 回應: Re: 回應: Re: 回應: Re: moodle link from Ip to Dns
Particularly helpful Moodlers

Ahhhhh ... the FQDN is internal only ... private network.

So from a workstation, using whatever tool you have to DNS, what would be returned to the workstation if one queried DNS for chamilo.ft.ftg.com?   That should respond with the 192.168.8.200 IP address you show in the first posting of this thread.

First screen shot ... have asked for this before, will ask again ... originally you stated that you were running CentOS 6.3.

Please verify with command: cat /etc/redhat-release

On a CentOS 6 server, apache not setup like it is on a CentOS 7 server.  In a 6, it's not Linux Standards Based and thus in config of Apache there aren't any defaults like /etc/apache2/sites-available/default which in 7 is really an alias (not a file).

Don't follow faqs/etc. that were made for CentOS 7 .... they will not work.

The .htaccess file you created will re-direct any attempted access to 10.10.10.200 to the 'fake' FQDN as it should.

Moodle itself is restricted to access by either IP address OR FQDN ... the config.php file's wwwroot line ... *** but not both *** IP or FQDN.

$CFG->wwwroot = 'http://IP OR FQDN ... ****but not both****.

First posting, https://moodle.org/mod/forum/discuss.php?d=369139#p1488350, you showed a 192.168.8.200 IP address in the screen that Moodle shows you.  That IP should be used in the .htaccess file ... not the 10. IP you show in 2nd screen shot.

Moodle is not using 'relative addressing' for apache setup ... everything any one does in moodle involving internal links to the moodle ** will use ** the wwwroot variable and **record in the database**  the URL's to whatever resource in moodle as:

$CFG->wwwroot /blah/blah/etc.

This is really something that involves internal training of users ... don't use IP ... use the FQDN.  The FQDN should be easier (in theory) to remember.   When was the last time you used an IP address for moodle.org forums here for example.

There is one other thing you can do to help users/remind users to use FQDN ... edit the language files that displays in that yellow information/notice and add a URL to what it says .... something like:

<a href="http://chamilo.ft.ftg.com">Click Here</a> ... in your language, of course.

That way, if they use the IP, they will still get the yellow info screen, but now there will be a clickable link for them to get to the site by the FQDN.

This assumes that the host chamilo.ft.ftg.com *IS* in internal DNS and resolves to the 192.168.8.200 IP address.

From a Windows workstation, go to command prompt, and type:

nslookup chamilo.ft.ftg.com

If that doesn't respond with the 192.168.8.200 IP address, but rather the outside DNS IP then you have an internal DNS issue.

'spirit of sharing', Ken

BTW, when it comes to internal setups like yours, sharing facts like ... 'internal only' ... is very important for those trying to help.


 
Average of ratings: Useful (1)
Picture of Anderson Hsu
回應: Re: 回應: Re: 回應: Re: 回應: Re: moodle link from Ip to Dns
 

Dear Ken, 

Thanks for your kindly assistance.

Actually my main purpose is to make ip and dns name can work , and now dns can work in my lab environment. But when we connect Ip address, it will show a message and then redirect dns name. I would like to make the message invisible. Is it possible to make the message invisible ?

I manually add a record in my computer host file as shown as below:


setting as shown as below:

10.10.10.200 chamilo.ft.ftg.com


So I can connect http://chamilo.ft.ftg.com in my lab environment.

Additional information: Sometimes I change ip to 192.168.8.200, it's another lab environment.

 
Average of ratings: -
Picture of Ken Task
Re: 回應: Re: 回應: Re: 回應: Re: 回應: Re: moodle link from Ip to Dns
Particularly helpful Moodlers

So your internal private IP network 10. or 192.168.x.x doesn't have an internal DNS server?

And you are using either the host file or lmhost.sam file to associate IP to DN (note that's NOT a fully qualified DN)? - that's NOT DNS so all workstations would have to use the same setup ... wouldn't they?  Meaning one has to touch each workstation to change that!!!!

And why in the world do you change IP address of the server for Moodle?   Different lab environment or no, the 10. network and the 192.168.x.x network are still in the same private IP WAN ... switches in such a network should allow a 10. machine to see machines in 192.168.x.x unless network folks have segmented them and restricted access to only workstations within the same IP blocks.

Solution to your problem ... an internal DNS server with entries for chamilo.ft.ftg.com that point to the IP.

Can't suggest any 'workaround'  so this is my final response ... again:

Solution to your problem ... an internal DNS server with entries for chamilo.ft.ftg.com that point to the IP.

Moodle configured to use the DN of chamilo.ft.ftg.com

Maybe someone else has a very guruish network way to accomplish what you desire ... but, not me!

'spirit of sharing', Ken


 
Average of ratings: -