Networking Basics and DNS
Networking Basics
IP Addressing
Command to Add IP Address:
To add an IP address to an interface use:
bash ip addr add 192.168.1.10/24 dev eth0Example:
bash ip addr add 192.168.1.11/24 dev eth0
Testing Connectivity:
Use ping to test if the host is reachable:
bash ping 192.168.1.11Expected output example:
plaintext Reply from 192.168.1.11: bytes=32 time=4ms TTL=117
Network Interface Details
Command for Interface Info:
To view the state of network interfaces:
bash ip link show eth0
Output Breakdown:
Example output:
plaintext eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP
Routing Basics
Routing Example:
For routing between two networks (192.168.1.0 and 192.168.2.0):
plaintext 192.168.1.10 <--> 192.168.1.11 <--> 192.168.2.10
Add Route Command:
To add a route for a network:
bash ip route add 192.168.2.0/24 via 192.168.1.1
Default Gateway Configuration
Setting Up Default Gateway:
Command to set the default route through a gateway:
bash ip route add default via 192.168.2.1
Kernel IP Routing Table:
Example output of routing table:
plaintext Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 192.168.2.1 255.255.255.0 UG 0 0 0 eth0
Network Address Translation (NAT)
IP Forwarding:
Enabling IP forwarding is crucial for routing traffic between networks:
bash echo 1 > /proc/sys/net/ipv4/ip_forward
Check IP Forwarding Status:
bash cat /proc/sys/net/ipv4/ip_forwardExpected output if enabled:
1If disabled, use application configuration files to enable it permanently.
Domain Name System (DNS) Basics
Testing Name Resolution:
Ping using hostname instead of IP:
bash ping db
Adding Entries to Hosts File:
To resolve local hostnames, edit
/etc/hosts:bash echo '192.168.1.11 db' >> /etc/hosts
Using DNS for Name Resolution:
Check DNS resolution using:
bash nslookup www.google.comExpected output includes server address and resolved IP address.
Basic Commands Summary
Add IP address:
ip addr add
Add route:
ip route add
View network interfaces:
ip link show
Ping:
ping [IP/Hostname]
Enable IP forwarding:
echo 1 > /proc/sys/net/ipv4/ip_forward
Important Tools
nslookup: For querying the DNS to obtain domain name or IP address mapping.
dig: Providing detailed DNS query results.
Domain Names Structure
Components of a Domain Name:
Subdomain: The prefix before the main domain (e.g., www).
Domain Name: The registered domain (e.g., example.com).
Top Level Domain (TLD): Last part of a domain name (e.g., .com, .org).
Example:
```plaintext
www.google.com =
www (subdomain)
google (domain)
com (TLD)
- **Resource Records Types:**
- **A Record**: Maps a hostname to an IPv4 address.
- **AAAA Record**: Maps a hostname to an IPv6 address.
- **CNAME Record**: Alias of one domain to another, e.g., food.web-server to hungry.web-server.
## DNS Configuration Best Practices
- Set up local DNS servers to handle internal requests efficiently.
- Maintain an accurate `/etc/resolv.conf` file for proper DNS resolution.
- Example content of `/etc/resolv.conf`:
plaintext
nameserver 192.168.1.100
- Use `ping` to verify hostname resolution both before and after configuration adjustments.
## Summary of Domain Names
- Example domains to understand hierarchy:
- www.google.com
- www.facebook.com
- www.un.org
- **Scripting Examples:**
bash
cat >> /etc/hosts <<EOF
192.168.1.10 web
192.168.1.11 db
EOF
```