Guide- Setting up a Hostname

From PINE64
Revision as of 10:39, 30 August 2017 by Ptheven (Talk | contribs) (Setting up a Hostname)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Setting up a Hostname

Preface


Depending on your network configuration, and how often you reboot your Rock 64 or your Router, you might see that the IP Address of the board changes. This is simply the byproduct of the device having a dynamically assigned IP address, most devices on home/small default to that mode.

If you wish to keep logging in or accessing your Board without having to keep track of your IP, there are two strategies. The first is assigning a Hostname to your device, so that even if it's IP address changes in the network, it will still be identifiable (and contactable) via a hostname. The second option is to configure the device to keep its IP address Static.

In this guide, we will be setting up a Hostname.



You'll need to make sure you know the IP address of your device, and be logged in via SSH.


The easiest way to do this is to use a tool called "nmtui". You'll need superuser privileges to invoke this text user interface, so put the following into the terminal and hit enter:


sudo nmtui


Use the arrows key to select "Set System Hostname" and press the tab key to highlight "okay".


Nmtui1.png


Hit enter and you should get a text field to set the hostname of your choice.


Nmtui2.png


Press the tab key to highlight "okay" and hit enter to set your new hostname:


Nmtui3.png


Not all Distros have this tool installed. If you dont have nmtui installed, there is another fairly simple way.




You'll need to edit the file /etc/hostname and to do that, you'll need superuser privilege. Type in:


sudoedit /etc/hostname


Then type in your password and hit enter.


Hostname1.png


It will open a basic text editor, in which you put down the hostname you'd like:


Hostname2.png


Hold down the Control key and Hit X to save and exit, you'll be prompted to save. Press the Y key:


Hostname3.png


Press enter to save the file, dont worry about the filename:


Hostname3.png


You'll need to edit one more file, in a similar way:


sudoedit /etc/hosts


Change the first line to the same hostname you set prior:


Hostname5.png

Save and exit the document the same way: press Control + X, then Y, the Enter to finally save and exit the text editor. To immediately change the hostname without a reboot, you'll need to run a script:


sudo /etc/init.d/hostname.sh start


It should take a moment to run and return you to prompt. You should have your hostname changed now, confirm it by typing in "hostname" into the terminal:


Hostname6.png


To login using a hostname instead of an IP Address, you simply put in the hostname followed by a ".local" into your SSH client. This way, it will connect to the server, regardless of what its IP address may be. In this case, my hostname was rock64.


So, instead of doing


ssh [email protected]


I can simply do


ssh [email protected]


Which follows this notation:


ssh [email protected]


Hostname.local.png


Using this method, you will be able to access your board, regardless of what the IP address is.



References

Forum link: https://forum.pine64.org/showthread.php?tid=4868&pid=30220#pid30220