> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man1/hostname.1.md).

# hostname.1

`hostname` — 设置或打印当前主机系统的名称

## 名称

`hostname`

## 概要

`hostname [-f] [-s | -d] [name-of-host]`

## 描述

`hostname` 实用程序打印当前主机的名称。超级用户可以通过提供参数来设置主机名；这通常在初始化脚本 **/etc/rc.d/hostname** 中完成，该脚本通常在启动时运行。此脚本使用 **/etc/rc.conf** 中的 `hostname` 变量。

选项：

**`-f`** 在打印的名称中包含域名信息。这是默认行为。

**`-s`** 从打印的名称中去掉任何域名信息。

**`-d`** 仅打印域名信息。

## 实例

设置机器的主机名并检查结果：

```sh
$ hostname beastie.localdomain.org
$ hostname
beastie.localdomain.org
```

不显示域名信息：

```sh
$ hostname -s
beastie
```

仅显示域名信息：

```sh
$ hostname -d
localdomain.org
```

## 参见

gethostname(3), [rc.conf(5)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man5/rc.conf.5.md)

## 历史

`hostname` 命令首次出现于 4.2BSD。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man1/hostname.1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
