mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
commit
b015d67d08
@ -1,125 +0,0 @@
|
||||
[#]: subject: "How to Set Static IP Address on Ubuntu Server 22.04"
|
||||
[#]: via: "https://www.linuxtechi.com/static-ip-address-on-ubuntu-server/"
|
||||
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
How to Set Static IP Address on Ubuntu Server 22.04
|
||||
======
|
||||
In this post, we will cover how to set static ip address on Ubuntu server 22.04.
|
||||
|
||||
It is highly recommended to have a static ip on linux server because it would be persistent across the reboot. Static IP plays an important role for servers like Mail Server, Web Server and File server etc.
|
||||
|
||||
##### Prerequisites
|
||||
|
||||
* Minimal Installed Ubuntu Server 22.04
|
||||
* Regular User with sudo admin rights
|
||||
|
||||
In Ubuntu server 22.04, networking is controlled by netplan utility, so we will use netplan to configure static ip address on Ubuntu server.
|
||||
|
||||
Note: we cannot use [nmcli utiltity][1] as it is not the part of default installation on Ubuntu server.
|
||||
|
||||
### Setting up Static IP address on Ubuntu Server 22.04
|
||||
|
||||
Login to your Ubuntu server 22.04, look for the netplan configuration file. It is located under /etc/netplan directory.
|
||||
|
||||
```
|
||||
$ cd /etc/netplan/
|
||||
$ ls -l
|
||||
total 4
|
||||
-rw-r--r-- 1 root root 116 Oct 12 04:03 00-installer-config.yaml
|
||||
$
|
||||
```
|
||||
|
||||
Run below cat command to view the contents of ‘00-installer-config.yaml’
|
||||
|
||||
Note: Name of configuration file may differ as your per setup. As it is an yaml file, so make sure to maintain the indentation and syntax while editing.
|
||||
|
||||
```
|
||||
$ cat 00-installer-config.yaml
|
||||
```
|
||||
|
||||
Output,
|
||||
|
||||
![Default-Content-netplan-ubuntu-server][2]
|
||||
|
||||
As per above output, it says that we have ens33 interface and it is getting ip from dhcp server. Alternate way to view interface name is via ip command.
|
||||
|
||||
Now, to configure static ip in place of dhcp, edit netplan configuration file using vi or nano editor and add the following content.
|
||||
|
||||
```
|
||||
$ sudo vi 00-installer-config.yaml
|
||||
# This is the network config written by 'subiquity'
|
||||
network:
|
||||
renderer: networkd
|
||||
ethernets:
|
||||
ens33:
|
||||
addresses:
|
||||
- 192.168.1.247/24
|
||||
nameservers:
|
||||
addresses: [4.2.2.2, 8.8.8.8]
|
||||
routes:
|
||||
- to: default
|
||||
via: 192.168.1.1
|
||||
version: 2
|
||||
```
|
||||
|
||||
save and close the file.
|
||||
|
||||
![Updated-Netplan-Config-File-Content-Ubuntu-Server][3]
|
||||
|
||||
In the above file we have used following,
|
||||
|
||||
* ens33 is the interface name
|
||||
* addresses are used to set the static ip
|
||||
* nameservers used to specify the DNS server ips
|
||||
* routes used to specify the default gateway
|
||||
|
||||
Note: Change the IP details and interface name as per your environment.
|
||||
|
||||
To make above changes into the effect the apply these changes using following netplan command,
|
||||
|
||||
```
|
||||
$ sudo netplan apply
|
||||
```
|
||||
|
||||
Run following ip command to view the ip address on interface,
|
||||
|
||||
```
|
||||
$ ip addr show ens33
|
||||
```
|
||||
|
||||
To view the default route, run
|
||||
|
||||
```
|
||||
$ ip route show
|
||||
```
|
||||
|
||||
Output of above commands,
|
||||
|
||||
![ip-addr-route-command-output-ubuntu-server][4]
|
||||
|
||||
Perfect, above commands’ output confirms that static ip and route has been configured successfully.
|
||||
|
||||
That’s all from this post. Kindly do post your queries and feedback in below comments section.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxtechi.com/static-ip-address-on-ubuntu-server/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linuxtechi.com/author/pradeep/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.linuxtechi.com/configure-ip-with-nmcli-command-linux/
|
||||
[2]: https://www.linuxtechi.com/wp-content/uploads/2022/10/Default-Content-netplan-ubuntu-server.png
|
||||
[3]: https://www.linuxtechi.com/wp-content/uploads/2022/10/Updated-Netplan-Config-File-Content-Ubuntu-Server.png
|
||||
[4]: https://www.linuxtechi.com/wp-content/uploads/2022/10/ip-addr-route-command-output-ubuntu-server.png
|
@ -0,0 +1,125 @@
|
||||
[#]: subject: "How to Set Static IP Address on Ubuntu Server 22.04"
|
||||
[#]: via: "https://www.linuxtechi.com/static-ip-address-on-ubuntu-server/"
|
||||
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
如何在 Ubuntu Server 22.04 上设置静态 IP 地址
|
||||
======
|
||||
在这篇文章中,我们将介绍如何在 Ubuntu Server 22.04 上设置静态 IP 地址。
|
||||
|
||||
强烈建议在 linux 服务器上使用静态 ip,因为它会在重启后保持不变。静态 IP 对邮件服务器、Web 服务器和文件服务器等服务器起着重要作用。
|
||||
|
||||
##### 先决条件
|
||||
|
||||
* 最小安装的 Ubuntu Server 22.04
|
||||
* 具有 sudo 管理员权限的普通用户
|
||||
|
||||
在 Ubuntu Server 22.04 中,网络由 netplan 程序控制,因此我们将使用 netplan 在 Ubuntu Server 上配置静态 IP 地址。
|
||||
|
||||
注意:我们不能使用 [nmcli 程序][1],因为它不是 Ubuntu Server 上默认安装的一部分。
|
||||
|
||||
### 在 Ubuntu Server 22.04 上设置静态 IP 地址
|
||||
|
||||
登录到你的 Ubuntu Server 22.04,查找 netplan 配置文件。它位于 /etc/netplan 目录下。
|
||||
|
||||
```
|
||||
$ cd /etc/netplan/
|
||||
$ ls -l
|
||||
total 4
|
||||
-rw-r--r-- 1 root root 116 Oct 12 04:03 00-installer-config.yaml
|
||||
$
|
||||
```
|
||||
|
||||
运行以下 cat 命令以查看 “00-installer-config.yaml” 的内容
|
||||
|
||||
注意:配置文件的名称可能因你的设置而异。由于它是一个 yaml 文件,因此请确保在编辑时保持缩进和语法。
|
||||
|
||||
```
|
||||
$ cat 00-installer-config.yaml
|
||||
```
|
||||
|
||||
输出:
|
||||
|
||||
![Default-Content-netplan-ubuntu-server][2]
|
||||
|
||||
根据上面的输出,它说我们有 ens33 接口,它正在从 dhcp 服务器获取 ip。查看接口名称的另一种方法是通过 ip 命令。
|
||||
|
||||
现在,要配置静态 ip 代替 dhcp,使用 vi 或 nano 编辑器编辑 netplan 配置文件并添加以下内容。
|
||||
|
||||
```
|
||||
$ sudo vi 00-installer-config.yaml
|
||||
# This is the network config written by 'subiquity'
|
||||
network:
|
||||
renderer: networkd
|
||||
ethernets:
|
||||
ens33:
|
||||
addresses:
|
||||
- 192.168.1.247/24
|
||||
nameservers:
|
||||
addresses: [4.2.2.2, 8.8.8.8]
|
||||
routes:
|
||||
- to: default
|
||||
via: 192.168.1.1
|
||||
version: 2
|
||||
```
|
||||
|
||||
保存并关闭文件。
|
||||
|
||||
![Updated-Netplan-Config-File-Content-Ubuntu-Server][3]
|
||||
|
||||
在上面的文件中,我们使用了以下内容,
|
||||
|
||||
* ens33 为接口名称
|
||||
* 用于设置静态 ip 的地址
|
||||
* nameservers 用于指定 DNS 服务器的 ip
|
||||
* 用于指定默认网关的路由
|
||||
|
||||
注意:根据你的环境更改 IP 详细信息和接口名称。
|
||||
|
||||
要是上述修改生效,请使用以下 netplan 命令应用这些更改:
|
||||
|
||||
```
|
||||
$ sudo netplan apply
|
||||
```
|
||||
|
||||
运行以下 ip 命令查看接口上的 ip 地址:
|
||||
|
||||
```
|
||||
$ ip addr show ens33
|
||||
```
|
||||
|
||||
要查看默认路由,请运行:
|
||||
|
||||
```
|
||||
$ ip route show
|
||||
```
|
||||
|
||||
上述命令的输出。
|
||||
|
||||
![ip-addr-route-command-output-ubuntu-server][4]
|
||||
|
||||
完美,以上命令的输出确认静态ip和路由配置成功。
|
||||
|
||||
这就是这篇文章的全部内容。请在下面的评论部分发表你的问题和反馈。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.linuxtechi.com/static-ip-address-on-ubuntu-server/
|
||||
|
||||
作者:[Pradeep Kumar][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://www.linuxtechi.com/author/pradeep/
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://www.linuxtechi.com/configure-ip-with-nmcli-command-linux/
|
||||
[2]: https://www.linuxtechi.com/wp-content/uploads/2022/10/Default-Content-netplan-ubuntu-server.png
|
||||
[3]: https://www.linuxtechi.com/wp-content/uploads/2022/10/Updated-Netplan-Config-File-Content-Ubuntu-Server.png
|
||||
[4]: https://www.linuxtechi.com/wp-content/uploads/2022/10/ip-addr-route-command-output-ubuntu-server.png
|
Loading…
Reference in New Issue
Block a user