❤️ AZDIGI has officially updated to a new blog system. However, some posts may have incorrect or mismatched images. Please click the Report article button at the bottom of the post so AZDIGI can update as quickly as possible. Thank you!

While using Linux, you must have encountered the “Name or service not known” error message when pinging or connecting to a certain address. So what is the cause of this error and how to fix it, will be solved by AZDIGI in this article.

I. Cause

The cause of this error is usually because the DNS on your server is not configured or the configured DNS servers are having problems.

Name or service not known error message

II. How to fix the error: Name or service not known on Linux

To fix the error: Name or service not known on Linux, we perform the following 2 steps.

Step 1: SSH into your server

To fix the error: Name or service not known on Linux, we first need to SSH or access your VPS or server as root. If you do not know how to SSH into your VPS/Server, you can refer to the following tutorial:

After SSH successfully, we continue with step 2 to start the error handling process: Name or service not known on Linux.

Step 2: Commands to fix the error: Name or service not known on Linux

There will be many options for you to choose from.

Option 1: Switch to using the carrier’s DNS

Before switching to using the network’s DNS, we need to know the IP list of the network’s servers first. Here’s a list of all your carrier’s DNS servers:

Home networkDNS Server 1DNS Server 2
DNS VNPT Hanoi203.162.0.181203.162.0.182
DNS VNPT HCM203.162.4.190203.162.4.191
DNS FPT210.245.24.20210.245.24.22
DNS Viettel203.113.131.1203.113.131.2
List of all network DNS servers (updated March 2018).

Once you have the list of carrier IPs, just run the following command to add these DNS to the server:

AZDIGI Tutorial
sudo sh -c "echo nameserver DIA_CHI_IP_1 > /etc/resolv.conf"
sudo sh -c "echo nameserver DIA_CHI_IP_2 >> /etc/resolv.conf"
    

For example, I do with DNS of Viettel DNS, the command will be as follows:

AZDIGI Tutorial
sudo sh -c "echo nameserver 203.113.131.1 > /etc/resolv.conf"
sudo sh -c "echo nameserver 203.113.131.2 >> /etc/resolv.conf"
    

Option 2: Switch to using Google’s DNS

Similarly to change to using Google’s DNS, we use the following commands:

AZDIGI Tutorial
sudo sh -c "echo nameserver 8.8.8.8 > /etc/resolv.conf"
sudo sh -c "echo nameserver 8.8.4.4 >> /etc/resolv.conf"
    

Option 3: Switch to using OpenDNS’s DNS

Similarly, to change to OpenDNS‘s DNS, we use the following commands:

AZDIGI Tutorial
sudo sh -c "echo nameserver 208.67.222.222 > /etc/resolv.conf"
sudo sh -c "echo nameserver 208.67.220.220 >> /etc/resolv.conf"
    

Option 4: Switch to Cloudflare DNS (Recommended)

To change to using Cloudflare‘s DNS, we use the command:

AZDIGI Tutorial
sudo sh -c "echo nameserver 1.1.1.1 > /etc/resolv.conf"
    

Of these 4 options, I recommend using option 4 because I think Cloudflare’s DNS servers work the best and update the fastest.

We retry the ping command to see that everything is working normally.

Name or service not known

III. Summary

Hopefully, through this article, you have learned how to handle the “Name or service not known” error by adjusting the DNS on your Linux server. And how to quickly change the appropriate DNS server if you want. Hope the article is useful to you.

Wishing you success!

Share:
This article has been reviewed by AZDIGI Team

About the author

Thạch Phạm

Thạch Phạm

Đồng sáng lập và Giám đốc điều hành của AZDIGI. Có hơn 15 năm kinh nghiệm trong phổ biến kiến thức liên quan đến WordPress tại thachpham.com, phát triển website và phát triển hệ thống.

10+ years serving 80,000+ customers

Start your web project with AZDIGI