How can I create a custom TLD (for an Intranet) on my Wi-Fi network with a Windows computer and Apache?

399

Solution 1

It all hinges on DNS. You have to make sure that the DNS name intranet gets resolved to an IP address. I know how to do this only one way: installing my own DHCP and DNS service for the infrastructure. Bonjour-style should work as well, but I have no experience doing it that way.

The operating systems I know of support DNS suffixes, like .local or example.corp. You'll control the DHCP server on your network, correct? Lets assume it will give out addresses like 192.168.13.128, with a 255.255.255.0 network mask and most importantly, it will give out the address of a DNS server that knows how to answer authoritatively over the example.corp zone and it will say to the DHCP clients that their DNS domain is example.corp. Most operating systems will then try to access http://intranet.example.corp if you type http://intranet.

This is how the short-names will work. Onwards to name-based virtual-hosting, like @Iain said. Let's assume your Apache's configuration says:

Listen *:80
NameVirtualHost *:80

I'll assume the Apache server has the 192.168.13.1/24 IP address. I'd put an A record like s01.srv.example.corp. pointing at 192.168.13.1 and a CNAME like intranet.example.corp. pointing at s01.srv.example.corp. and if you need sub-sites I'd put in site.intranet.example.corp. as well, pointing at the full s01.srv DNS name.

Back to the Apache configuration: you'll need to add virtual-hosts like these:

# this matches the NameVirtualHost directive and
# loosely matches the Listen directive; it could also be:
# NameVirtualHost 192.168.13.1:80 and you'd change this below as well
<VirtualHost *:80>
    # notice you'll need both of these;
    # they must match what's in the browser Location bar
    ServerName intranet.example.corp
    ServerAlias intranet

    # sorry for the Unix-style paths, I avoid Windows a bit
    DocumentRoot /var/www/intranet.example.corp
</VirtualHost>

I don't mind expanding on this, if you need help. Please feel free to ask!

Solution 2

The technology you are after is name-based virtual hosting. You would typically configure your DNS server with an A or CNAME record that for each domain/subdomain that you want to serve that points to the address of your apache server.

You then use name-based virtual hosting to configure a vhost for each domain/subdomain.

Share:
399

Related videos on Youtube

Tomi Fodor
Author by

Tomi Fodor

Updated on September 18, 2022

