精华内容
下载资源
问答
  • 大约五分钟之后,网工反馈说域名解析已经添加,我在服务器上测试了下,确实已经正确解析出了IP,随后回复测试人员故障已恢复。 但是,事情总是很少一帆风顺的,大约两小时之后,测试人员反馈说故障依旧。很纳闷,...

    事件起因

    某一天测试部门的同事反馈某一个后台应用接口无法访问,我们立即登陆相关服务器,查看后台日志,发现了如下信息:

    <2018-04-28 16:59:02.713 ERROR 102603 --- [nio-8888-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

    java.net.UnknownHostException: a.b.com: 未知的名称或服务

    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_152]

    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[na:1.8.0_152]

    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[na:1.8.0_152]

    at java.net.InetAddress.getAllByName0(InetAddress.java:1276) ~[na:1.8.0_152]

    at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[na:1.8.0_152]

    at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[na:1.8.0_152]

    at java.net.InetAddress.getByName(InetAddress.java:1076) ~[na:1.8.0_152]

    at com.transfar.controller.GetDns.getip(GetDns.java:16) ~[classes!/:0.0.1-SNAPSHOT]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_152]

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_152]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_152]

    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_152]

    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]

    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]/>

    由于该接口会访问一个内网域名地址,第一反应是域名解析的问题,在服务器上ping a.b.com,无法解析出IP地址,那问题就清楚了,随后立即联系网络人员解决域名解析的问题。

    大约五分钟之后,网工反馈说域名解析已经添加,我在服务器上测试了下,确实已经正确解析出了IP,随后回复测试人员故障已恢复。

    但是,事情总是很少一帆风顺的,大约两小时之后,测试人员反馈说故障依旧。很纳闷,再次登陆服务器查看日志,发现依然在报之前的错误,百思不得其解之下,选择重启了java应用,故障终于彻底解决。(对运维来说,一时解决不了的问题,重启一定是对的,但也是临时的。)

    怀着不解的心情,决定一探到底。。

    其实我当时第一反应就是jdk是不是缓存了dns解析,查看资料得到两个重要的参数(jdk1.8)说明:

    文件位置:/usr/local/jdk1.8.0_152/jre/lib/security/java.security

    The Java-level namelookup cache policy for successful lookups:

    any negative value: caching forever

    any positive value: the number of seconds to cache an address for

    zero: do not cache

    default value is forever (FOREVER). For security reasons, this caching is made forever when a security manager is set. When a security manager is not set, the default behavior in this implementation is to cache for 30 seconds.

    NOTE:

    setting this to anything other than the default value can have

    serious security implications. Do not set it unless

    you are sure you are not exposed to DNS spoofing attack.

    networkaddress.cache.ttl=-1

    #参数意义:设置jdk解析域名成功的缓存时间。

    其他:设置缓存时间,单位秒

    默认值:如果开启了-Djava.security.manager,默认是-1,如果未开启,默认是30s

    The Java-level namelookup cache policy for failed lookups:

    any negative value: cache forever

    any positive value: the number of seconds to cache negative lookup results

    zero: do not cache

    In some Microsoft Windows networking environments that employ

    the WINS name service in addition to DNS, name service lookups

    that fail may take a noticeably long time to return (approx. 5 seconds).

    For this reason the default caching policy is to maintain these

    results for 10 seconds.

    networkaddress.cache.negative.ttl=10

    #参数意义:设置jdk解析域名失败的缓存时间。

    -1:永久缓存

    0:不缓存

    其他:设置缓存时间,单位秒

    下面做了一个测试,写成表格,对比了两个参数的影响,方便大家理解。

    参数名

    参数值

    cache.ttl

    -1

    cache.negative.ttl

    10

    结果分析:

    1、正常解析的域名被永久保存,即使dns修改过解析结果,程序解析出来的还是老的参数。

    2、异常解析的域名,根据配置值每隔10秒发起一次解析请求。

    分析结论

    查看问题服务器的jdk配置,发现设置了networkaddress.cache.negative.ttl=10,但是从表象来看,并没有正常解析出IP,重启应用之后,才解决。所以跟参数的配置说明不一致,原因待查。

    展开全文
  • import java.net.InetAddress;import java.net.UnknownHostException;public class ParseDomainName {InetAddress myServer = null;InetAddress myIPaddress = null;String domainName = null;public ParseDomainNam...

    import java.net.InetAddress;

    import java.net.UnknownHostException;

    public class ParseDomainName {

    InetAddress myServer = null;

    InetAddress myIPaddress = null;

    String domainName = null;

    public ParseDomainName(String domainName) {

    this.domainName = domainName;

    }

    public InetAddress getServerIP() {

    try {

    myServer = InetAddress.getByName(domainName);

    } catch (UnknownHostException e) {

    }

    return (myServer);

    }

    // 取得LOCALHOST的IP地址

    public InetAddress getMyIP() {

    try {

    myIPaddress = InetAddress.getLocalHost();

    } catch (UnknownHostException e) {

    }

    return (myIPaddress);

    }

    public static void main(String[] args) {

    ParseDomainName pdn = new ParseDomainName("www.baidu.com");

    System.out.println("Your host IP is: " + pdn.getMyIP().getHostAddress());

    System.out.println("The Server IP is :" + pdn.getServerIP().getHostAddress());

    }

    }

    展开全文
  • 普通的域名解析方法:import java.net.*;public class Kkkk {public static void main(String args[]) throws Exception {InetAddress address = InetAddress.getByName("wxh-PC");// wxh-PC是我的计算机名System....

    普通的域名解析方法:

    import java.net.*;

    public class Kkkk {

    public static void main(String args[]) throws Exception {

    InetAddress address = InetAddress.getByName("wxh-PC");// wxh-PC是我的计算机名

    System.out.println(address);

    System.out.println("-----");

    InetAddress address1 = InetAddress.getLocalHost();

    System.out.println(address1);

    InetAddress[] addresses = InetAddress

    .getAllByName("www.baidu.com");

    System.out.println(addresses.length);

    for (InetAddress addr : addresses) {

    System.out.println(addr);

    }

    }

    }

    实现具有动态主机IP的域名解析

    目的利用一台INTERNET DNS HOST 将域名定向到家中(个人)的主机上.

    目前CABLEMODEM已经很快了,而且有动态IP,所以就有了将域名解析到个人机器的上可能.

    只要通过很简单的设置就可以搞定.

    例如你有一个域名叫 yourdomain.com ,你可以将此域名解析任意的主机.

    1.服务器 (IP: A.A.A.A) 启动DNS动态解析的一个小进程.

    jb51.net的域名文件为 /var/named/jb51.net

    再建个/var/named/jb51.net.static (模板文件可以用来生成jb51.net的)

    (JDK1.3 , linux )

    # 原代码如下: ThreadDNSReloadServer.java

    import java.io.*;

    import java.net.*;

    public class ThreadDNSReloadServer

    {  public static void main(String[] args)

    { int i=1;

    try

    { ServerSocket s=new ServerSocket(8189);

    for (;;)

    { Socket incoming =s.accept();

    System.out.println("accept new client: " + i);

    new ThreadDNSReloadHandle(incoming,i).start();

    i++ ;

    }

    }

    catch (Exception e)

    { System.out.println(e);

    }

    }

    }

    class ThreadDNSReloadHandle extends Thread

    { public ThreadDNSReloadHandle(Socket i,int c)

    { incoming= i; counter=c; }

    public void run()

    { try

    { BufferedReader in=new BufferedReader(new InputStreamReader(incoming.getInputStream()));

    String User="Unkown";

    String DNSFILEPATH="/var/named/";

    String DNSFILE="jb51.net";

    String HOSTIP="127.0.0.1";

    boolean USER_VALIDATED=true ;

    boolean done=false;

    while ( !done )

    {  String str=in.readLine();

    //validate user;

    if ( str ==null ) done=true;

    else

    {

    str=str.trim();

    if ( str.substring(0,2).equals("LA") )

    { if (str.length() >2) User=str.substring(2);

    }

    if ( str.substring(0,2).equals("LB") )

    { if (str.length() >2) DNSFILE=str.substring(2);

    }

    if ( str.substring(0,2).equals("LC") )

    { if (str.length() >2) HOSTIP=str.substring(2);

    }

    if ( str.trim().equals("BYE")) done = true;

    }

    }

    incoming.close();

    //加入用户验证.

    //将服务器中的jb51.net.static文件写入jb51.net中

    String DNSTMP =DNSFILEPATH + DNSFILE +".static";

    BufferedReader sin=new BufferedReader(new FileReader(DNSTMP));

    PrintWriter sout=new PrintWriter(new FileWriter(DNSFILEPATH + DNSFILE) , true);

    String s;

    while ((s=sin.readLine()) != null)

    {

    if (s.startsWith("host"))

    { s="host IN A " + HOSTIP;

    sout.println(s);

    s="@ IN A " + HOSTIP;

    }

    sout.println(s);

    }

    //System.out.println("User:" + User );

    //System.out.println("DNSFILE:" + DNSFILE );

    //System.out.println("HOSTIP:" + HOSTIP );

    //ndc reload

    String command="ndc reload " + DNSFILE ;

    java.lang.Runtime.getRuntime().exec(command);

    }

    catch ( Exception e)

    { System.out.println(e);

    }

    }

    private Socket incoming;

    private int counter;

    }

    2.客户机(windows / linux)

    # 客户端每次启动时加入到开机启动(或进程中): SockTest.java

    import java.io.*;

    import java.net.*;

    public class SocketTest

    { public static void main(String[] args)

    { try

    { Socket s=new Socket("A.A.A.A",8189);

    BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));

    PrintWriter out=new PrintWriter(s.getOutputStream(),true);

    InetAddress localHostAddress =InetAddress.getLocalHost() ; //get LocalHost Ip

    out.println("LAguest");

    out.println("LByourdomain.com");

    out.println("LC" + localHostAddress.getHostAddress() );

    out.close();

    s.close();

    }

    catch (IOException e)

    { System.out.println(e);

    }

    }

    }

    dns 样本文件: ( jb51.net.static)

    @ ns.dnsserver.com xxxxx

    xxxx

    host    IN A 127.0.0.1      // 此处就是要更改的地方

    www    IN CNAME host

    ...

    展开全文
  • Java动态解析域名

    2021-02-12 17:30:55
    sun.net.spi.nameservice.provider.=Specifies the name service provider that you can ... By default, Java will use the system configured name lookup mechanism, such as file, nis, etc. You can specify y...

    sun.net.spi.nameservice.provider.=Specifies the name service provider that you can use. By default, Java will use the system configured name lookup mechanism, such as file, nis, etc. You can specify your own by setting this option. takes the value of a positive number, it indicates the precedence order with a small number takes higher precendence over a bigger number. Aside from the default provider, the JDK includes a DNS provider named "dns,sun".

    Prior to JDK 7, the first provider that was successfully loaded was used. In JDK 7, providers are chained, which means that if a lookup on a provider fails, the next provider in the list is consulted to resolve the name.sun.net.spi.nameservice.nameservers=You can specify a comma separated list of IP addresses that point to the DNS servers you want to use. If the sun.net.spi.nameservice.nameservers property is not defined, then the provider will use any name servers already configured in the platform DNS configurationsun.net.spi.nameservice.provider.=用于设置域名服务提供者= default的时候调用系统自带的DNS= dns,sun的时候,会调用sun.net.spi.nameservice.nameservers=指定的DNS来解析importjava.net.InetAddress;importjava.net.UnknownHostException;importjava.util.concurrent.ConcurrentLinkedQueue;importorg.apache.log4j.Logger;public classResolveDomain {private Logger log = Logger.getLogger(ResolveDomain.class);public static void main(String[] args) throwsUnknownHostException {

    ResolveDomain rd= newResolveDomain();

    rd.resolveDomain("www.baidu.com", "114.114.114.114", new ConcurrentLinkedQueue());

    }public void resolveDomain(String domain, String DNS, ConcurrentLinkedQueuequeue){

    System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");

    System.setProperty("sun.net.spi.nameservice.nameservers", DNS);

    InetAddress[] addresses;try{

    addresses= InetAddress.getAllByName(domain); //IP or domain

    for (int i = 0; i < addresses.length; i++) {

    String ip=addresses[i].getHostAddress();

    log.info(DNS+ "\t" + domain + "\t" +ip);

    queue.add(DNS+ "\t" + domain + "\t" +ip);

    }

    }catch(UnknownHostException e) {

    e.printStackTrace();

    }

    }

    }

    ps:对于有些域名,例如www.baidu.com,在不同地区拥有不同的IP;因此使用不同的DNS服务器进行解析,得到的IP一般也不一样。

    参考博客: http://blog.chinaunix.net/uid-192452-id-3981087.html

    http://www.jianshu.com/p/f10808ae4b60

    https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

    https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html

    https://www.cnblogs.com/549294286/p/5307316.html

    http://blog.csdn.net/mofenglian/article/details/74344631

    展开全文
  • } } pom.xml配置如下,引入阿里域名sdk包 com.aliyun aliyun-java-sdk-core 4.3.2 com.aliyun aliyun-java-sdk-alidns 2.0.10 cn.hutool hutool-all 5.1.0  如果报错如下: ...
  • 1 域名解析,将域名可转换为ip地址InetAddress也可以通过使用getAddress()来获得IP地址,但是它的返回值是一个4个字节的数组。因此尽管getAddress()在获得IP方面是有用的,但却不适于用来输出。package dns;import ...
  • 域名解析和cdn 原理

    2021-03-17 14:16:18
    2)、浏览器调用域名解析函数库对域名进行解析,以得到此域名对应的IP地址;3)、浏览器使用所得到的IP地址,域名的服务主机发出数据访问请求;4)、浏览器根据域名主机返回的数据显示网页的内容。使用了CDN缓存后的...
  • However, I couldn't figure out a way to do this in Java. The application is in Java 5, running on Linux (Centos 5). 解决方案 Java has some seriously weird dns caching behavior. Your best bet is to ...
  • 域名(Domain Name),是由一串用点分隔的名字组成的Internet上某...一个域名的目的是便于记忆和沟通的一组服务器的地址(网站,电子邮件,FTP等),下面介绍一下Java解析域名获取IP数组方法。Java获取域名下所有Ip地址...
  • 根据这篇文章的分析,Java代码中调用InetAddress.getByName(host)进行域名解析后(可能得到有效解析结果,也可能解析失败),会将结果数据保存到缓存中。当下次域名解析时,如果缓存中数据未过期,可以直接使用缓存...
  • 下载代码代码package org.suyuesheng.spring7.util;...import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern;public class GetDomainName {private String url;...
  • URI uri = URI.create(... String host = uri.getHost(); int port = uri.getPort(); System.out.println(host); System.out.println(port);
  • #if 0//不能解析域名的方式 structsockaddr_in server; server.sin_family=AF_INET; server.sin_addr.s_addr= gethostIPbyname((const char*)ntpServerName); server.sin_port=htons(ntpPort);if(-1 == (int)server....
  • Java实现代码:package online.tools.applet.service.dns;import java.util.ArrayList;import java.util.Hashtable;import java.util.List;import javax.naming.NamingException;import javax.naming.directory....
  • java正则获取域名

    2021-02-12 23:14:24
    Pattern p = Pattern.compile("(?|\\.)[^.]*?... Matcher matcher = p.matcher(url); matcher.find(); System.out.println("域名是:"+matcher.... } } 控制台打印得到: 域名是:csdn.net 完整的域名是:blog.csdn.net
  • 有许多网址, 类似abc.abc.com ,abc.com/abc ,www.abc.com.cn , abc.com.tw ,www.abc.co.uk ,...如何用PHP正则获取所有网址的一级域名?获得结果为 abc.com,abc.com.cn, abc.co.uk?情况...
  • java数字证书解析

    2021-03-09 23:04:41
    package ...import java.io.*;import java.security.*;import java.security.cert.CertificateException;import java.security.cert.CertificateFactory;import java.security.cert.X509Certificate;i...
  • 在广域网中测试时,因为没有固定ip,所以就申请了一个no-ip的动态域名。结果在运行程序时,上面语句中的ip直接换为域名,总是出现connection refused的提示。端口是打开的,可是出现这个提示,就想着是...
  • 域名解析记录在线查询工具:Nslookup检测域名解析真实记录检测域名解析真实记录:A记录,CNAME记录,MX记录,NS记录,TXT记录NSLookup可以指定查询的类型,可以查到DNS记录的生存时间还可以指定使用那个DNS服务器进行...
  • } } #泛域名解析 server { listen 80; server_name *.web.yuyuyun.cn; location / { # 泛域名开始配置 if ( $host ~* (.*)\.(.*)\.(.*)\.(.*) ) { set $domain $1; #获取当前的 域名前缀 } proxy_pass ...
  • java解析DNS的SRV记录

    2021-03-12 22:51:40
    1、导入相应的jar包导入sjava-2.1.6.jar包,今天上传资源有问题,下次传了之后再补充到这里。2、关键代码public static List resoveSrv(String query) {// String s = "ramuh.example.com"; // the inputted string,...
  • 通过JAVA解析IP地址

    2021-02-27 13:23:04
    如何用Java获得一个域名的IP地址呢?提供这个功能的类叫做java.net.InetAddress。我们假设现在有这样一个域名,他用一个静态的 getByName来重新获得一个InetAddress,然后得到能够读出的IP地址。下面的代码是很基本...
  • DNS域名解析过程

    2021-01-21 10:17:26
    我们知道互联网都是通过URL来发布和请求资源的,而URL中的域名需要解析成IP地址才能与远程主机建立连接,如何将域名解析成IP地址就属于DNS解析的工作范畴。 可以毫不夸张地说,虽然我们平时上网感受不到DNS解析的...
  • 前言在介绍域名解析命令前,须要首先理解域名的解析过程,理解解析过程后,能更深入的理解nslookup、dig命令。linux域名解析为何要有域名?假如没有域名,那么访问一个网址,好比百度,须要输入ip,咱们知道输ip麻烦...
  • 在 “域名解析列表” 中,可查看全部已添加的域名。如下图所示: 说明: 若您的域名已在腾讯云注册,则默认添加到 DNS 解析列表。 若您需添加解析的域名未在腾讯云注册,请单击【添加域名】,在弹出的窗口中,根据...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 74,932
精华内容 29,972
关键字:

java域名解析

java 订阅
友情链接: proteltutorial.rar