How to generate an unique ID for a given linux machine? - linux

My python application running as a daemon in a variety of linux distributions are trying to register to my server using the machine's IP Address and FQDN Hostname(given by "hostname -f" command) as a primary key.
Now I am facing a problem when two machines are having same hostname and IP Address. Eg in case of two VM's running on two seperate machines, the hostname is "localhost.localdomain" and Ip Address is "192.168.0.2" for both of them.
Is there any unique way to differentitate any two machines. (Maybe some other third parameter which will guarantee uniqueness across any linux machine )

the MAC address should be unique per network interface.
maybe you can try a combination of IP, MAC and host name?
another option is to create a UUID and save it on the machine.

Related

Which kind of network should i choose to setup a Satndalone Spark Cluster

I have 2 PC (with Windows as default OS), let's say PC_master and PC_slave. Since it is recommended to work with Linux to manage a spark Cluster i created one Virtual Machines with Linux on each of theses PC: VM_master on PC_master and VM_slave on PC_slave.
I would like to setup a Standalone Spark Cluster, so which Networking configuration should i use (NAT, Bridge, HostOnly?) for theses 2VM in order that they own their private IP adress letting me ssh from one to another without the need of port forwarding ?
Edit: My two laptop are linked to the same box, so they have private IP and supposed to be linked to the same router.
Finally it seems that if i want to give each VM its own Ip adress to create a private Network i have to choose Bridge Network which will assign a unique Ip for each VM!

Mimic FQDN on a home machine not on a domain

I have a home PC running Windows 10, no domain controller, and therefore by default I do not have a FQDN for the machine.
I am trying to setup some server software for testing purposes, and it requires that I use a FQDN.
How can I manipulate my hosts file to mimic a FQDN?
Extra info, please let me know in comments if you need more.
There will be no other machines trying to access this other than the machine I am running the software on (my home PC)
I also think that my IP address is not static.
I believe you can just add a host entry corresponding to the IP address of your machine to all machines that need to address it using its FQDN. The hosts file can be found in System32\Drivers\etc. Just add an entry with your IP and the host to it, for example 192.168.0.1 mymachine.local.
Another option would be setting up your own DNS server which is relatively harder. The biggest problem is presented by you not having a static IP address, you should either set a static IP or configure your DHCP server to reserve an IP for you based on your adapter's MAC address.

Linux & Virtual machine

Is it possible to create different Linux OS in Virtual Box and set different IP address and ping one host through the other?
I configured 2 Linux running on Virtual box with different IP address but when I ping the other one i get no answer.
Yes it's possible, what i can recommend you is to connect the virtual machines in bridge mode so each machine has a ip and is shared with your host machine
Yes is very possible.
There is several ways to achive this. One is use "Bridged Networkin".
You can see more hereVirtual Box - Network configuration
It should work as #Arthur85 said, set the vms into bridge mode. If it does not work, then check whether they are in the same subnet. If it does not work even in the same subnet, check the iptable rules.

How to generate a host unique ID?

I have several applications which works together and need to communicate.
These applications can be installed on different host, which can be in different local networks, but all are connected together via a global network.
The host can be Linux (CenOS, Debian, Ubuntu) or Windows (7/10).
Now, I need to identify which host is running an application.
The requirements are :
- every application running on the same host have the same "host ID"
- every "host ID" is unique among all hosts
Since the host can be physical machines, virtual machines or even docker instances, I don't think I can use the hostname as a "global unique ID".
Since the host can be in different local networks, I don't think I can use local IP address as a "global unique ID".
So, which data can I use ? Maybe the Network adapter MAC address ? Is it
guaranteed to be unique, even between multiple instances of the same docker ?
Thanks.
On modern / recent Linux distro, linux generates for you a unique id in the /etc/machine-id file when the system is created the first time. Some distributed services such as etcd rely on this file to identify machines in a cluster.
Nothing prevents you from creating and persisting on disk something like a uuid. You can use uuidgen command on Linux for that.
You can say the MAC address is unique. However, if you are concerned about security, do not use the MAC address. The MAC address can be spoofed easily.
To generate a unique ID for the machine, you can use a combination of many items such as MAC Address, IP Address, hostname etc., throw in a random salt and take a sha256 hash of them. Since the host can run on many operating system, I would suggest against using any OS-specific parameters.
Without going into too much detail, the chances of finding a collision in sha256 is improbable to say the least.
You can see the SHA256 of different text here.
http://www.xorbin.com/tools/sha256-hash-calculator
Almost every programming language, these days, has a function/API for creating a SHA256 hash.
Looks like /var/lib/dbus/machine-id contains what you need.
read more here: http://man7.org/linux/man-pages/man5/machine-id.5.html
On linux I solved my problem just by changing the contents of the /var/lib/dbus/machine-id file

SSH to Raspberry Pi with same IP but interchangeable OS?

I have a Raspberry Pi which I run with two different Operating Systems by booting up with different SD cards. This RPi has a static internal IP address (and the same iface mac address), as both Operating Systems have a public IP whenever they are running, allowing me to SSH from work.
The problem is that I can only SSH into one Operating System given that my known_hosts only recognises one key per host, so I would have to delete each time the known_hosts entry whenever the Operating System/SD card changes.
I've created two different RSA keys for each system, and on my local machine under ~.ssh/config given each Host an alias and corresponding IdentifyFile key, but I still come across the same issue. I've also created one key for both system and still come across the same issue.
Is there any way/method to SSH into my RPi regardless of the OS without having to delete the key each time from known_hosts?

Resources