Wildcard DNS for only first level subdomain - dns

I want to know how to set a wildcard DNS for only first level subdomain, example:
user.example.com // valid
www.user.example.com // invalid
I have my BIND zone domain configured like this:
; example.com
$TTL 86400
# IN SOA ns.example.com. domain.example.com. (
2014021001 ; Serial
28800 ; Refresh
1800 ; Retry
604800 ; Expire - 1 week
86400 ) ; Minimum
IN NS ns
IN NS ns1
ns IN A 1.2.3.4 ; An IP
ns1 IN A 1.2.3.4 ; An IP
# IN A 1.2.3.4 ; An IP
*.example.com IN A 1.2.3.4 ; An IP
www IN A 1.2.3.4 ; An IP
# IN TXT "v=spf1 a mx -all"
And my Apache virtual host config is like this:
<VirtualHost 1.2.3.4:80>
ServerAdmin domain#example.com
DocumentRoot /var/www/html/example.com
ServerAlias www.example.com
ServerName example.com
ErrorLog logs/example.com-error_log
CustomLog logs/example.com-access_log common
</VirtualHost>
<VirtualHost 1.2.3.4:80>
ServerAdmin domain#example.com
DocumentRoot /var/www/html/apps.example.com
ServerAlias *.example.com
ServerName apps.example.com
ErrorLog logs/apps.example.com-error_log
CustomLog logs/apps.example.com-access_log common
</VirtualHost>
Please help!

You can't do it in the DNS - a wildcard will match one or more DNS labels.
You may be able to do it in the Apache server, perhaps by using mod_rewrite to match on the supplied hostname and returning a 404 error if the hostname is invalid.

Related

Is it possible to have a wildcard CNAME Record and an MX Record?

Is it possible to have a wildcard CNAME Record and an MX Record? Would these conflict?
*.example.com CNAME example.com
example.com MX 1 aspmx.l.google.com
They won't conflict since they are not on the same name (*.example.com vs example.com), once you put things in proper zonefile format.
But you could even simply say:
*.example.com MX 1 aspmx.l.google.com
Of course this is only half of the story, as the host under the MX record must also be properly configured to receive emails coming from all subdomains.
You can easily check things like that using named-checkzone.
$ cat zone1
example.com. 1 IN SOA ns.icann.org. noc.dns.icann.org. (
2019112601 ; serial
7200 ; refresh (2 hours)
3600 ; retry (1 hour)
1209600 ; expire (2 weeks)
3600 ; minimum (1 hour)
)
example.com. 1 IN NS a.iana-servers.net.
example.com. 1 IN NS b.iana-servers.net.
*.example.com 1 CNAME example.com
example.com 1 MX 1 aspmx.l.google.com
$ named-checkzone -i none example.com zone1
zone example.com/IN: loaded serial 2019112601
OK

Replace patterns on file except one line in it

