Moodle displays server IP instead of domain name

Moodle displays server IP instead of domain name

by Pals Pally -
Number of replies: 17

I have redirected my domain to my moodle server IP, it works, but after it loads the site, its displays the IP in the address bar instead of domain. How can i change that?

Average of ratings: -
In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Ken Task -
Picture of Particularly helpful Moodlers

When you say 'redirect' is that apache redirect?

What do you get for responses to dig -x IP_ADDRESS_OF_YOUR_SERVER

and dig FQDN of your server?   Remember if you do those commands on your server it reads /etc/hosts file first.

If those respond as they should, then check your config.php file - wwwroot variable.   Change it from IP to FQDN.    Then login, go to /admin/tool/replace/ and search and replace for http://IP/ to http://FQDN/

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Moodle displays server IP instead of domain name

by Pals Pally -

Thank you for your replay, it doesnt really redirect, sorry for that, it simply displays IP instead of domain when site is loaded.

Can you please explain

Then login, go to /admin/tool/replace/ and search and replace for http://IP/ to http://FQDN/


a bit more, what do you mean by this? What is that?

In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by James Steerpike -
Picture of Particularly helpful Moodlers
Instructions are here. https://docs.moodle.org/33/en/Search_and_replace_tool

I had the same annoying problem. It advises a database back up first.

In reply to James Steerpike

Re: Moodle displays server IP instead of domain name

by Pals Pally -

Ok, so i "Search whole database for" http://IP/ and "Replace with this string" http://FQDN/?


Do i place my current IP in /IP/ and my new domain in /FQDN/?



And this action has a potential to break my site? ))

In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Ken Task -
Picture of Particularly helpful Moodlers

As with anything, before you begin, make a backup of the database.

Yes, anything like this does have the potential to break the site, however ...

