---
title: "Hostname and OS Configuration"
---

# Hostname Changes and Related OS Configuration

This guide covers procedures that are often raised as troubleshooting questions but are really one-time OS configuration tasks — most commonly changing the hostname so it persists across reboots, or replacing the default rules on a custom image.

## Common Hostname Issues

| Issue                                                                           | What to do                                                                                                                                             |
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Hostname reverts to the old value after reboot                                  | The OpenNebula context script `05-hostname` (or `net-15-hostname` on KVM) is still in `/etc/one-context.d/`. Move it to `/root/`.       |
| `hostnamectl set-hostname` reports success but commands still show the old name | Open a new shell, or run `exec bash` — the new name applies to new sessions.                                                                           |
| cPanel still shows the old hostname                                             | cPanel maintains its own hostname store. Update via WHM → Networking Setup → Change Hostname after fixing the OS hostname.                             |
| Hostname change broke service startup                                           | Some services bind to or log the hostname at start. Restart the affected service, or revert the hostname and plan a maintenance window for the change. |

## Changing a Linux Virtual Compute Node's Hostname

A naive `hostname` change does not persist across reboots on E2E Linux nodes — the OpenNebula context package resets the hostname from the original boot configuration. To make the change permanent, you must also move the context-managed hostname script out of its directory.

### Step 1: Log In as Root

[Connect to a Linux node](/docs/myaccount/node/connect-to-node/linux-node) as root.

### Step 2: Check and Change the Hostname

Check the current hostname:

```bash
hostname
```

Apply a new hostname for the running session:

```bash
hostnamectl set-hostname new-hostname
```

### Step 3: Update the Hostname File (CentOS)

Edit `/etc/hostname` and replace the old hostname with the new one:

```bash
vi /etc/hostname
```

### Step 4: Update the `/etc/hosts` File

Edit `/etc/hosts` and update entries that reference the old hostname:

```bash
vi /etc/hosts
```

Save and exit.

### Step 5: Make the Change Permanent

The change so far survives until the next reboot — at which point the OpenNebula context package's `05-hostname` script will overwrite it. To prevent that, move the script out of the context directory:

```bash
cd /etc/one-context.d/
```

List the contents:

```bash
ls -la
```

For most VMs, move `05-hostname`:

```bash
mv 05-hostname /root/
```

For KVM-based servers, the equivalent script is named `net-15-hostname`:

```bash
mv net-15-hostname /root/
```

After the move, the hostname change survives reboots.

## Changing a cPanel Server's Hostname

cPanel keeps its own copy of the hostname. After the steps above:

1. Use [WHM → Networking Setup → Change Hostname](https://docs.cpanel.net/whm/networking-setup/change-hostname/) to update the cPanel-side hostname.
2. Add the following lines to `/etc/sysctl.conf`:

   ```bash
   kernel.hostname = hostname.domainname.com
   kernel.domainname = domainname.com
   ```

3. Apply:

   ```bash
   sysctl -p /etc/sysctl.conf
   ```

## Installing Node.js and npm on CentOS / RHEL

A common follow-up to launching a CentOS or RHEL-compatible node is installing Node.js. Use the package source that matches your OS lifecycle and application requirements. The old Node.js 6.x setup scripts are obsolete and should not be used for new deployments.

**Step 1 — Check the available package stream or repository:**

```bash
dnf module list nodejs
```

**Step 2 — Install Node.js and npm:**

```bash
dnf install -y nodejs npm
```

On older CentOS images that still use `yum`, use the OS-supported repository or an approved NodeSource LTS repository, then install:

```bash
yum install -y nodejs npm
```

**Step 3 — Verify versions:**

```bash
node -v
```

```bash
npm -v
```

**Step 4 — Test the installation:**

Create a test server file:

```bash
vim test_server.js
```

Add the following:

```bash
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Welcome');
}).listen(3001, "127.0.0.1");
console.log('Server running at http://127.0.0.1:3001/');
```

Start the server:

```bash
node test_server.js
```

Expected output:

```bash
Server running at http://127.0.0.1:3001/
```

Access `http://127.0.0.1:3001/` from inside the node to confirm.

## Related Resources

- [Connect to a Linux Node](/docs/myaccount/node/connect-to-node/linux-node)
- [Change Hostname Tutorial](/docs/myaccount/node/troubleshoot/hostname-and-config)
- [Node Not Accessible](./node-not-accessible.md)

---