I am looking for a solution to replace one pattern on a file except one line in it.
For example:
zone file:
> cat /var/named/test.com.db
; cPanel first:11.11.0-BETA_16994 (update_time):1468656855 Cpanel::ZoneFile::VERSION:1.3 hostname:server.test.com latest:11.56.0.13
; Zone file for test.com
$TTL 14400
test.com. 86400 IN SOA ns1.test.com. cpanel.test.com. (
2016071602 ;Serial Number
14400 ;refresh
7200 ;retry
2419200 ;expire
43200 )
test.com. 14400 IN A 192.168.1.100
localhost 14400 IN A 127.0.0.1
test.com. 14400 IN MX 0 test.com.
mail 14400 IN CNAME test.com.
www 14400 IN CNAME test.com.
ftp 14400 IN CNAME test.com.
webdisk 14400 IN A 192.168.1.100
cpcalendars 14400 IN A 192.168.1.100
test.com. IN TXT "v=spf1 +a +mx +ip4:192.168.1.100 ~all"
I want to replace all current IP address 192.168.1.100 in it with 192.168.1.101 except the "spf" record line.
How can this be done?.
sed '/spf/! s/192\.168\.1\.100/192.168.1.101/'
On lines which do not match /spf/ do the requested substitution. The backslashes prevent the . from matching any character, of course. If you have any lines where the IP address could appear multiple times, you could add a g at the end. If you think it is a real problem, you could worry about matching 9192.168.1.1001 (that is, you if you think the IP address might appear as a substring of something that isn't an IP address).
Try this
sed -i -r 's/192.168.1.100$/192.168.1.101/g' /var/named/test.com.db

Linux + Apache to detect the Connection Counts of each Vhosts?

With RHEL and Apache (httpd), is there a way to:
Detect which v.host (domain) is gaining how many incoming connections?
Because in this few days, i got a lot of incoming connections on the Server being acknowledged by using:
ps aux | grep httpd -c
734
That means i have 734 incoming connections currently being handled by Apache but the problem is i have (lets say) 10 Vhosts (domains).
So which Domain is getting the high loads?
Any sharp solutions please.
Say you have a file like /etc/apache2/sites-enabled/000-example.com
You may see lines like:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /www/example.com
Further down, If you want, you can create logfiles for each VirtualHost by changing lines
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Too:
ErrorLog ${APACHE_LOG_DIR}/example_com.error.log
CustomLog ${APACHE_LOG_DIR}/example_com.access.log combined
Otherwise, if you don't want to create logfiles for each VirtualHost, then you can create your own custom log format http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats
For example:
LogFormat "%v %h %l %u %t \"%r\" %>s %b" common
CustomLog ${APACHE_LOG_DIR}/access.log common
When you have decided how you want to log, then you can write all kinds of scripts to examine or compare your logs. It would be far easier if you are using separate logfiles for each virtualhost, because you may try this.
wc -l /var/log/apache2/*access.log

how to configure hostname to have identical name as subdomain?

I've accomplished the following easily on a unix system, but I don't manage to get the same configured on a MS Windows server:
subdomain.example.org is a zone, so that I can setup child hostnames like host.subdomain.example.org. Furthermore, subdomain.example.org is also an entry point to the subdomain and runs a webserver. For that purpose I create an A record that points to an IP address. That is, the hostname is identical with the subdomain name.
I don't seem to be able to reproduce this on the windows server. once I create the subdomain, I can't add the A record. What's the secret to getting this up and running?
When creating A records you can use the # symbol for the record name to indicate the parent record i.e. no record name. In your case this applies to subdomain zones (and beyond).
example.com = # IN A 1.2.3.4
www.example.com = www IN A 192.168.0.2
Example raw dns zone file:
$TTL 14400
$ORIGIN example.com.
# 1D IN SOA ns1.example.com. hostmaster.example.com. (
2002022401 ; serial
3H ; refresh
15 ; retry
1w ; expire
3h ; minimum
)
IN NS ns1.example.com. ; in the domain
IN NS ns2.smokeyjoe.com. ; external to domain
IN MX 10 mail.another.com. ; external mail provider
# IN A 1.2.3.4 ; root record here would be value for example.com
ns1 IN A 192.168.0.1 ;name server definition
www IN A 192.168.0.2 ;web server definition
ftp IN CNAME www.example.com. ;ftp server definition
bill IN A 192.168.0.3
fred IN A 192.168.0.4

Bind DNS host pointing name servers to different IPs

Okay, at the moment i have my domain's host file which was generated by the Webmin control panel. I have a box to myself with several IPs and i want to make use of more than one. I don't fully understand everything to do with host files but I know enough to get by.
Can anyone suggest how i would go about changing the below host file to make my two name servers and mail server have their own IPs and then my domains and sub domains share another?
$ttl 120
# IN SOA ns1.example.com. webmaster.example.com. (
1283718781
1D
120
7D
120 )
example.com. IN NS ns1.example.com.
example.com. IN A 192.168.0.1
www.example.com. IN A 192.168.0.1
ftp.example.com. IN A 192.168.0.1
m.example.com. IN A 192.168.0.1
localhost.example.com. IN A 127.0.0.1
webmail.example.com. IN A 192.168.0.1
admin.example.com. IN A 192.168.0.1
mail.example.com. IN A 192.168.0.1
example.com. IN MX 5 mail.example.com.
example.com. IN NS ns2.example.com.
[edit]
Just to add, can you also suggest any improvements because at present initial loading of the website is slow, i did a dns test from an online tool and resolving was taking a long while. After the first page load the site's home page then loads in less than 2 seconds, presumably because stuff has been cached after the first load.
please and thanks in advance for any help.
I'm not sure if I understood your question but I would use following zone file for example.com domain:
$ttl 120
# IN SOA ns1.example.com. webmaster.example.com. (
2010091401 ; Serial format YYYYmmddXX where XX is 01-99
1D
120
7D
120 )
IN NS ns1.example.com.
IN NS ns2.example.com.
IN MX 5 mail.example.com.
IN A 192.168.0.1
ns1 IN A 192.168.xxx.xxx ; ns1 ip
ns2 IN A 192.168.xxx.xxx ; ns2 ip
www IN A 192.168.0.1
ftp IN A 192.168.0.1
m IN A 192.168.0.1
webmail IN A 192.168.0.1
admin IN A 192.168.0.1
mail IN A 192.168.0.1
localhost IN A 127.0.0.1

Resources