Home Linux ServerLinux Fundementals How to fix Name or service not known error on Linux

How to fix Name or service not known error on Linux

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

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!

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign