DNS 服务地址配置

更新时间:
2024-03-14
下载文档

DNS 服务地址配置

SylixOS 下支持DNS(域名解析)服务,既可以通过域名地址来访问网络地址。

测试

先进行一个域名解析的测试:

[root@sylixos:/root]# 
[root@sylixos:/root]# ifconfig
en1       Link encap: Ethernet HWaddr: a6:2a:a5:e4:ed:c4
          Dev: e1000_0 Ifidx: 2 DHCP: D4 D6 Spd: 1000 Mbps
          inet addr: 192.168.196.110 netmask: 255.255.255.0
          gateway: 192.168.196.1 broadcast: 192.168.196.255
          inet6 addr: fe80::a42a:a5ff:fee4:edc4 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          collisions:0 txqueue:0 tcpaf:2 tcpwnd:65535
          RX ucast packets:1 nucast packets:1291 dropped:0
          TX ucast packets:0 nucast packets:7 dropped:0
          RX bytes:83938 (81.9 KB)  TX bytes:518 (518.0 B)

lo0       Link encap: Local Loopback
          Dev: N/A Ifidx: 1 DHCP: D4 D6 Spd: N/A
          inet addr: 127.0.0.1 netmask: 255.0.0.0
          P-to-P: 127.0.0.1 broadcast: N/A
          inet6 addr: ::1 Scope:Loopback
          UP LOOPBACK RUNNING  MTU:0  Metric:1
          collisions:0 txqueue:0 tcpaf:2 tcpwnd:262140
          RX ucast packets:3 nucast packets:0 dropped:0
          TX ucast packets:3 nucast packets:0 dropped:0
          RX bytes:168 (168.0 B)  TX bytes:168 (168.0 B)

dns0: 0.0.0.0
dns1: 0.0.0.0
dns2: 0.0.0.0
dns3: 0.0.0.0
default device is: null
list net interface: 2
[root@sylixos:/root]# ping www.baidu.com
Execute a DNS query...
Pinging request could not find host www.baidu.com .Please check the name and try again.

parameter(s) error.
[root@sylixos:/root]# 

通过 ifconfig 命令可以查看当前的DNS配置。由上图可知,系统 DNS 配置为空时,直接 ping 域名是失败的。

在 Windows 系统下,PowerShell 命令行中 ping 百度域名可通,同时也得到了百度的实际 IP 地址。

PS C:\Users\86186>
PS C:\Users\86186> ping www.baidu.com

正在 Ping www.a.shifen.com [180.101.50.188] 具有 32 字节的数据:
来自 180.101.50.188 的回复: 字节=32 时间=19ms TTL=48
来自 180.101.50.188 的回复: 字节=32 时间=19ms TTL=48
来自 180.101.50.188 的回复: 字节=32 时间=19ms TTL=48
来自 180.101.50.188 的回复: 字节=32 时间=19ms TTL=48

180.101.50.188 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 19ms,最长 = 19ms,平均 = 19ms
PS C:\Users\86186>

再在 SylixOS 下,直接 ping 百度的 IP 地址,是可以 ping 通的,说你设备网络设置正常,可访问外网。

[root@sylixos:/root]# ping 180.101.50.188
Pinging 180.101.50.188

Reply from 180.101.50.188: bytes=32 time=17.203ms TTL=48
Reply from 180.101.50.188: bytes=32 time=18.905ms TTL=48
Reply from 180.101.50.188: bytes=32 time=18.768ms TTL=48
Reply from 180.101.50.188: bytes=32 time=18.775ms TTL=48

Ping statistics for 180.101.50.188:
    Packets: Send = 4, Received = 4, Lost = 0(0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 17.203ms, Maximum = 18.905ms, Average = 18.412ms

[root@sylixos:/root]#

由上图可知,在其他网络参数配置正确的情况下,SylixOS 可以直接 ping 通 www.baidu.com 的 ip 地址,但在DNS无配置的情况下不能直接按域名进行访问。

配置

SylixOS 下查看DNS配置通过 ifconfig 命令,系统最多能配置 4 个 DNS 服务地址,默认都为空(全 0)。

有两种方法配置DNS服务地址。

通过 ifconfig 命令配置,立即有效,但配置不能保存,复位后无效。

[root@sylixos:/root]# help ifconfig
show or set net interface parameter.
if there are no arguments, it will show all interface parameter
ifconfig -u (show all interface with 'IFF_UP' state)
ifconfig -r (show all interface with 'IFF_UP' & 'IFF_RUNNING' state)
set interface like following:
ifconfig en1 inet    192.168.0.3
ifconfig en1 netmask 255.255.255.0
ifconfig en1 gateway 192.168.0.1
ifconfig en1 dns 0   192.168.0.2
ifconfig dns 0       192.168.0.2
ifconfig [ifname] [{inet | netmask | gateway}] [address]
[root@sylixos:/root]# 
[root@sylixos:/root]# 
[root@sylixos:/root]# ifconfig dns 0 114.114.114.114
[root@sylixos:/root]# ifconfig
en1       Link encap: Ethernet HWaddr: a6:2a:a5:e4:ed:c4
          Dev: e1000_0 Ifidx: 2 DHCP: D4 D6 Spd: 1000 Mbps
          inet addr: 192.168.196.110 netmask: 255.255.255.0
          gateway: 192.168.196.1 broadcast: 192.168.196.255
          inet6 addr: fe80::a42a:a5ff:fee4:edc4 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          collisions:0 txqueue:0 tcpaf:2 tcpwnd:65535
          RX ucast packets:37 nucast packets:9864 dropped:0
          TX ucast packets:5 nucast packets:9 dropped:0
          RX bytes:653868 (638.5 KB)  TX bytes:968 (968.0 B)

lo0       Link encap: Local Loopback
          Dev: N/A Ifidx: 1 DHCP: D4 D6 Spd: N/A
          inet addr: 127.0.0.1 netmask: 255.0.0.0
          P-to-P: 127.0.0.1 broadcast: N/A
          inet6 addr: ::1 Scope:Loopback
          UP LOOPBACK RUNNING  MTU:0  Metric:1
          collisions:0 txqueue:0 tcpaf:2 tcpwnd:262140
          RX ucast packets:3 nucast packets:0 dropped:0
          TX ucast packets:3 nucast packets:0 dropped:0
          RX bytes:168 (168.0 B)  TX bytes:168 (168.0 B)

dns0: 114.114.114.114
dns1: 0.0.0.0
dns2: 0.0.0.0
dns3: 0.0.0.0
default device is: en1
list net interface: 2
[root@sylixos:/root]# 
[root@sylixos:/root]# 
[root@sylixos:/root]# ping www.baudi.com
Execute a DNS query...
Pinging www.baudi.com [199.59.243.224]

Pinging 199.59.243.224

Reply from 199.59.243.224: bytes=32 time=74.973ms TTL=239
Reply from 199.59.243.224: bytes=32 time=74.741ms TTL=239
Reply from 199.59.243.224: bytes=32 time=75.025ms TTL=239
Reply from 199.59.243.224: bytes=32 time=74.907ms TTL=239

Ping statistics for 199.59.243.224:
    Packets: Send = 4, Received = 4, Lost = 0(0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 74.741ms, Maximum = 75.025ms, Average = 74.911ms

[root@sylixos:/root]# 

另一种方式是通过配置 /etc/resolv.conf 文件来实现,重启有效。

[root@sylixos:/root]# 
[root@sylixos:/root]# cat /etc/resolv.conf
nameserver 114.114.114.114

[root@sylixos:/root]# 

注意:在网卡驱动中,init_flags 字段要置位 NETDEV_INIT_LOAD_DNS 才会在网卡初始化时自动加载 /etc/resolv.conf 中的配置。

正确配置系统DNS服务后,就可以直接 ping 通域名了。

常用DNS服务地址如下:

文档内容是否对您有所帮助?
有帮助
没帮助