Posts Tagged ‘Hostname’

Pada contoh ini digunakan method-method yang tersedia dalam kelas java.net.InetAddress. Berikut adalah contoh kelasnya:

package id.co.testing;

import java.net.InetAddress;

public class netUtil {
	public static void main(String[] args) {
		InetAddress ip;
		try {

			// ===================== Informasi localhost ===================
			ip = InetAddress.getLocalHost();
			System.out.println("========= " + "Info Localhost" + " ========");
			System.out.println("\tCurrent IP address \t\t: "
					+ ip.getHostAddress());
			System.out.println("\tCurrent hostname \t\t: " + ip.getHostName());
			System.out.println("\tCurrent canonical hostname \t: "
					+ ip.getCanonicalHostName());

			// ===================== Cari berdasarkan IP Address ===========
			// ip address = 167.205.1.34

			byte[] ipAddr = new byte[] { (byte) 167, (byte) 205, (byte) 1,
					(byte) 34 };
			ip = InetAddress.getByAddress(ipAddr);
			System.out.println();

			System.out.println("========= " + ip.getHostAddress()
					+ " =========");
			System.out.println("\tIP address \t\t: " + ip.getHostAddress());
			System.out.println("\thostname \t\t: " + ip.getHostName());
			System.out.println("\tcanonical hostname \t: "
					+ ip.getCanonicalHostName());

			// ====================== Cari berdasarkan hostname ============
			String host = "www.facebook.com ";
			host = host.trim();
			System.out.println();
			System.out.println("========= " + host + " =========");
			ip = InetAddress.getByName(host);
			System.out.println("\tIP address \t\t: " + ip.getHostAddress());
			System.out.println("\thostname \t\t: " + ip.getHostName());
			System.out.println("\tcanonical hostname \t: "
					+ ip.getCanonicalHostName());

			// ==================== Cari berdasarkan IP Address ============
			host = "152.118.24.181";
			host = host.trim();
			System.out.println();
			System.out.println("========= " + host + " =========");
			ip = InetAddress.getByName(host);
			System.out.println("\tIP address \t\t: " + ip.getHostAddress());
			System.out.println("\thostname \t\t: " + ip.getHostName());
			System.out.println("\tcanonical hostname \t: "
					+ ip.getCanonicalHostName());

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


Berikut adalah contoh output yang dihasilkan kelas tersebut, di tempat Anda kemungkinan besar outputnya berbeda: (more…)

Advertisements

Read Full Post »

Pada Fedora untuk mengatur hostname terdapat utility hostnamectl. Agar perubahan nama host disimpan permanen, sintak umumnya adalah sebagai berikut:

# hostnamectl set-hostname --static “nama_host_baru”

Contohnya:

 1

Ketika login ulang:

2

Read Full Post »