Comments

  • Tomi Fodor
    Tomi Fodor over 1 year

    I have a lab assignment which needs me to use an Atmega328P to do an ADC, and with USART, transmit the digital value to a MILFORD-4X20-BKP LCD display. The LCD needs to display the value in a 2 byte format (decimal, 0-255) on the first line, and a word format (4 bytes, 0-1023) on the third line.

    I was successful in doing this, but because I was unsure of the array sizes, I initially had them all big enough to not have an issue. When I changed it to what I believe was necessary, I had a weird bug. It's the weird symbol shown below (or I guess at the bottom). The symbol in that position would depend on the potentiometer value.

    So here is my thinking. I allocated 36 (+1 for pos 0) positions to the buff, which was sent to the LCD. I allocated 3 to buff2 for the word value (4 n positions) and finally 4 for buff1 for the 2 bytes value (5 n positions)

    buff[36]; buff1[4]; buff2[3];
    

    3n positions for the word value works, but when I put 4n for the 2byte value, the bug appears. See the first picture.

    The bug also appears in the form of a portion of the 0-255 value appearing at the end of line 3, depending on different array values of buff and buff1. The second photo has buff[37], buff1[2], buff2[3]

    Last note, if I change the value to buff1[5], the bug disappears..but why? The array size for 2 bytes should be less than that for 4 bytes.

    The weird bug

    The LCD

    I'm doing my best at explaining my issue, but don't know if I'm clear enough. I know I am having my arrays cross over into one another's memory address, but I don't see how and where.

    /*
     * Serial Lcd.c
     * 
     * Use's a 4x20 serial LCD display.
     *
     * Adapted by Phil J to suit Atmega328P: 15/2/2015 (corrected Usart_Rx Int Vector address ref. for 328)
     *
     * Editted by Tomi Fodor
     *
     */ 
    
    #define F_CPU 16000000UL
    #define BAUDRATE 9600 - change to External 16MHz crystal on MCU
    
    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <util/delay.h>
    #include "stdlib.h"
    #include "USART.h"
    
    // Global Variables
    // Note the use of the volatile keyword to ensure that the compiler knows that these variables can be changed at 
    // any time, including by the ISR
    
    volatile int i=0; 
    volatile uint16_t buffer[]; // 20 place array
    volatile char buff[36];     // var sent out value
    volatile char buff1[4];     // var for the pot value / 4 ***** HAS TO BE AT LEAST 4 FOR SOME REASON (5 w/o bug), SHOULD BE FINE AT 2
    volatile char buff2[3];     // var for the actual pot value
    volatile uint16_t StrRxFlag=0;
    volatile int Ana, Bell;     // pot value
    
    int main(void)
    {
       buff[4]=' ';buff[5]='P';buff[6]='o';buff[7]='t';buff[8]=' ';buff[9]='V';buff[10]='a';buff[11]='l';buff[12]='(';buff[13]='D';buff[14]=')'; // constants to be displayed
       _delay_ms(500);
    
       ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1);    // Enables the ADC, sets the ADC to use the division factor 64 for the ADC clock 
       USART_interrupt_init();
       USART_putstring("Ready ");           // Send String to the LCD
    // USART_putstring(buff3);                  
       USART_send('\r');                // Send carriage return
    // USART_send('\n');                // Send linefeed
       _delay_ms(500);              // Allows for the LCD module to initialize
    
       while(1)
          {
         USART_send(254);       // LCD control mode
         USART_send(0);         // LCD HOME command
         USART_send(254);
         USART_send(1);         // LCD CLEAR SCREEN
         buff[0] = ' ';         // Required for offset of display
         buff[4] = ' ';         // Signifies terminator of pot
         ADCSRA |= (1<<ADSC);       // Starts A-D conversion
         while (ADCSRA & (1<<ADSC));    // Wait till A-D conversion is complete
         Ana = ADCW/4;          // Get A-D result
         Bell = ADCW;           // Get actual A-D result
         itoa(Ana,buff1,10);        // Creats the dec value of the Analogue value [stdlib.h]
         itoa(Bell,buff2,10);       // actual
    
         if (buff1[1] == '\0')      // If only 1 digit
            {
               buff[1] = ' ';       // Not hundreds
               buff[2] = ' ';       // Not tens
               buff[3] = buff1[0];  // Place in single digit
            }
         else if(buff1[2] == '\0')  // If only 2 digits
            {
               buff[1] = ' ';       // Not hundreds
               buff[2] = buff1[0];  // Shift
               buff[3] = buff1[1];  // Shift
            }
         else
            {
               buff[1] = buff1[0];  // Shift
               buff[2] = buff1[1];  // Shift
               buff[3] = buff1[2];  // Shift
            }
    
         for(i=0;i<25;i++)
            {
               buff[i+15] = ' ';
            }
    buff[25]=' ';buff[26]='P';buff[27]='o';buff[28]='t';buff[29]=' ';buff[31]='V';buff[32]='a';buff[33]='l';buff[34]='(';buff[35]='D';buff[36]=')'; // constants to be displayed
    
         if (buff2[1] == '\0')      // If only 1 digit
            {
               buff[21] = ' ';      // Not thousands
               buff[22] = ' ';      // Not hundreds
               buff[23] = ' ';      // Not tens
               buff[24] = buff2[0]; // Place in single digit
            }
         else if(buff2[2] == '\0')  // If only 2 digits
            {
               buff[21] = ' ';      // Not thousands
               buff[22] = ' ';      // Not hundreds
               buff[23] = buff2[0]; // Shift
               buff[24] = buff2[1]; // Shift
            }
         else if(buff2[3] == '\0')  // If only 3 digits
            {
               buff[21] = ' ';      // Not thousands
               buff[22] = buff2[0]; // Shift
               buff[23] = buff2[1]; // Shift
               buff[24] = buff2[2]; // Shift
            }
         else
            {
               buff[21] = buff2[0]; // Shift
               buff[22] = buff2[1]; // Shift
               buff[23] = buff2[2]; // Shift
               buff[24] = buff2[3]; // Shift
            }
    
              USART_putstring(buff);
              USART_send('\r'); 
             _delay_ms(500);
        }
    }
    
    //ISR(USART0_RX_vect) - not for 328
    ISR(USART_RX_vect)              //this is the right vector ref, not above
    {   
       buffer[i]=UDR0;              //Read USART data register
       if(buffer[i++]=='\r')            //check for carriage return terminator and increment buffer index
          { 
         // if terminator detected
         StrRxFlag=1;           //Set String received flag 
         buffer[i-1]=0x00;      //Set string terminator to 0x00
         i=0;               //Reset buffer index
          }
    }
    
    • MDMarra
      MDMarra about 12 years
      Really don't do this. "Custom" TLDs break enough RFCs that you should just buy the domain name that you want to use internally and use it. A few bucks a year isn't an overwhelming price.
    • ajmint
      ajmint about 12 years
      @MDMarra I have several domain names, but I want to do this as a hobby project, really.
    • Luis Bruno
      Luis Bruno about 12 years
      I mostly agree with @MDMarra so consider buying the example.com domain and serving a separate corp.example.com domain from DNS servers reachable only from "internal" addresses.
    • ajmint
      ajmint about 12 years
      @LuisBruno I could do that, but, as I said, I am mostly doing this as a hobby project.
    • Luis Bruno
      Luis Bruno about 12 years
      Sorry, didn't mean to preach to the choir. It's just too easy to go with the default example.local domain that I just wanted to get that out in the clear.
    • ryyker
      ryyker about 8 years
      Is the code shown in your post == to the code you compiled,ran and observed your bug?
    • Tomi Fodor
      Tomi Fodor about 8 years
      The main code I posted is the code I ran yes. It should be the same code that resulted in the issues first described, and shown in the first picture. I did repeat a part of the same code in my question which may have resulted in some confusion. (buff[36], buff1[4], buff2[3]).
  • ajmint
    ajmint about 12 years
    Would I need to set up the DNS on my router? How would I do that?
  • voretaq7
    voretaq7 over 11 years
    OpenNIC, like it's predecessor AlterNIC Breaks The Internet. As a site for professionals recommendations for things that Break The Internet are not really appropriate here.
  • Tomi Fodor
    Tomi Fodor about 8 years
    Sorry, I believe I included the tags, but didn't mention it in the question. It's WinAVR, on Proteus. TBH I am not sure the rules it follows. I thought that an undefined array would adopt the size it needs, but perhaps that's a foolish mistake. I learned programming from Arduino first. The Null character makes a lot of sense. I can't remember if the compiler will automatically add those to the string if I leave it blank, but I'll fix these tomorrow morning. The weird errors make more sense since all 3 arrays have this shortcoming, so I'll update asap. Thanks.
  • ryyker
    ryyker about 8 years
    @TomiFodor - No, an undefined array does not automatically adjust for size. However, this initialization method will work: char array[]={"string"}; Initialized like this, the string array will be terminated with a NULL automagically, and of course the size of the array will be 7, 6 for the visible characters and 1 for the NULL. Adding space for (and applying) the NULL in your strings will probably fix your stated issues.
  • Tomi Fodor
    Tomi Fodor about 8 years
    Ok so I did it and it gets rid of the bug, but here's the annoying thing. buff2, a value which seems to need an array of 5 elements, works perfectly fine with only 3. This doesn't seem to make any sense.
  • Tomi Fodor
    Tomi Fodor about 8 years
    volatile char buff2[3]; // var for the actual pot value and later on I do this: buff[24] = buff2[3]; // Shift ...but it works!? Even though buff2 only have 0,1 and 2 for its positions.. element 3 does not even exist.. let alone the '\0'
  • Tomi Fodor
    Tomi Fodor about 8 years
    Ok I think I get it. It still works because it's using memory somewhere after buff2. And it's still pointing to it properly. It's just that if I had another array, I'd have crossovers. Which was my issue before. Correct? I'll assume I'm correct. Thanks.
  • ryyker
    ryyker about 8 years
    Be careful with this. referencing a memory element that is not owned by the process (or a variable) may work at some times when the hijacked space is not needed at the moment by its owner. But at any time the owner of that space can write to it, changing the definition of the array.
  • ryyker
    ryyker about 8 years
    Yes, you beat me to the punch. I was writing the last comment when you posted yours.
  • Tomi Fodor
    Tomi Fodor about 8 years
    Yes, actually I just realized this is exactly what you said in the answer but I got my brain thinking about things all over the place. Thanks for making my first experience on stackoverflow so awesome!