depending upon just how much was developed under IP address, the search and replace util provided has been accurate and did as advertised (it's been my experience).

IF you are asking if /IP/ replace /FQDN/ will work ... am gonna guess that it would.   I, however, use search for 'http://ip/' replace with 'http://FQDN/' because it includes the protocol as that's at the very beginning of any url.

Now if you are nervous about it (it's ok to be), another way to do the same thing:

1. do a db dump to an .sql file.

2. in a text editor on the server ... I use nano ... load up the .sql dump file.

3. use nano's built in search and replace .... this will show you one at a time and allows you to say yes/no or you can have it do them all.

Once the nano search/replace has been completed, you've saved the file, and before you import into a *new* database with the right character set/collation, one can do a quick command line search of that file:

fgrep 'http://IPADDRESS/' nameofdump.sql

Finds none then good.

Paranoid mode:

fgrep 'http://FQDN/' nameofdump.sql

Should show all the references in the .sql file.

Import sql as new DB.

Then edit config.php of the site to use the newly imported DB.

'spirit of sharing', Ken


In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by James Steerpike -
Picture of Particularly helpful Moodlers
FQDN is your fully qualified domain name - something like mygreatschool.com
So " http://mygreatschool.com/ replaces " http://10.0/0.1/"
Average of ratings: Useful (1)
In reply to James Steerpike

Re: Moodle displays server IP instead of domain name

by Pals Pally -

but if i use something like a subdomain, for example moodle.mygreatschool.com, will it work too?

In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Ken Task -
Picture of Particularly helpful Moodlers

Yes.

We are still talking your moodle and not DNS, right?

So what do you get from DNS when using: dig -x IP_address_of_server   Where IP_address_of_server is both the private IP or the public IP of server?

Does dig return a fully qualified domain name?

What does (as per your example): dig moodle.mygreatschool.com return for a response?

'spirit of sharing', Ken


In reply to Ken Task

Re: Moodle displays server IP instead of domain name

by Pals Pally -

 get this with dig, 


 DiG 9.10.3-P4-Ubuntu <<>> http://moodle.mydomain.lv/

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 65353

;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 512

;; QUESTION SECTION:

;http://moodle.mydomain.lv/.   IN      A


;; AUTHORITY SECTION:

.                       86397   IN      SOA     a.root-servers.net. nstld.verisign-grs.com. 2017101000 1800 900 604800 86400


;; Query time: 19 msec

;; SERVER: 8.8.8.8#53(8.8.8.8)

;; WHEN: Tue Oct 10 16:41:37 EEST 2017

;; MSG SIZE  rcvd: 131


In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Ken Task -
Picture of Particularly helpful Moodlers

Issue all dig commands *without* the protocol ... http://

like:

dig moodle.mydomain.lv

'spirit of sharing', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Moodle displays server IP instead of domain name

by Pals Pally -

I did as you asked and got this:


; <<>> DiG 9.10.3-P4-Ubuntu <<>> moodle.mydomain.lv

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43712

;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 512

;; QUESTION SECTION:

;moodle.mydomain.lv.           IN      A


;; ANSWER SECTION:

moodle.mydomain.lv.    874     IN      A       myip.myip.myip.myip


;; Query time: 19 msec

;; SERVER: 8.8.8.8#53(8.8.8.8)

;; WHEN: Wed Oct 11 14:15:19 EEST 2017

;; MSG SIZE  rcvd: 64


In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Ken Task -
Picture of Particularly helpful Moodlers

Very good.  It shows that your server's FQDN (moodle.mydomain.lv) is known to outside DNS (the 8.8.8.8 is Google's DNS resolver).   Now if your server is hosted on a private network that has a private network internal DNS then see if your server has those internal DNS servers in it's config.   Assuming a linux here ...

cat /etc/resolv.conf

on most linuxes would/should show what internal DNS servers your moodle server is using for DNS.

The workstations on that private network are configured to use the same internal DNS servers for their first DNS servers.   Do the same command but point it to the private IP address server via: dig @PRIVATEIPDNSSERVER moodle.mydomain.lv and see if you get the servers private IP in the response or if it gets the public IP.

What that means to moodle config .... config.php uses moodle.mydomain.lv in the $CFG->wwwroot line.

IF your private net doesn't have an internal DNS server, it will mean that any browser attempting to access your internal moodle, would be routed (because of the DNS response to the outside IP) to your net's boundary and then back inside again - looping.

The bottom line is $CFG->wwwroot line must be the FQDN that is resolvable to other computers both inside the private net an to the rest of internet.

There is also (if using Apache) a line in it's config file related to the FQDN of the server.  IF running apache, that line has a comment.   See the section on ServerName.

Once you know that the DNS is resolving your Moodle servers FQDN correctly AND you've made changed to config.php to reflect the FQDN, *IF* you have done any development in the Moodle, it has recorded in the DB of the ste the IP address.   To correct that, you need to run the admin search/replace tool (search for http://ip/ replace with (as per your example) http://moodle.mydomain.lv/

Goes to lllustrate that networking comes before application (web server/moodle) ... a fact/concept to remember when working with web servers as well as trouble shooting things in general.

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Moodle displays server IP instead of domain name

by Pals Pally -

Thank you for your assistance Ken and everyone else! Il do a database backup and will do a replace, will post if/when change will be successful.

In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Pals Pally -
sorry for long delay, did replace as you asked, but nothing changed, it still shows IP address instead of domain name, is there anything else i can do?
In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Ken Task -
Picture of Particularly helpful Moodlers

What's in your config.php file for wwwroot?

That variable has to match how DNS shows the FQDN of the Moodle.

The only other place I can think of would be in config of apache (if that's what you are running).    And added to that if you are running virtual apaches or not.

Clips from a CentOS 7 config using mod.  The # lines are comments/commented out:

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80

Then there is the vhost.conf for virtual apache host.  A clip:

<VirtualHost *:80>
ServerAdmin root@emoodle.somenet.net   
ServerName moodle.somenet.net
ServerAlias moodle.somenet.net
DirectoryIndex index.html index.php
DocumentRoot /home/moodle/html
<Directory "/home/moodle/html/">

.... more to this file, but enough here for an idea.

When running virtual apaches, DNS is highly involved.

'spirit of sharing', Ken


Average of ratings: Useful (1)
In reply to Ken Task

Re: Moodle displays server IP instead of domain name

by Pals Pally -
I solved the problem! It seems that i also had to replace my IP addresses in config.php in moodle root, for some reason my editor did not save string changed in of wwwroot, and i reuploded file unchanged.


Now everything is working as it should and i get my domain displayed, thank you all for your assistance!

Average of ratings: Useful (1)
In reply to Pals Pally

Re: Moodle displays server IP instead of domain name

by Ken Task -
Picture of Particularly helpful Moodlers

Glad to hear it! Congrats!

For those who might find this thread ... if you know for a fact that the moodle you are about to setup will be used then begin with DNS settings for the server upon which Moodle will be installed.  It makes it so much easier to install moodle with a fully qualfied domain name from the git go ... notice the term 'git'. ;)   All the content one is developing can be hidden until one is ready to take on students.  Using FQDN from the start means one won't have to change config.php nor run search/replace. ;)

Anyhoo ... again ... Congrats!

'spirit of sharing', Ken