The system admins team of xFusionCorp Industries has noticed intermittent issues with DNS resolution in several apps . App Server 2 in Stratos Datacenter is having some DNS resolution issues, so we want to add some additional DNS nameservers on this server.
As a temporary fix we have decided to go with Google public DNS (ipv4). Please make appropriate changes on this server.
Solution
Step 1: Connect to App Server 2 (stapp02)
ssh steve@stapp02
# Password: Am3ric@
Step 2: Switch to root
sudo su -
# Password: Am3ric@
Step 3: Check current DNS configuration
cat /etc/resolv.conf
Step 4: Add Google Public DNS nameservers
Google Public DNS IPv4 addresses:
-
8.8.8.8(Primary) -
8.8.4.4(Secondary)
# Add Google DNS servers to resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
Step 5: Verify the configuration
cat /etc/resolv.conf
Step 6: Test DNS resolution
# Test with ping
ping -c 2 google.com
# Test with nslookup
nslookup google.com
# Test with dig
dig google.com
One-Line Commands
From jump host with password:
echo 'Am3ric@' | ssh steve@stapp02 "sudo -S bash -c 'echo \"nameserver 8.8.8.8\" >> /etc/resolv.conf && echo \"nameserver 8.8.4.4\" >> /etc/resolv.conf && cat /etc/resolv.conf'"
Using heredoc (Recommended):
ssh steve@stapp02 << 'EOF'
echo 'Am3ric@' | sudo -S bash -c '
echo "=== Current DNS configuration ==="
cat /etc/resolv.conf
echo ""
echo "=== Adding Google Public DNS ==="
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
echo ""
echo "=== Updated DNS configuration ==="
cat /etc/resolv.conf
echo ""
echo "=== Testing DNS resolution ==="
ping -c 2 google.com
'
EOF
Step-by-Step Interactive Commands
# Connect to stapp02
ssh steve@stapp02
# Password: Am3ric@
# Become root
sudo su -
# Password: Am3ric@
# Step 1: Check current DNS configuration
echo "=== Current DNS configuration ==="
cat /etc/resolv.conf
# Step 2: Backup existing resolv.conf (optional but recommended)
echo "=== Backing up resolv.conf ==="
cp /etc/resolv.conf /etc/resolv.conf.backup
# Step 3: Add Google DNS servers
echo "=== Adding Google Public DNS ==="
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
# Step 4: Verify the changes
echo "=== Updated DNS configuration ==="
cat /etc/resolv.conf
# Step 5: Test DNS resolution
echo "=== Testing DNS resolution ==="
ping -c 2 google.com
nslookup google.com
# Exit
exit
exit
Expected Output
[root@stapp02 ~]# cat /etc/resolv.conf
nameserver 10.0.0.2
[root@stapp02 ~]# echo "nameserver 8.8.8.8" >> /etc/resolv.conf
[root@stapp02 ~]# echo "nameserver 8.8.4.4" >> /etc/resolv.conf
[root@stapp02 ~]# cat /etc/resolv.conf
nameserver 10.0.0.2
nameserver 8.8.8.8
nameserver 8.8.4.4
[root@stapp02 ~]# ping -c 2 google.com
PING google.com (142.250.192.46) 56(84) bytes of data.
64 bytes from 142.250.192.46: icmp_seq=1 ttl=115 time=10.2 ms
64 bytes from 142.250.192.46: icmp_seq=2 ttl=115 time=10.5 ms
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
[root@stapp02 ~]# nslookup google.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: google.com
Address: 142.250.192.46
Alternative Methods
Method 1: Using tee command
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
echo "nameserver 8.8.4.4" | sudo tee -a /etc/resolv.conf
Method 2: Using cat with heredoc
cat >> /etc/resolv.conf << EOF
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
Method 3: Using sed to replace existing nameservers
sed -i 's/^nameserver.*/nameserver 8.8.8.8/' /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
Method 4: Using nmcli (NetworkManager)
# Check connection name
nmcli connection show
# Add DNS servers
nmcli connection modify <connection-name> ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection up <connection-name>
Method 5: Using nmtui (Text User Interface)
nmtui
# Navigate to Edit a connection
# Select the connection
# Add DNS servers
# Save and exit
Verification Commands
# 1. Check resolv.conf
cat /etc/resolv.conf
# 2. Test DNS resolution with ping
ping -c 2 google.com
# 3. Test with nslookup
nslookup google.com
# 4. Test with dig
dig google.com
# 5. Test with host
host google.com
# 6. Check DNS resolution order
getent hosts google.com
# 7. Check if DNS servers are reachable
ping -c 2 8.8.8.8
ping -c 2 8.8.4.4
Understanding Google Public DNS
Google Public DNS IPv4 Addresses
| Address | Description |
|---|---|
8.8.8.8 |
Primary DNS |
8.8.4.4 |
Secondary DNS |
Google Public DNS IPv6 Addresses
| Address | Description |
|---|---|
2001:4860:4860::8888 |
Primary DNS |
2001:4860:4860::8844 |
Secondary DNS |
Why Use Google Public DNS
- Reliability: Highly available and globally distributed
- Speed: Fast resolution times
- Security: DNSSEC validation and protection against DNS poisoning
- Privacy: No logging of personal information
- Free: Available to everyone at no cost
Important Notes
resolv.conf May Be Overwritten
On systems using NetworkManager or DHCP, /etc/resolv.conf may be automatically overwritten. To make changes permanent, consider these approaches.
Option 1: Use NetworkManager
nmcli connection modify <connection-name> ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection modify <connection-name> ipv4.ignore-auto-dns yes
nmcli connection up <connection-name>
Option 2: Make resolv.conf immutable
chattr +i /etc/resolv.conf
# To undo: chattr -i /etc/resolv.conf
Option 3: Configure in network interface file
# For RHEL/CentOS
vi /etc/sysconfig/network-scripts/ifcfg-<interface>
# Add: DNS1=8.8.8.8
# Add: DNS2=8.8.4.4
Troubleshooting
- "Permission denied" when editing resolv.conf:
# Use sudo or become root
sudo su -
- DNS still not resolving:
# Check if DNS servers are reachable
ping -c 2 8.8.8.8
# Check network connectivity
ping -c 2 8.8.4.4
# Restart network service
systemctl restart NetworkManager
- resolv.conf changes not persisting:
# Check if NetworkManager is managing resolv.conf
ls -la /etc/resolv.conf
# If symlink to NetworkManager, configure via nmcli
nmcli connection modify <connection> ipv4.dns "8.8.8.8 8.8.4.4"
- DNS resolution slow:
# Check which DNS server is being used
nslookup google.com
# Check DNS response time
dig google.com | grep "Query time"
- Cannot reach Google DNS:
# Check firewall rules
firewall-cmd --list-all
# Allow DNS traffic
firewall-cmd --add-service=dns --permanent
firewall-cmd --reload
Complete Script (Run from Jump Host)
#!/bin/bash
echo "========================================="
echo "Configuring Google Public DNS"
echo "========================================="
ssh steve@stapp02 << 'EOF'
echo 'Am3ric@' | sudo -S bash -c '
echo ""
echo "=== Current DNS Configuration ==="
cat /etc/resolv.conf
echo ""
echo "=== Backing up resolv.conf ==="
cp /etc/resolv.conf /etc/resolv.conf.backup
echo ""
echo "=== Adding Google Public DNS ==="
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
echo ""
echo "=== Updated DNS Configuration ==="
cat /etc/resolv.conf
echo ""
echo "=== Testing DNS Resolution ==="
ping -c 2 google.com
echo ""
echo "========================================="
echo "✅ Google Public DNS configured successfully!"
echo "📌 Primary DNS: 8.8.8.8"
echo "📌 Secondary DNS: 8.8.4.4"
echo "========================================="
'
EOF
Summary
- ✅ Google Public DNS added:
8.8.8.8and8.8.4.4 - ✅ Configuration file:
/etc/resolv.conf - ✅ DNS resolution tested: Working correctly
- ✅ Backup created:
/etc/resolv.conf.backup
The DNS configuration on App Server 2 has been updated to use Google Public DNS as a temporary fix for the intermittent DNS resolution issues.
Top comments (0)