Admins eHow SysAdmin Tips & Tricks

December 2, 2022

Redirect all DNS requests to local caching DNS server

Filed under: dns,linux — Tags: , , , , — admin @ 2:44 am

For caching DNS Server, I use PowerDNS recursor server. Install it first :

apt install pdns-recursor

By default it listens on 127.0.0.1:53 and should work right after the installation, but for faster performance I want it to forward all queries to 8.8.8.8 which is Google’s public DNS server. so change /etc/powerdns/recursor.conf and add the following line :

forward-zones-recurse= .=8.8.8.8;

Restart the service after config change :

systemctl restart pdns-recursor.service

Now you can test it :

dig yahoo.com @127.0.0.1

You should get a valid response.
Now lets redirect all DNS queries to our local server :

iptables -t nat -I OUTPUT -m owner --uid-owner pdns -j RETURN
iptables -t nat -I POSTROUTING -m owner --uid-owner pdns -j RETURN
iptables -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to 127.0.0.1:53
iptables -t nat -A POSTROUTING -p udp --dport 53 -j SNAT --to-source 127.0.0.1

The first two iptables rules prevent a loop in redirecting pdns queries to outside world (8.8.8.8 in our case).
Done. Easy 😉

May 11, 2009

How to redirect mail.domain.com to roundcube using mod_rewrite

Filed under: cPanel,General — Tags: , , , — admin @ 8:45 am

This only works only if you have a dedicated IP on your cPanel account
Many people are having problems accessing cPanel mail clients , entering mail client from cPanel takes a lot of times and memorizing the URL which is located on “http://domain.com:2095/3rdparty/roundcube/index.php” is not easy, also it is very long.
after some research, I found an excellent solution to solve this problem one time forever and for all addon domains !
cPanel makes a CNAME entry for mail.maindomain.com and all mail.addondomains.com to maindomain.com automatically , we will use it to do the trick.
create .htaccess file in the root directory of your main domain ( /public_html folder ) and copy and paste the following code into it :

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^mail\.(.*)\.com$ [NC]
RewriteRule ^(.*)$ http://%1.com:2095/3rdparty/roundcube/index.php [R=301,NC,L]

it will redirect mail.maindomain.com and all of mail.addondomains.com to http://domain.com:2095/3rdparty/roundcube/index.php

May 7, 2009

Redirect 301 domain.com to www.domain.com using mod_rewrite

Filed under: General — Tags: , , , , — admin @ 9:10 am

For SEO improvements you may want to create a permanent redirect (301) from your domain.com to www.domain.com.
you can do it easily using Apache mod_rewrite , simply open .htaccess file in the root directory of your website and add the following lines to it :

Options +FollowSymLinks
RewriteEngine On
rewritecond %{http_host} ^domain.com [NC]
rewriterule ^(.*)$ http://www.domain.com/$1 [R=301,NC,L]

it will do the trick for you 🙂

Powered by WordPress