Results 1 to 4 of 4

Thread: Http hosted website cannot be accessed via hostname (only by IP)

  1. #1
    Join Date
    Feb 2022

    Question Http hosted website cannot be accessed via hostname (only by IP)

    Hi, I have a website which can only be accessed by the devices in my LAN. For some reason the website can only be accessed through the IP (not public facing ip address) but if I try with the hostname I get connection refused. I have DHCP enabled so that my devices leases IPs to the connected devices. I have checked that the port is open and listening. My /etc/dnsmasq.conf has the following config:

    dchp-range= least ip, highest ip, mask, 24h
    and /etc/hosts/ has (for IPv4) the following configuration:

    Code: localhost
    domain-IP domain-name
    Does anyone know why the resolve process is not working for my ip address? I would really appreciate your help.

  2. #2
    Join Date
    Mar 2010

    Re: Http hosted website cannot be accessed via hostname (only by IP)

    For every system, the /etc/hosts file needs to have the IP NAME you want to use.
    There needs to be a DNS server running and the clients need to point at that DNS server in their network configurations AND that needs to be reflected in each client's /etc/resolv.conf file. dnsmasq can do that, but I don't think it is configured the way you show. My dnsmasq setups (primary and failover) have a host table that gets used for DNS.
    use avahi on all the systems which implements mDNS. In that case, each computer announces itself on the network. The names for avahi are "{hostname}.local" - and all the systems need to run avahi/zeroconf/Bonjour <--- these are all the same service, just different OSes call them different things.

    To be clear with examples.
    # domain-IP FQDN, not just domainname.
    #    hostname       hostname.domain.lan    regulus       regulus.canonical.lan

    FQDN is the hostname+domainname. And the domainname is the DNS domainname, not some other domain ... there are lots of other sorts of domains in computing, all the others are completely unrelated.

    I almost forgot, while you shouldn't need to touch it, the /etc/nsswitch.conf controls the order that name lookups happen.
    # hosts:          files mdns4_minimal [NOTFOUND=return] dns mymachines   # this is the original line
    hosts:          files dns   # is the line I modified to prevent Avahi from being used.
    If you want mdns to be used, the original line is better.
    Last edited by TheFu; January 31st, 2024 at 05:38 PM.

  3. #3
    Join Date
    Nov 2008
    Boston MetroWest

    Re: Http hosted website cannot be accessed via hostname (only by IP)

    The quickest solution is to set up a local DNS server and push it to all the clients via DHCP. Or you can manually edit /etc/hosts on every machine including Windows machines where it lives as C:\Windows\System32\Drivers\etc\hosts. That's a lot more tedious work than using DNS.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  4. #4
    Join Date
    Jan 2024

    Re: Http hosted website cannot be accessed via hostname (only by IP)

    What is the HTTP server config (and which HTTP server are you using)? Some, such as apache2, can be configured via a VirtualHost directive to respond to only specific hostnames or IP addresses.

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts