I wrote a simple program where you enter ip, and it should issue a host.
import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Scanner; public class Index { public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Введите интерисующий ip:"); String ip = in.nextLine(); InetAddress addr = null; try { addr = InetAddress.getByName(ip); } catch (UnknownHostException e) { e.printStackTrace(); } System.out.println(addr.getCanonicalHostName()); } } If I enter the server ip on which I run this program, I get the host name. If I try to find out the host of another server on the same network, I just get ip.
Therefore, question 2:
- From .getCanonicalHostName () learns the host name.
- Where do I need to register the host name on the linux server so that the code works as it should, maybe you need to specify it somewhere on the DNS server? (In what places is it possible to do this?)