hostname command code example Example 1: how to get hostname on linux $ hostnamectl Example 2: get hostname socket.gethostbyname(socket.gethostname())