DNS: Difference between revisions

From 太極
Jump to navigation Jump to search
 
(12 intermediate revisions by the same user not shown)
Line 33: Line 33:
* [https://www.digitalocean.com/docs/networking/dns/how-to/manage-records/ How to Create, Edit, and Delete DNS Records]
* [https://www.digitalocean.com/docs/networking/dns/how-to/manage-records/ How to Create, Edit, and Delete DNS Records]
* [https://www.namecheap.com/support/knowledgebase/article.aspx/319/2237/how-can-i-set-up-an-a-address-record-for-my-domain How can I set up an A (address) record for my domain (namecheap)?], [https://support.prontomarketing.com/hc/en-us/articles/217414266-How-to-edit-DNS-records-on-Namecheap- How to edit DNS records on Namecheap?]
* [https://www.namecheap.com/support/knowledgebase/article.aspx/319/2237/how-can-i-set-up-an-a-address-record-for-my-domain How can I set up an A (address) record for my domain (namecheap)?], [https://support.prontomarketing.com/hc/en-us/articles/217414266-How-to-edit-DNS-records-on-Namecheap- How to edit DNS records on Namecheap?]
* [https://www.howtogeek.com/devops/how-to-buy-a-domain-name-for-your-website/ How To Buy a Domain Name For Your Website]


== A record ==
== A record ==
* A records are used to map a domain name to an IP address and CNAME records are used to map one domain name to another domain name.
* A records are used to map a domain name to an IP address and CNAME records are used to map one domain name to another domain name.
* For example, "domain.com" is an A record, and "www.domain.com" is CNAME record which maps it to "www.domain.com".
* For example, "domain.com" is an A record, and "www.domain.com" is CNAME record which maps it to "www.domain.com".
* [https://serverfault.com/a/1101393 What does '''@''' mean when setting up A Records in your DNS settings?]  '''Apex records''', '''naked domain'''
** When creating a new A record, using the host as ''' @''' means that the record is for the root domain itself. In other words, if your domain is “example.com”, an A record with '''@''' as the host would point “example.com” to the specified IP address. This is often used to direct traffic for the bare domain (i.e., example.com without any subdomains like www) to a particular server.
* [https://servebolt.com/help/how-to-set-up-subdomains-with-cloudflare/ How to set up subdomains with Cloudflare], [https://youtu.be/Y02t6hzaUBM?si=10HEB2Hk0fwWEzMP&t=560 免费开源论坛程序推荐!含搭建教程,手把手教你安装].


== CNAME ==
== CNAME ==
Line 78: Line 82:
# open port 53, or let ufw to allow bind9
# open port 53, or let ufw to allow bind9
</syntaxhighlight>
</syntaxhighlight>
* [https://www.howtoforge.com/how-to-set-up-local-dns-with-dnsmasq-on-debian-12/ How to Set Up Local DNS with Dnsmasq on Debian 12]
* [https://www.howtoforge.com/how-to-setup-dns-server-with-bind-on-ubuntu-22-04/ How to Setup DNS Server with BIND on Ubuntu 22.04]
* [https://www.howtoforge.com/how-to-setup-dns-server-with-bind-on-ubuntu-22-04/ How to Setup DNS Server with BIND on Ubuntu 22.04]
* [https://www.makeuseof.com/find-and-change-dns-server-on-linux/ How to Find and Change Your DNS Server on Linux]
* [https://www.makeuseof.com/find-and-change-dns-server-on-linux/ How to Find and Change Your DNS Server on Linux]
Line 155: Line 160:
</pre>
</pre>


== '''dig''' Command Examples ==
== '''dig''' Command Examples - check DNS server ==
dig (domain information groper) is a DNS lookup utility.
dig (domain information groper) is a DNS lookup utility.


Line 162: Line 167:
: <syntaxhighlight lang='bash'>
: <syntaxhighlight lang='bash'>
$ sudo apt install dnsutils
$ sudo apt install dnsutils
$ dig google.com ANY
 
$ dig r-project.org  # only 1 is returned
$ dig techmint.com
$ dig r-project.org  ANY
...
...
;r-project.org.                 IN      ANY
;; Query time: 220 msec
;; SERVER: 100.100.100.100#53(100.100.100.100)
;; WHEN: Fri Aug 16 08:44:30 EDT 2024
;; MSG SIZE  rcvd: 57


;; ANSWER SECTION:
$ dig @1.1.1.1 techmint.com
r-project.org.         7199    IN      NS      ns2.urbanek.info.
...
r-project.org.         7199    IN      NS      ns1.urbanek.info.
;; Query time: 68 msec
r-project.org.          7199    IN      NS      ns2.wu-wien.ac.at.
;; SERVER: 1.1.1.1#53(1.1.1.1)
r-project.org.         7199    IN      NS      ns3.urbanek.info.
;; WHEN: Fri Aug 16 08:47:02 EDT 2024
r-project.org.          7199    IN      NS      ns4.urbanek.info.
;; MSG SIZE  rcvd: 57
r-project.org.          7199    IN      NS      ns1.wu-wien.ac.at.
 
r-project.org.          7199    IN      A      137.208.57.37
# List All DNS Records Using dig
r-project.org.          7199    IN      MX      5 mc1.ethz.ch.
$ dig google.com ANY 
r-project.org.          7199    IN      MX      5 mc4.ethz.ch.
r-project.org.          7199    IN      MX      5 mc3.ethz.ch.
r-project.org.          7199    IN      MX      5 mc2.ethz.ch.
r-project.org.          7199    IN      TXT    "v=spf1 ip4:129.132.119.208/32 ~all"
r-project.org.          7199    IN      SOA    ns0.wu-wien.ac.at. postmaster.wu-wien.ac.at.
</syntaxhighlight>
</syntaxhighlight>
* 100.100.100.100 is from '''tailscale'''. [https://tailscale.com/kb/1381/what-is-quad100 What is 100.100.100.100?]
* [https://rud.is/b/2019/06/28/quick-hit-dig-ging-into-dns-records-with-processx/ Quick hit: ‘dig’-ging Into r-project.org DNS Records with {processx}]
* [https://rud.is/b/2019/06/28/quick-hit-dig-ging-into-dns-records-with-processx/ Quick hit: ‘dig’-ging Into r-project.org DNS Records with {processx}]
* [https://www.linuxuprising.com/2021/04/doggo-is-dns-lookup-utility-with.html Doggo Is A DNS Lookup Utility With Colorful Output, DNS-over-TLS and DNS-over-HTTPS Support]
* [https://www.linuxuprising.com/2021/04/doggo-is-dns-lookup-utility-with.html Doggo Is A DNS Lookup Utility With Colorful Output, DNS-over-TLS and DNS-over-HTTPS Support]
Line 197: Line 200:
* https://blogging.dragon.org.uk/howto-setup-dnsmasq-as-dns-dhcp/
* https://blogging.dragon.org.uk/howto-setup-dnsmasq-as-dns-dhcp/
* [https://www.cloudsavvyit.com/14924/how-to-run-a-local-network-dhcp-server-with-dnsmasq/ How to Run a Local Network DHCP Server with Dnsmasq]
* [https://www.cloudsavvyit.com/14924/how-to-run-a-local-network-dhcp-server-with-dnsmasq/ How to Run a Local Network DHCP Server with Dnsmasq]
* [https://www.howtoforge.com/how-to-set-up-local-dns-with-dnsmasq-on-rocky-linux/ How to Install a Local DNS Resolver with Dnsmasq on Rocky Linux]


== Local forwarding server ==
== Local forwarding server ==
Line 207: Line 211:
$ sudo netstat -anp | grep -i dnsmasq
$ sudo netstat -anp | grep -i dnsmasq
</syntaxhighlight>
</syntaxhighlight>
== DHCP server ==
<ul>
<li>[[Raspberry#Turn_Raspi_into_a_wireless_hotspot_/_access_point|Turn Raspi into a wireless hotspot / access point]]
<li>ChatGPT. Remember to replace eth0 with the interface name connected to your home router and adjust IP ranges and settings according to your needs.
* Install the DHCP Server
<pre>
sudo apt install isc-dhcp-server
sudo nano /etc/default/isc-dhcp-server
INTERFACES="eth0 eth1"
</pre>
* Configure the DHCP Server
<pre>
subnet 10.50.50.0 netmask 255.255.255.0 {
  range 10.50.50.10 10.50.50.100;
  option routers 10.50.50.1;
  option subnet-mask 255.255.255.0;
  option broadcast-address 10.50.50.255;
  option domain-name-servers 8.8.8.8, 8.8.4.4;
  default-lease-time 600;
  max-lease-time 7200;
}
</pre>
* Assign Static IP to the Second NIC
* Enable IP Forwarding: Enable IP forwarding to allow internet access to the devices on the new network.
<pre>
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
</pre>
* Set Up NAT: Use iptables to set up NAT (Network Address Translation) so that devices on the new network can access the internet.
<pre>
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables-save > /etc/iptables.rules
</pre>
</ul>


= DNS providers =
= DNS providers =
Line 297: Line 336:
http://www.makeuseof.com/tag/nifty-ways-use-dns-advantage/
http://www.makeuseof.com/tag/nifty-ways-use-dns-advantage/


== Discover subdomains ==
[https://www.makeuseof.com/linux-tools-to-discover-subdomains-ethical-hacker/ 5 Powerful Linux Tools to Discover Subdomains as an Ethical Hacker]


= DNStracer =
= DNStracer =
Line 314: Line 355:
* [https://hub.docker.com/r/linuxserver/ddclient/ *ddclient container]
* [https://hub.docker.com/r/linuxserver/ddclient/ *ddclient container]


nano <s>'''/etc/ddclient.conf'''</s> '''/etc/ddclient/ddclient.conf'''. See my 'ddclient' google doc.
nano '''/etc/ddclient.conf''' on Debian 12. Use '''ddclient --help | grep version''' to find the installed version. See my 'ddclient' google doc.


Note that the specification should depend on the domain name registrar (eg namecheap). For namecheap, the login/password is NOT your actual credential from your domain name registrar. The password should be obtained from the domain name registrar website. The last line is about the host. If I am setting it up for a subdomain, I should enter the subdomain name (and skip the domain name part). The '''ssl=yes''' is to ensure the [https://help.dyn.com/ddclient/ connection is made over https instead of http].  
Note that the specification should depend on the domain name registrar (eg namecheap). For namecheap, the login/password is NOT your actual credential from your domain name registrar. The password should be obtained from the domain name registrar website. The last line is about the host. If I am setting it up for a subdomain, I should enter the subdomain name (and skip the domain name part). The '''ssl=yes''' is to ensure the [https://help.dyn.com/ddclient/ connection is made over https instead of http].  
Line 323: Line 364:
</pre>
</pre>


No matter which method we use, we can go to our DNS account (in namecheap, go to Dashboard -> MANAGE button -> Domains -> Advanced DNS) and temporarily change the global IP address to another one, run the update script and then check if the global IP address has been updated to the correct one.  
No matter which method we use, we can go to our DNS account (in namecheap, go to Dashboard -> MANAGE button -> Domains -> Advanced DNS) and temporarily change the global IP address to another one, run the update script and then check if the global IP address has been updated to the correct one.
 
<pre>
sudo systemctl restart ddclient.service
# sudo /etc/init.d/ddclient restart
 
sudo service ddclient status
</pre>


== namecheap ==
== namecheap ==
Line 432: Line 480:
* By using these new free CloudFlare Tunnels you don’t need ANY of that including the open ports on your local firewalls. [https://chriscolotti.us/technology/how-to-setup-and-use-cloudflare-tunnels/ How To Setup And Use CloudFlare Tunnels]
* By using these new free CloudFlare Tunnels you don’t need ANY of that including the open ports on your local firewalls. [https://chriscolotti.us/technology/how-to-setup-and-use-cloudflare-tunnels/ How To Setup And Use CloudFlare Tunnels]
* (video)  
* (video)  
** [https://youtu.be/Q5dG8g4-Sx0?si=EQVqgYtM2V1u6cx4&t=797 Cloudflare Tunnels: Getting Started with Domains, DNS, and Tunnels] (part 1) & [https://youtu.be/wdmbAo02ktQ Cloudflare Tunnels: Restrict Access with Google and Github] (part 2).
*** It works. We can pick the free plan for Cloudflare Zero Trust. Then '''Tunnels''' option is now under '''Networks''' instead of '''Access'''.
*** Note in creating a policy, I choose Github authentication. In the '''Configure rules''', I choose '''Emails''' & my email associated with Github account.
** [https://youtu.be/ZvIdFs3M5ic You Need to Learn This! Cloudflare Tunnel Easy Tutorial]
** [https://youtu.be/ZvIdFs3M5ic You Need to Learn This! Cloudflare Tunnel Easy Tutorial]
** [https://youtu.be/fNSf7D8CXgA HOW TO: SSH into Raspberry Pi remotely through Cloudflare tunnel (using terminal and putty)]
** [https://youtu.be/Z6b3l1z0N7w HOW TO: Remote access a Raspberry Pi using a Cloudflare tunnel (node-red and ssh)]
** [https://youtu.be/wdmbAo02ktQ Cloudflare Tunnels: Restrict Access with Google and Github]. It works. Note in creating a policy, I choose Github authentication. In the '''Configure rules''', I choose '''Emails''' & my email associated with Github account.
* SSH
* SSH
** [https://youtu.be/Z6b3l1z0N7w?t=834 HOW TO: Remote access a Raspberry Pi using a Cloudflare tunnel (node-red and ssh)]. Easy to follow!
** [https://youtu.be/Z6b3l1z0N7w?t=834 HOW TO: Remote access a Raspberry Pi using a Cloudflare tunnel (node-red and ssh)]. Easy to follow!

Latest revision as of 14:09, 9 November 2024

Resource

Block Ads

TTL

How to see Time-To-Live (TTL) for a DNS record

FQDN

URL

  • It seems we can append "?" and "#" after a valid URL.
  • What do "?" and "#" mean in a URL?
    • “?” in URL acts as separator
    • “#” was used as an anchor to jump to an element. However, nowadays it's usually used with AJAX-based pages since changing the hash can be detected using JavaScript and allows you to use the back/forward button without actually triggering a full page reload.
  • Which characters make a URL invalid?
  • Special character in URL ignored by browsers

Records

A record

CNAME

  • A CNAME record is used to map one domain name to another domain name. For example, a CNAME record for "www.example.com" might map to "example.com". This is useful when you want to point multiple domain names to the same server.
  • A CNAME record is used in lieu of an A record when a domain or subdomain is an alias of another domain. All CNAME records must point to a domain, never to an IP address. See What is a DNS CNAME record? For example, www.example.com is an alias of example.com.

DNSCrypt

Network commands

DNS server

Setup on Linux/Ubuntu

sudo apt install bind9
sudo nano /etc/bind/named.conf.options
  # update 'forwarders' key to use 1,1,1,1; 8.8.8.8;
  # add 'forward only;'
sudo systemctl restart bind9
# open port 53, or let ufw to allow bind9

AdGuard Home

How to set up your own open source DNS server

Pi-hole

Unbound

How to Set Up Local DNS Resolver with Unbound on Ubuntu 22.04

Client part

  • Windows/Mac/Linux
dig @192.168.1.2  linkedin.com  # Suppose the DNS server ips is 192.168.1.2
Pay attention to the Query time result. If we run the same command again, the query time will be reduced to 0 because of the cache in the DNS server.

Client part 2: what is my DNS server /etc/resolv.conf or /etc/network/interfaces. Static IP

Use one of the following commands

systemd-resolve  --status
resolvectl status
nmcli dev show | grep 'IP4.DNS'

PS. dig command can show my DNS server as part of its output.

On Ubuntu 18.04 and up, it uses netplan. PS. use space character instead tab in yml file.

Even I can change my DNS setting using the Network Manager (IPv4 -> disable Automatic -> Enter 8.8.8.8 -> Apply -> Toggle On/Off), the name solving does not work. Testing https://129.43.254.99 works but not https://brb.nci.nih.gov

To use the /etc/resolv.conf method, check out how to add DNS servers or Set permanent DNS nameservers on Ubuntu/Debian with resolv.conf (video).

On my home computer, it just shows one line nameserver 127.0.1.1. On work computer, it shows

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search XXX.XXX.gov

On the VM of my work computer, it shows

nameserver 127.0.0.53
search XXX.XXX.gov

It seems the /etc/resolv.conf file changes with the file on the host.

After any change, we can restart the network by using sudo service networking restart.

Note:

  • nameserver Name-server-IP-address: Point out to your your own nameserver or to ISP’s name server. Up to 3 name servers may be listed.
  • search domain.com: The search list is normally determined from the local domain name; by default, it contains only the local domain name. So when you type nslookup www, it will be matched to www.cyberciti.biz

You can also use Public Name Servers

nameserver 8.8.8.8
nameserver 8.8.4.4

dig Command Examples - check DNS server

dig (domain information groper) is a DNS lookup utility.

$ sudo apt install dnsutils

$ dig techmint.com
...
;; Query time: 220 msec
;; SERVER: 100.100.100.100#53(100.100.100.100)
;; WHEN: Fri Aug 16 08:44:30 EDT 2024
;; MSG SIZE  rcvd: 57

$ dig @1.1.1.1 techmint.com
...
;; Query time: 68 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Fri Aug 16 08:47:02 EDT 2024
;; MSG SIZE  rcvd: 57

# List All DNS Records Using dig
$ dig google.com ANY

host command

Linux and Unix host Command Examples

DNSmasq (DNS + DHCP server)

Local forwarding server

dnsmasq program is running on my Ubuntu and Linux/Mint machines.

See nameserver 127.0.1.1 in resolv.conf won't go away!

$ ps -ef | grep -i dnsmasq

$ sudo netstat -anp | grep -i dnsmasq

DHCP server

  • Turn Raspi into a wireless hotspot / access point
  • ChatGPT. Remember to replace eth0 with the interface name connected to your home router and adjust IP ranges and settings according to your needs.
    • Install the DHCP Server
    sudo apt install isc-dhcp-server
    sudo nano /etc/default/isc-dhcp-server
    INTERFACES="eth0 eth1"
    
    • Configure the DHCP Server
    subnet 10.50.50.0 netmask 255.255.255.0 {
      range 10.50.50.10 10.50.50.100;
      option routers 10.50.50.1;
      option subnet-mask 255.255.255.0;
      option broadcast-address 10.50.50.255;
      option domain-name-servers 8.8.8.8, 8.8.4.4;
      default-lease-time 600;
      max-lease-time 7200;
    }
    
    • Assign Static IP to the Second NIC
    • Enable IP Forwarding: Enable IP forwarding to allow internet access to the devices on the new network.
    echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
    sudo sysctl -p
    
    • Set Up NAT: Use iptables to set up NAT (Network Address Translation) so that devices on the new network can access the internet.
    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    sudo iptables-save > /etc/iptables.rules
    

DNS providers

Benchmark, bottleneck

How to determine bottleneck in page load time? Use a plugin or if you have Chrome, use its built-in inspector. Google Chrome: Right-click on anything and click "Inspect element" and click "Network" tab on the new box that appears. Navigate to your site, you will now see in real-time how the browser is receiving the information

Change DNS setting

Command line

How to Find and Change Your DNS Server on Linux.

resolvectl status

resolvectl dns <interface> <dns address 1> <dns address2>

Domain Setup & SSL Certificates, HTTPS - NGINX & Docker Compose

Shiny Production with AWS Book

Flush DNS cache

How To Set Permanent DNS Nameservers

How To Set Permanent DNS Nameservers in Ubuntu and Debian

Test if you are using OpenDNS

https://welcome.opendns.com/

I try to change the DNS ip using either Network Connection GUI or modifying /etc/resolv.conf (& calling sudo /etc/init.d/networking restart). But it does not change anything??

DNS-over-HTTPS (DoH) in Firefox

Query DNS server

DNS leak test

To list the current DNS servers used by my system,

Method 1:

# Ubuntu >= 15
$ nmcli dev show | grep 'IP4.DNS'
$ nmcli device show <interfacename> | grep IP4.DNS
# Ubuntu <= 14
$ nmcli dev list iface <interfacename> | grep IP4

Method 2:

$ cat /etc/resolv.conf

Method 3 (macOS):

scutil --dns | grep nameserver
# cat /etc/resolv.conf

Another way is to use the R packages: gdns and dnsflare. More Options For Querying DNS From R with 1.1.1.1.

3 Ways to Check DNS Propagation Status

https://www.makeuseof.com/tag/check-dns-propagation-status/

DNS tricks

5 DNS Servers Guaranteed to Improve Your Online Safety

http://www.makeuseof.com/tag/best-dns-providers-security/

5 Nifty Ways to Use DNS to Your Advantage

http://www.makeuseof.com/tag/nifty-ways-use-dns-advantage/

Discover subdomains

5 Powerful Linux Tools to Discover Subdomains as an Ethical Hacker

DNStracer

http://www.ubuntugeek.com/dnstracer-trace-dns-queries-to-the-source.html

Reverse DNS

Reverse DNS (rDNS) is a process that resolves an IP address back to a domain name, the opposite of a forward DNS query. What Is Reverse DNS and How Does It Work?

Dyndns and ddclient

According to a comment in this video, Cloudflare tunnel completely replaces the need for reverse proxy like Traefik/Nginx Proxy Manager.

Resources

nano /etc/ddclient.conf on Debian 12. Use ddclient --help | grep version to find the installed version. See my 'ddclient' google doc.

Note that the specification should depend on the domain name registrar (eg namecheap). For namecheap, the login/password is NOT your actual credential from your domain name registrar. The password should be obtained from the domain name registrar website. The last line is about the host. If I am setting it up for a subdomain, I should enter the subdomain name (and skip the domain name part). The ssl=yes is to ensure the connection is made over https instead of http.

And run sudo ddclient -daemon=0 -debug -verbose -noquiet to verify ddclient is working. You shall get a long return with the last line looks like

SUCCESS:  updating YOURSUBDOMAIN: good: IP address set to XX.XXX.XXX.XXX

No matter which method we use, we can go to our DNS account (in namecheap, go to Dashboard -> MANAGE button -> Domains -> Advanced DNS) and temporarily change the global IP address to another one, run the update script and then check if the global IP address has been updated to the correct one.

sudo systemctl restart ddclient.service
# sudo /etc/init.d/ddclient restart

sudo service ddclient status

namecheap

Cloudflare

Mail

CDN

Why You Should Use a CDN to Improve Your Website’s User Experience

DuckDNS

no-ip

Mail

  • Allow only one MX record for each host for free no-ip account.
  • Click Host/Redirects > Manage Hosts > Modify.

DNS attack

What Are DNS Attacks and How Do You Prevent Them?

Proxy server

Zero trust network access

What Is Zero Trust Network Access (ZTNA)

Cloudflare Tunnel

tailscale

  • Tailscale is an alternative to cloudflare tunnel
  • https://tailscale.com/kb/use-cases/. Some of the most common ones include deploying internal apps anywhere without changing firewall settings, replacing site-to-site VPNs with WireGuard, transparently interconnecting microservices between data centers and pods, and VPN from the couch to the office and HQ. Tailscale also allows remote access to computer resources and applications from any location.
  • How NAT traversal works by tailscale
  • How I use tailscale

Wireguard tunnel

SelfHosted Gateway - WireGuard Tunnel for secure external access to all of your Self Hosted Apps & Notes

twingate

IP spoofing

What Is IP Spoofing and What Is It Used For?