mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
Merge branch 'master' of https://github.com/LCTT/TranslateProject into new
This commit is contained in:
commit
79438d3d9b
@ -0,0 +1,61 @@
|
|||||||
|
Linux 虚拟机与 Linux 现场镜像版
|
||||||
|
======
|
||||||
|
|
||||||
|
> Linux 虚拟机与 Linux 现场镜像版各有优势,也有不足。
|
||||||
|
|
||||||
|
首先我得承认,我非常喜欢频繁尝试新的 [Linux 发行版本][1]。然而,我用来测试它们的方法根据每次目标而有所不同。在这篇文章中,我们来看看两种运行 Linux 的模式:虚拟机或<ruby>现场镜像版<rt>live image</rt></ruby>。每一种方式都存在优势,但是也有一些不足。
|
||||||
|
|
||||||
|
### 首次测试一个全新的 Linux 发行版
|
||||||
|
|
||||||
|
当我首次测试一个全新 Linux 发行版时,我使用的方法很大程度上依赖于我当前所拥有的 PC 资源。如果我使用台式机,我会在一台虚拟机中运行该发行版来测试。使用这种方法的原因是,我可以下载并测试该发行版,不只是在一个现场环境中,而且也可以作为一个带有持久存储的安装的系统。
|
||||||
|
|
||||||
|
另一方面,如果我的 PC 不具备强劲的硬件,那么通过 Linux 的虚拟机安装来测试发行版是适得其反的。我会将那台 PC 压榨到它的极限,诚然,更好的是使用现场版的 Linux 映像,而不是从闪存驱动器中运行。
|
||||||
|
|
||||||
|
### 体验新的 Linux 发行版本的软件
|
||||||
|
|
||||||
|
如果你有兴趣查看发行版本的桌面环境或可用的软件,那使用它的现场镜像版就没错了。一个现场版环境可以提供给你所预期的全局视角、其所提供的软件和用户体验的整体感受。
|
||||||
|
|
||||||
|
公平的说,你也可以在虚拟机上达到同样的效果,但是它有一点不好,如果这么做会让更多数据填满你的磁盘空间。毕竟这只是对发行版的一个简单体验。记得我在第一节说过:我喜欢在虚拟机上运行 Linux 来做测试。用这个方式我就能看到如何去安装它、分区是怎么样的等等,而使用现场镜像版时你就看不到这些。
|
||||||
|
|
||||||
|
这种体验方式通常表明你只想对该发行版本有个大致了解,所以在这种情况下,这种只需要付出最小的精力和时间的方式是一种不错的办法。
|
||||||
|
|
||||||
|
### 随身携带一个发行版
|
||||||
|
|
||||||
|
这种方式虽然不像几年前那样普遍,这种随身携带一个 Linux 发行版的能力也许是出于对某些用户的考虑。显然,虚拟机安装对于便携性并无太多帮助。不过,现场镜像版实际上是十分便携的。现场镜像版可以写入到 DVD 当中或复制到一个闪存盘中而便于携带。
|
||||||
|
|
||||||
|
从 Linux 的便携性这个概念上展开来说,当要在一个朋友的电脑上展示 Linux 如何工作,使用一个闪存盘上的现场镜像版也是很方便的。这可以使你能演示 Linux 如何丰富他们的生活,而不用必须在他们的 PC 上运行一个虚拟机。使用现场镜像版这就有点双赢的感觉了。
|
||||||
|
|
||||||
|
### 选择做双引导 Linux
|
||||||
|
|
||||||
|
这接下来的方式是个大工程。考虑一下,也许你是一个 Windows 用户。你喜欢玩 Linux,但又不愿意冒险。除了在某些情况下会出些状况或者识别个别分区时遇到问题,双引导方式就没啥挑剔的。无论如何,使用 Linux 虚拟机或现场镜像版都对于你来说是一个很好的选择。
|
||||||
|
|
||||||
|
现在,我在某些事情上采取了奇怪的立场。我认为长期在闪存盘上运行现场镜像版要比虚拟机更有价值。这有两个原因。首先,您将会习惯于真正运行 Linux,而不是在 Windows 之上的虚拟机中运行它。其次,您可以设置闪存盘以包含持久存储的用户数据。
|
||||||
|
|
||||||
|
我知道你会说用一个虚拟机运行 Linux 也是如此,然而,使用现场镜像版的方式,你绝不会因为更新而被破坏任何东西。为什么?因为你不会更新你的宿主系统或者客户系统。请记住,有整个 Linux 发行版本被设计为持久存储的 Linux 发行版。Puppy Linux 就是一个非常好的例子。它不仅能运行在要被回收或丢弃的个人 PC 上,它也可以让你永远不被频繁的系统升级所困扰,这要感谢该发行版处理安全更新的方式。这不是一个常规的 Linux 发行版,而是以这样的一种方式封闭了安全问题——即持久存储的现场镜像版中没有什么令人担心的坏东西。
|
||||||
|
|
||||||
|
### Linux 虚拟机绝对是一个最好的选择
|
||||||
|
|
||||||
|
在我结束这篇文章时,让我告诉你。有一种场景下,使用 Virtual Box 等虚拟机绝对比现场镜像版更好:记录 Linux 发行版的桌面环境。
|
||||||
|
|
||||||
|
例如,我制作了一个视频,里面介绍和点评了许多 Linux 发行版。使用现场镜像版进行此操作需要我用硬件设备捕获屏幕,或者从现场镜像版的软件仓库中安装捕获软件。显然,虚拟机比 Linux 发行版的现场镜像版更适合这项工作。
|
||||||
|
|
||||||
|
一旦你需要采集音频进行混音,毫无疑问,如果您要使用软件来捕获您的点评语音,那么您肯定希望拥有一个宿主操作系统,里面包含了一个起码的捕获环境的所有基本需求。同样,您可以使用硬件设备来完成所有这一切,但如果您只是做兼职的视频/音频捕获, 那么这可能要付出成本高昂的代价。
|
||||||
|
|
||||||
|
### Linux 虚拟机 VS. Linux 现场镜像版
|
||||||
|
|
||||||
|
你最喜欢尝试新发行版的方式是哪些?也许,你是那种可以很好地格式化磁盘、将风险置之脑后的人,所以这里说的这些都是没用的?
|
||||||
|
|
||||||
|
我在网上互动的大多数人都倾向于遵循我上面提及的方法,但是我很想知道哪种方式更加适合你。点击评论框,让我知道在体验 Linux 发行版世界最伟大和最新的版本时,您更喜欢哪种方法。
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://www.datamation.com/open-source/linux-virtual-machines-vs-linux-live-images.html
|
||||||
|
|
||||||
|
作者:[Matt Hartley][a]
|
||||||
|
译者:[sober-wang](https://github.com/sober-wang)
|
||||||
|
校对:[wxy](https://github.com/wxy)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]:https://www.datamation.com/author/Matt-Hartley-3080.html
|
||||||
|
[1]:https://www.datamation.com/open-source/best-linux-distro.html
|
@ -0,0 +1,341 @@
|
|||||||
|
如何在 Ubuntu 系统中添加一个辅助 IP 地址
|
||||||
|
======
|
||||||
|
|
||||||
|
Linux 管理员应该意识到这一点,因为这是一项例行任务。很多人想知道为什么我们需要在服务器中添加多个 IP 地址,以及为什么我们需要将它添加到单块网卡中?我说的对吗?
|
||||||
|
|
||||||
|
你可能也会有类似的问题:在 Linux 中如何为单块网卡分配多个 IP 地址?在本文中,你可以得到答案。
|
||||||
|
|
||||||
|
当我们对一个新服务器进行设置时,理想情况下它将有一个 IP 地址,即服务器主 IP 地址,它与服务器主机名对应。
|
||||||
|
|
||||||
|
我们不应在服务器主 IP 地址上托管任何应用程序,这是不可取的。如果要在服务器上托管任何应用程序,我们应该为此添加辅助 IP。
|
||||||
|
|
||||||
|
这是业界的最佳实践,它允许用户安装 SSL 证书。大多数系统都配有单块网卡,这足以添加额外的 IP 地址。
|
||||||
|
|
||||||
|
**建议阅读:**
|
||||||
|
|
||||||
|
- [在 Linux 命令行中 9 种方法检查公共 IP 地址][1]
|
||||||
|
- [在 Linux 终端中 3 种简单的方式来检查 DNS(域名服务器)记录][2]
|
||||||
|
- [在 Linux 上使用 Dig 命令检查 DNS(域名服务器)记录][3]
|
||||||
|
- [在 Linux 上使用 Nslookup 命令检查 DNS(域名服务器)记录][4]
|
||||||
|
- [在 Linux 上使用 Host 命令检查 DNS(域名服务器)记录][5]
|
||||||
|
|
||||||
|
我们可以在同一个接口上添加 IP 地址,或者在同一设备上创建子接口,然后在其中添加 IP。默认情况下,一直到 Ubuntu 14.04 LTS,接口给名称为 `ethX (eth0)`,但是从 Ubuntu 15.10 之后网络接口名称已从 `ethX` 更改为 `enXXXXX`(对于服务器是 ens33,桌面版是 enp0s3)。
|
||||||
|
|
||||||
|
在本文中,我们将教你如何在 Ubuntu 上执行此操作,并且衍生到其它发行版(to 校正:这句自己加的)。
|
||||||
|
|
||||||
|
**注意:**别在 DNS 详细信息后添加 IP 地址。如果是这样,DNS 将无法正常工作。
|
||||||
|
|
||||||
|
### 如何在 Ubuntu 14.04 LTS 中添加临时辅助 IP 地址
|
||||||
|
|
||||||
|
在系统中添加 IP 地址之前,运行以下任一命令即可验证服务器主 IP 地址:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ifconfig
|
||||||
|
或
|
||||||
|
# ip addr
|
||||||
|
|
||||||
|
# ip addr
|
||||||
|
|
||||||
|
eth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36
|
||||||
|
inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0
|
||||||
|
inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link
|
||||||
|
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||||
|
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
|
||||||
|
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
|
||||||
|
collisions:0 txqueuelen:1000
|
||||||
|
RX bytes:902 (902.0 B) TX bytes:16423 (16.4 KB)
|
||||||
|
|
||||||
|
eth1 Link encap:Ethernet HWaddr 08:00:27:6a:cf:d3
|
||||||
|
inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0
|
||||||
|
inet6 addr: fe80::a00:27ff:fe6a:cfd3/64 Scope:Link
|
||||||
|
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||||
|
RX packets:80 errors:0 dropped:0 overruns:0 frame:0
|
||||||
|
TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
|
||||||
|
collisions:0 txqueuelen:1000
|
||||||
|
RX bytes:8698 (8.6 KB) TX bytes:17047 (17.0 KB)
|
||||||
|
|
||||||
|
lo Link encap:Local Loopback
|
||||||
|
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||||
|
inet6 addr: ::1/128 Scope:Host
|
||||||
|
UP LOOPBACK RUNNING MTU:65536 Metric:1
|
||||||
|
RX packets:25 errors:0 dropped:0 overruns:0 frame:0
|
||||||
|
TX packets:25 errors:0 dropped:0 overruns:0 carrier:0
|
||||||
|
collisions:0 txqueuelen:1
|
||||||
|
RX bytes:1730 (1.7 KB) TX bytes:1730 (1.7 KB)
|
||||||
|
```
|
||||||
|
|
||||||
|
如我所见,服务器主 IP 地址是 `192.168.56.150`,我将下一个 IP `192.168.56.151` 作为辅助 IP,使用以下方法完成:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ip addr add 192.168.56.151/24 broadcast 192.168.56.255 dev eth0 label eth0:1
|
||||||
|
```
|
||||||
|
|
||||||
|
输入以下命令以检查新添加的 IP 地址。如果你重新启动服务器,那么新添加的 IP 地址会消失,因为我们的 IP 是临时添加的。
|
||||||
|
|
||||||
|
```
|
||||||
|
# ip addr
|
||||||
|
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
|
||||||
|
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
||||||
|
inet 127.0.0.1/8 scope host lo
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet6 ::1/128 scope host
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
||||||
|
link/ether 08:00:27:98:b7:36 brd ff:ff:ff:ff:ff:ff
|
||||||
|
inet 192.168.56.150/24 brd 192.168.56.255 scope global eth0
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet 192.168.56.151/24 brd 192.168.56.255 scope global secondary eth0:1
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet6 fe80::a00:27ff:fe98:b736/64 scope link
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
||||||
|
link/ether 08:00:27:6a:cf:d3 brd ff:ff:ff:ff:ff:ff
|
||||||
|
inet 10.0.3.15/24 brd 10.0.3.255 scope global eth1
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet6 fe80::a00:27ff:fe6a:cfd3/64 scope link
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
```
|
||||||
|
|
||||||
|
### 如何在 Ubuntu 14.04 LTS 中添加永久辅助 IP 地址
|
||||||
|
|
||||||
|
要在 Ubuntu 系统上添加永久辅助 IP 地址,只需编辑 `/etc/network/interfaces` 文件并添加所需的 IP 详细信息。
|
||||||
|
|
||||||
|
```
|
||||||
|
# vi /etc/network/interfaces
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
# vi /etc/network/interfaces
|
||||||
|
|
||||||
|
# The loopback network interface
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
|
||||||
|
# The primary network interface
|
||||||
|
auto eth0
|
||||||
|
iface eth0 inet static
|
||||||
|
address 192.168.56.150
|
||||||
|
netmask 255.255.255.0
|
||||||
|
network 192.168.56.0
|
||||||
|
broadcast 192.168.56.255
|
||||||
|
gateway 192.168.56.1
|
||||||
|
|
||||||
|
auto eth0:1
|
||||||
|
iface eth0:1 inet static
|
||||||
|
address 192.168.56.151
|
||||||
|
netmask 255.255.255.0
|
||||||
|
```
|
||||||
|
|
||||||
|
保存并关闭文件,然后重启网络接口服务。
|
||||||
|
|
||||||
|
```
|
||||||
|
# service networking restart
|
||||||
|
或
|
||||||
|
# ifdown eth0:1 && ifup eth0:1
|
||||||
|
```
|
||||||
|
|
||||||
|
验证新添加的 IP 地址:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ifconfig
|
||||||
|
eth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36
|
||||||
|
inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0
|
||||||
|
inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link
|
||||||
|
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||||
|
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
|
||||||
|
TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
|
||||||
|
collisions:0 txqueuelen:1000
|
||||||
|
RX bytes:962 (962.0 B) TX bytes:11905 (11.9 KB)
|
||||||
|
|
||||||
|
eth0:1 Link encap:Ethernet HWaddr 08:00:27:98:b7:36
|
||||||
|
inet addr:192.168.56.151 Bcast:192.168.56.255 Mask:255.255.255.0
|
||||||
|
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||||
|
|
||||||
|
eth1 Link encap:Ethernet HWaddr 08:00:27:6a:cf:d3
|
||||||
|
inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0
|
||||||
|
inet6 addr: fe80::a00:27ff:fe6a:cfd3/64 Scope:Link
|
||||||
|
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
||||||
|
RX packets:4924 errors:0 dropped:0 overruns:0 frame:0
|
||||||
|
TX packets:3185 errors:0 dropped:0 overruns:0 carrier:0
|
||||||
|
collisions:0 txqueuelen:1000
|
||||||
|
RX bytes:4037636 (4.0 MB) TX bytes:422516 (422.5 KB)
|
||||||
|
|
||||||
|
lo Link encap:Local Loopback
|
||||||
|
inet addr:127.0.0.1 Mask:255.0.0.0
|
||||||
|
inet6 addr: ::1/128 Scope:Host
|
||||||
|
UP LOOPBACK RUNNING MTU:65536 Metric:1
|
||||||
|
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
|
||||||
|
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
|
||||||
|
collisions:0 txqueuelen:1
|
||||||
|
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 如何在 Ubuntu 16.04 LTS 中临时添加辅助 IP 地址
|
||||||
|
|
||||||
|
正如本文开头所述,网络接口名称从 Ubuntu 15.10 就开始从 ‘ethX’ 更改为 ‘enXXXX’ (enp0s3),所以,替换你的接口名称。
|
||||||
|
|
||||||
|
在执行此操作之前,先检查系统上的 IP 信息:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ifconfig
|
||||||
|
或
|
||||||
|
# ip addr
|
||||||
|
|
||||||
|
enp0s3: flags=4163 mtu 1500
|
||||||
|
inet 192.168.56.201 netmask 255.255.255.0 broadcast 192.168.56.255
|
||||||
|
inet6 fe80::a00:27ff:fe97:132e prefixlen 64 scopeid 0x20
|
||||||
|
ether 08:00:27:97:13:2e txqueuelen 1000 (Ethernet)
|
||||||
|
RX packets 7 bytes 420 (420.0 B)
|
||||||
|
RX errors 0 dropped 0 overruns 0 frame 0
|
||||||
|
TX packets 294 bytes 24747 (24.7 KB)
|
||||||
|
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
||||||
|
|
||||||
|
enp0s8: flags=4163 mtu 1500
|
||||||
|
inet 10.0.3.15 netmask 255.255.255.0 broadcast 10.0.3.255
|
||||||
|
inet6 fe80::344b:6259:4dbe:eabb prefixlen 64 scopeid 0x20
|
||||||
|
ether 08:00:27:12:e8:c1 txqueuelen 1000 (Ethernet)
|
||||||
|
RX packets 1 bytes 590 (590.0 B)
|
||||||
|
RX errors 0 dropped 0 overruns 0 frame 0
|
||||||
|
TX packets 97 bytes 10209 (10.2 KB)
|
||||||
|
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
||||||
|
|
||||||
|
lo: flags=73 mtu 65536
|
||||||
|
inet 127.0.0.1 netmask 255.0.0.0
|
||||||
|
inet6 ::1 prefixlen 128 scopeid 0x10
|
||||||
|
loop txqueuelen 1000 (Local Loopback)
|
||||||
|
RX packets 325 bytes 24046 (24.0 KB)
|
||||||
|
RX errors 0 dropped 0 overruns 0 frame 0
|
||||||
|
TX packets 325 bytes 24046 (24.0 KB)
|
||||||
|
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
||||||
|
```
|
||||||
|
|
||||||
|
如我所见,服务器主 IP 地址是 `192.168.56.201`,所以,我将下一个 IP `192.168.56.202` 作为辅助 IP,使用以下命令完成。
|
||||||
|
|
||||||
|
```
|
||||||
|
# ip addr add 192.168.56.202/24 broadcast 192.168.56.255 dev enp0s3
|
||||||
|
```
|
||||||
|
|
||||||
|
运行以下命令来检查是否已分配了新的 IP。当你重启机器时,它会消失。
|
||||||
|
|
||||||
|
```
|
||||||
|
# ip addr
|
||||||
|
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
|
||||||
|
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
||||||
|
inet 127.0.0.1/8 scope host lo
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet6 ::1/128 scope host
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
||||||
|
link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff
|
||||||
|
inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet6 fe80::a00:27ff:fe97:132e/64 scope link
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
||||||
|
link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff
|
||||||
|
inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8
|
||||||
|
valid_lft 86353sec preferred_lft 86353sec
|
||||||
|
inet6 fe80::344b:6259:4dbe:eabb/64 scope link
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
```
|
||||||
|
|
||||||
|
### 如何在 Ubuntu 16.04 LTS 中添加永久辅助 IP 地址
|
||||||
|
|
||||||
|
要在 Ubuntu 系统上添加永久辅助 IP 地址,只需编辑 `/etc/network/interfaces` 文件并添加所需 IP 的详细信息。
|
||||||
|
|
||||||
|
我们不应该在 `dns-nameservers` 行之后添加辅助 IP 地址,因为它不会起作用,应该以下面的格式添加 IP 详情。
|
||||||
|
|
||||||
|
此外,我们不需要添加子接口(我们之前在 Ubuntu 14.04 LTS 中的做法):
|
||||||
|
|
||||||
|
```
|
||||||
|
# vi /etc/network/interfaces
|
||||||
|
|
||||||
|
# interfaces(5) file used by ifup(8) and ifdown(8)
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
|
||||||
|
# The primary network interface
|
||||||
|
auto enp0s3
|
||||||
|
iface enp0s3 inet static
|
||||||
|
address 192.168.56.201
|
||||||
|
netmask 255.255.255.0
|
||||||
|
|
||||||
|
iface enp0s3 inet static
|
||||||
|
address 192.168.56.202
|
||||||
|
netmask 255.255.255.0
|
||||||
|
|
||||||
|
gateway 192.168.56.1
|
||||||
|
network 192.168.56.0
|
||||||
|
broadcast 192.168.56.255
|
||||||
|
dns-nameservers 8.8.8.8 8.8.4.4
|
||||||
|
dns-search 2daygeek.local
|
||||||
|
```
|
||||||
|
|
||||||
|
保存并关闭文件,然后重启网络接口服务:
|
||||||
|
|
||||||
|
```
|
||||||
|
# systemctl restart networking
|
||||||
|
或
|
||||||
|
# ifdown enp0s3 && ifup enp0s3
|
||||||
|
```
|
||||||
|
|
||||||
|
运行以下命令来检查是否已经分配了新的 IP:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ip addr
|
||||||
|
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
|
||||||
|
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
||||||
|
inet 127.0.0.1/8 scope host lo
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet6 ::1/128 scope host
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
||||||
|
link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff
|
||||||
|
inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
inet6 fe80::a00:27ff:fe97:132e/64 scope link
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
||||||
|
link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff
|
||||||
|
inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8
|
||||||
|
valid_lft 86353sec preferred_lft 86353sec
|
||||||
|
inet6 fe80::344b:6259:4dbe:eabb/64 scope link
|
||||||
|
valid_lft forever preferred_lft forever
|
||||||
|
```
|
||||||
|
|
||||||
|
让我来 ping 一下新 IP 地址:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ping 192.168.56.202 -c 4
|
||||||
|
PING 192.168.56.202 (192.168.56.202) 56(84) bytes of data.
|
||||||
|
64 bytes from 192.168.56.202: icmp_seq=1 ttl=64 time=0.019 ms
|
||||||
|
64 bytes from 192.168.56.202: icmp_seq=2 ttl=64 time=0.087 ms
|
||||||
|
64 bytes from 192.168.56.202: icmp_seq=3 ttl=64 time=0.034 ms
|
||||||
|
64 bytes from 192.168.56.202: icmp_seq=4 ttl=64 time=0.042 ms
|
||||||
|
|
||||||
|
--- 192.168.56.202 ping statistics ---
|
||||||
|
4 packets transmitted, 4 received, 0% packet loss, time 3068ms
|
||||||
|
rtt min/avg/max/mdev = 0.019/0.045/0.087/0.026 ms
|
||||||
|
```
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://www.2daygeek.com/how-to-add-additional-ip-secondary-ip-in-ubuntu-debian-system/
|
||||||
|
|
||||||
|
作者:[Prakash Subramanian][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[MjSeven](https://github.com/MjSeven)
|
||||||
|
校对:[wxy](https://github.com/wxy)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]:https://www.2daygeek.com/author/prakash/
|
||||||
|
[1]:https://www.2daygeek.com/check-find-server-public-ip-address-linux/
|
||||||
|
[2]:https://www.2daygeek.com/check-find-dns-records-of-domain-in-linux-terminal/
|
||||||
|
[3]:https://www.2daygeek.com/dig-command-check-find-dns-records-lookup-linux/
|
||||||
|
[4]:https://www.2daygeek.com/nslookup-command-check-find-dns-records-lookup-linux/
|
||||||
|
[5]:https://www.2daygeek.com/host-command-check-find-dns-records-lookup-linux/
|
@ -3,86 +3,85 @@
|
|||||||
|
|
||||||
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Switch-Between-TTYs-720x340.png)
|
![](https://www.ostechnix.com/wp-content/uploads/2018/08/Switch-Between-TTYs-720x340.png)
|
||||||
|
|
||||||
本简要指南介绍了在类 Unix 操作系统中如何在不使用功能键的情况下切换 TTY。在进一步讨论之前,我们将了解 TTY 是什么。正如在 AskUbuntu 论坛的一个[**答案**][1]中所提到的,**TTY**这个词来自 **T**ele **TY** pewriter。在 Unix 的早期,连接到计算机的用户终端就是机电电传机或电传打字机(简称 tty)。从那时起,TTY 这个名称继续用于纯文本控制台。如今,所有文本控制台都代表虚拟控制台,而不是物理控制台。TTY 命令打印连接到标准输入的终端的文件名。
|
本简要指南介绍了在类 Unix 操作系统中如何在不使用功能键的情况下切换 TTY。在进一步讨论之前,我们将了解 TTY 是什么。正如在 AskUbuntu 论坛的一个[答案][1]中所提到的,**TTY**这个词来自 **T**ele**TY**pewriter(电传打字机)。在 Unix 的早期,连接到计算机的用户终端就是机电的电传机或电传打字机(简称 tty)。从那时起,TTY 这个名称继续用于纯文本控制台。如今,所有文本控制台都代表虚拟控制台,而不是物理控制台。TTY 命令打印连接到标准输入的终端的文件名。
|
||||||
|
|
||||||
### 在 Linux 中切换 TTY
|
### 在 Linux 中切换 TTY
|
||||||
|
|
||||||
默认情况下,Linux 中有 7 个 tty。它们被称为 tty1、tty2。。。tty7。1 到 6 tty 只是命令行。第 7 个 tty 是 GUI(你的 X 桌面会话)。你可以使用 **CTRL+ALT+Fn** 键在不同的 TTY 之间切换。例如,要切换到 tty1,我们按下 CTRL+ALT+F1。这就是 tty1 在 Ubuntu 18.04 LTS 服务器中的样子。
|
默认情况下,Linux 中有 7 个 tty。它们被称为 tty1、tty2……tty7。1 到 6 的 tty 只是命令行。第 7 个 tty 是 GUI(你的 X 桌面会话)。你可以使用 `CTRL+ALT+Fn` 键在不同的 TTY 之间切换。例如,要切换到 tty1,我们按下 `CTRL+ALT+F1`。这就是 tty1 在 Ubuntu 18.04 LTS 服务器中的样子。
|
||||||
|
|
||||||
![](https://www.ostechnix.com/wp-content/uploads/2018/08/tty1.png)
|
![](https://www.ostechnix.com/wp-content/uploads/2018/08/tty1.png)
|
||||||
|
|
||||||
如果你的系统没有 X 会话,
|
如果你的系统没有 X 会话, 只需要按下 `Alt+Fn` 键,不需要按下 `CTRL`。
|
||||||
|
|
||||||
在某些 Linux 版本中(例如,从 Ubuntu 17.10 开始),登录页面开始使用虚拟控制台 1。因此,你需要按 CTRL+ALT+F3 到 CTRL+ALT+F6 来访问虚拟控制台。要返回桌面环境,请在 Ubuntu 17.10 及更高版本上按下 CTRL+ALT+F2 或 CTRL+ALT+F7。
|
在某些 Linux 版本中(例如,从 Ubuntu 17.10 开始),登录屏开始使用 1 号虚拟控制台。因此,你需要按 `CTRL+ALT+F3` 到 `CTRL+ALT+F6` 来访问虚拟控制台。要返回桌面环境,请在 Ubuntu 17.10 及更高版本上按下 `CTRL+ALT+F2` 或 `CTRL+ALT+F7`。
|
||||||
|
|
||||||
目前为止我们看到我们可以使用 CTRL+ALT+功能键(F1-F7)在 TTY 之间轻松切换。但是,如果出于任何原因你不想使用功能键,那么在 Linux 中有一个名为 **“chvt”** 的简单命令。
|
目前为止我们看到我们可以使用 `CTRL+ALT+Fn`(`F1` - `F7`)在 TTY 之间轻松切换。但是,如果出于任何原因你不想使用功能键,那么在 Linux 中有一个名为 `chvt` 的简单命令。
|
||||||
|
|
||||||
“chvt N” 命令让你切换到前台终端 N,这与按 CTRL+ALT+Fn 相同。如果它不存在,则创建相应的屏幕。
|
`chvt N` 命令让你切换到前台终端 N,这与按 `CTRL+ALT+Fn` 相同。如果它不存在,则创建相应的屏幕。
|
||||||
|
|
||||||
|
让我们试试显示当前的 tty:
|
||||||
|
|
||||||
让我们试试打印当前的 tty:
|
|
||||||
```
|
```
|
||||||
$ tty
|
$ tty
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
我的 Ubuntu 18.04 LTS 服务器的示例输出。
|
我的 Ubuntu 18.04 LTS 服务器的示例输出。
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/08/tty-command-output.png)
|
||||||
|
|
||||||
现在让我们切换到 tty2。为此,请输入:
|
现在让我们切换到 tty2。为此,请输入:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo chvt 2
|
$ sudo chvt 2
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
记住你需要在 chvt 命令中使用 “sudo”。
|
记住你需要在 `chvt` 命令一同使用 `sudo`。
|
||||||
|
|
||||||
现在,使用命令检查当前的 tty:
|
现在,使用命令检查当前的 tty:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ tty
|
$ tty
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
你会看到 tty 现在已经改变了。
|
你会看到 tty 现在已经改变了。
|
||||||
|
|
||||||
同样,你可以使用 “sudo chvt 3” 切换到 tty3,使用 “sudo chvt 4” 切换到 tty4 等等。
|
同样,你可以使用 `sudo chvt 3` 切换到 tty3,使用 `sudo chvt 4` 切换到 tty4 等等。
|
||||||
|
|
||||||
当任何一个功能键不起作用时,chvt 命令会很有用。
|
当任何一个功能键不起作用时,`chvt` 命令会很有用。
|
||||||
|
|
||||||
要查看活动虚拟控制台的总数,请运行:
|
要查看活动虚拟控制台的总数,请运行:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ fgconsole
|
$ fgconsole
|
||||||
2
|
2
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
如你所见,我的系统中有两个活动的 VT。
|
如你所见,我的系统中有两个活动的虚拟终端。
|
||||||
|
|
||||||
你可以使用以下命令查看下一个未分配的虚拟终端:
|
你可以使用以下命令查看下一个未分配的虚拟终端:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ fgconsole --next-available
|
$ fgconsole --next-available
|
||||||
3
|
3
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
如果虚拟控制台不是前台控制台,并且它没有打开任何进程来读取或写入,并且未在其屏幕上选择任何文本,则它是未使用的。
|
如果虚拟控制台不是前台控制台,并且它没有打开任何进程来读取或写入,并且未在其屏幕上选择任何文本,则它是未使用的。
|
||||||
|
|
||||||
要移除未使用的 VT,只需键入:
|
要移除未使用的虚拟终端,只需键入:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ deallocvt
|
$ deallocvt
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
上面的命令为所有未使用的虚拟控制台释放内核内存和数据结构。简单地说,此命令将释放连接到未使用的虚拟控制台的所有资源。
|
上面的命令为所有未使用的虚拟控制台释放内核内存和数据结构。简单地说,此命令将释放连接到未使用的虚拟控制台的所有资源。
|
||||||
|
|
||||||
有关更多详细信息,请参阅相应命令的手册页。
|
有关更多详细信息,请参阅相应命令的手册页。
|
||||||
|
|
||||||
```
|
```
|
||||||
$ man tty
|
$ man tty
|
||||||
|
|
||||||
$ man chvt
|
$ man chvt
|
||||||
|
|
||||||
$ man fgconsole
|
$ man fgconsole
|
||||||
|
|
||||||
$ man deallocvt
|
$ man deallocvt
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
就是这些了。希望这很有用。还有更多的好东西。敬请关注!
|
就是这些了。希望这很有用。还有更多的好东西。敬请关注!
|
||||||
@ -90,7 +89,6 @@ $ man deallocvt
|
|||||||
干杯!
|
干杯!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
via: https://www.ostechnix.com/how-to-switch-between-ttys-without-using-function-keys-in-linux/
|
via: https://www.ostechnix.com/how-to-switch-between-ttys-without-using-function-keys-in-linux/
|
||||||
@ -98,7 +96,7 @@ via: https://www.ostechnix.com/how-to-switch-between-ttys-without-using-function
|
|||||||
作者:[SK][a]
|
作者:[SK][a]
|
||||||
选题:[lujun9972](https://github.com/lujun9972)
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
译者:[geekpi](https://github.com/geekpi)
|
译者:[geekpi](https://github.com/geekpi)
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
校对:[wxy](https://github.com/wxy)
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
@ -1,3 +1,5 @@
|
|||||||
|
pinewall translating
|
||||||
|
|
||||||
How to analyze your system with perf and Python
|
How to analyze your system with perf and Python
|
||||||
======
|
======
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
pinewall translating
|
||||||
|
|
||||||
Add GUIs to your programs and scripts easily with PySimpleGUI
|
Add GUIs to your programs and scripts easily with PySimpleGUI
|
||||||
======
|
======
|
||||||
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
How to Create a Slideshow of Photos in Ubuntu 18.04 and other Linux Distributions
|
||||||
|
======
|
||||||
|
Creating a slideshow of photos is a matter of a few clicks. Here’s how to make a slideshow of pictures in Ubuntu 18.04 and other Linux distributions.
|
||||||
|
|
||||||
|
![How to create slideshow of photos in Ubuntu Linux][1]
|
||||||
|
|
||||||
|
Imagine yourself in a situation where your friends and family are visiting you and request you to show the pictures of a recent event/trip.
|
||||||
|
|
||||||
|
You have the photos saved on your computers, neatly in a separate folder. You invite everyone near the computer. You go to the folder, click on one of the pictures and start showing them the photos one by one by pressing the arrow keys.
|
||||||
|
|
||||||
|
But that’s tiring! It will be a lot better if those images get changed automatically every few seconds.
|
||||||
|
|
||||||
|
That’s called a slideshow and I am going to show you how to create a slideshow of photos in Ubuntu. This will allow you to loop pictures from a folder and display them in fullscreen mode.
|
||||||
|
|
||||||
|
### Creating photo slideshow in Ubuntu 18.04 and other Linux distributions
|
||||||
|
|
||||||
|
While you could use several image viewers for this purpose, I am going to show you two of the most popular tools that should be available in most distributions.
|
||||||
|
|
||||||
|
#### Method 1: Photo slideshow with GNOME’s default image viewer
|
||||||
|
|
||||||
|
If you are using GNOME in Ubuntu 18.04 or any other distribution, you are in luck. The default image viewer of Gnome, Eye of GNOME, is well capable of displaying the slideshow of pictures in the current folder.
|
||||||
|
|
||||||
|
Just click on one of the pictures and you’ll see the settings option on the top right side of the application menu. It looks like three bars stacked over the top of one another.
|
||||||
|
|
||||||
|
You’ll see several options here. Check the Slideshow box and it will go fullscreen displaying the images.
|
||||||
|
|
||||||
|
![How to create slideshow of photos in Ubuntu Linux][2]
|
||||||
|
|
||||||
|
By default, the images change at an interval of 5 seconds. You can change the slideshow interval by going to the Preferences->Slideshow.
|
||||||
|
|
||||||
|
![change slideshow interval in Ubuntu][3]Changing slideshow interval
|
||||||
|
|
||||||
|
#### Method 2: Photo slideshow with Shotwell Photo Manager
|
||||||
|
|
||||||
|
[Shotwell][4] is a popular [photo management application for Linux][5]. and available for all major Linux distributions.
|
||||||
|
|
||||||
|
If it is not installed already, search for Shotwell in your distribution’s software center and install it.
|
||||||
|
|
||||||
|
Shotwell works slightly different. If you directly open a photo in Shotwell Viewer, you won’t see preferences or options for a slideshow.
|
||||||
|
|
||||||
|
For slideshow and other options, you have to open Shotwell and import the folders containing those pictures. Once you have imported the folder in here, select that folder from left side-pane and then click on View in the menu. You should see the option of Slideshow here. Just click on it to create the slideshow of all the images in the selected folder.
|
||||||
|
|
||||||
|
![How to create slideshow of photos in Ubuntu Linux][6]
|
||||||
|
|
||||||
|
You can also change the slideshow settings. This option is presented when the images are displayed in the full view. Just hover the mouse to the lower bottom and you’ll see a settings option appearing.
|
||||||
|
|
||||||
|
#### It’s easy to create photo slideshow
|
||||||
|
|
||||||
|
As you can see, it’s really simple to create slideshow of photos in Linux. I hope you find this simple tip useful. If you have questions or suggestions, please let me know in the comment section below.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://itsfoss.com/photo-slideshow-ubuntu/
|
||||||
|
|
||||||
|
作者:[Abhishek Prakash][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://itsfoss.com/author/abhishek/
|
||||||
|
[1]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/Create-photos-Slideshow-Linux.png
|
||||||
|
[2]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/create-slideshow-photos-ubuntu-gnome.jpeg
|
||||||
|
[3]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/change-slideshow-interval-gnome-image.jpeg
|
||||||
|
[4]: https://wiki.gnome.org/Apps/Shotwell
|
||||||
|
[5]: https://itsfoss.com/linux-photo-management-software/
|
||||||
|
[6]: https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2018/08/create-slideshow-photos-shotwell.jpeg
|
@ -0,0 +1,268 @@
|
|||||||
|
8 Linux commands for effective process management
|
||||||
|
======
|
||||||
|
|
||||||
|
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/command_line_prompt.png?itok=wbGiJ_yg)
|
||||||
|
|
||||||
|
Generally, an application process' lifecycle has three main states: start, run, and stop. Each state can and should be managed carefully if we want to be competent administrators. These eight commands can be used to manage processes through their lifecycles.
|
||||||
|
|
||||||
|
### Starting a process
|
||||||
|
|
||||||
|
The easiest way to start a process is to type its name at the command line and press Enter. If you want to start an Nginx web server, type **nginx**. Perhaps you just want to check the version.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ nginx
|
||||||
|
|
||||||
|
alan@workstation:~$ nginx -v
|
||||||
|
nginx version: nginx/1.14.0
|
||||||
|
```
|
||||||
|
|
||||||
|
### Viewing your executable path
|
||||||
|
|
||||||
|
The above demonstration of starting a process assumes the executable file is located in your executable path. Understanding this path is key to reliably starting and managing a process. Administrators often customize this path for their desired purpose. You can view your executable path using **echo $PATH**.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ echo $PATH
|
||||||
|
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
#### WHICH
|
||||||
|
|
||||||
|
Use the which command to view the full path of an executable file.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ which nginx
|
||||||
|
/opt/nginx/bin/nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
I will use the popular web server software Nginx for my examples. Let's assume that Nginx is installed. If the command **which nginx** returns nothing, then Nginx was not found because which searches only your defined executable path. There are three ways to remedy a situation where a process cannot be started simply by name. The first is to type the full path. Although, I'd rather not have to type all of that, would you?
|
||||||
|
```
|
||||||
|
alan@workstation:~$ /home/alan/web/prod/nginx/sbin/nginx -v
|
||||||
|
nginx version: nginx/1.14.0
|
||||||
|
```
|
||||||
|
|
||||||
|
The second solution would be to install the application in a directory in your executable's path. However, this may not be possible, particularly if you don't have root privileges.
|
||||||
|
|
||||||
|
The third solution is to update your executable path environment variable to include the directory where the specific application you want to use is installed. This solution is shell-dependent. For example, Bash users would need to edit the PATH= line in their .bashrc file.
|
||||||
|
```
|
||||||
|
PATH="$HOME/web/prod/nginx/sbin:$PATH"
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, repeat your echo and which commands or try to check the version. Much easier!
|
||||||
|
```
|
||||||
|
alan@workstation:~$ echo $PATH
|
||||||
|
/home/alan/web/prod/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
|
||||||
|
|
||||||
|
alan@workstation:~$ which nginx
|
||||||
|
/home/alan/web/prod/nginx/sbin/nginx
|
||||||
|
|
||||||
|
alan@workstation:~$ nginx -v
|
||||||
|
nginx version: nginx/1.14.0
|
||||||
|
```
|
||||||
|
|
||||||
|
### Keeping a process running
|
||||||
|
|
||||||
|
#### NOHUP
|
||||||
|
|
||||||
|
A process may not continue to run when you log out or close your terminal. This special case can be avoided by preceding the command you want to run with the nohup command. Also, appending an ampersand (&) will send the process to the background and allow you to continue using the terminal. For example, suppose you want to run myprogram.sh.
|
||||||
|
```
|
||||||
|
nohup myprogram.sh &
|
||||||
|
```
|
||||||
|
|
||||||
|
One nice thing nohup does is return the running process's PID. I'll talk more about the PID next.
|
||||||
|
|
||||||
|
### Manage a running process
|
||||||
|
|
||||||
|
Each process is given a unique process identification number (PID). This number is what we use to manage each process. We can also use the process name, as I'll demonstrate below. There are several commands that can check the status of a running process. Let's take a quick look at these.
|
||||||
|
|
||||||
|
#### PS
|
||||||
|
|
||||||
|
The most common is ps. The default output of ps is a simple list of the processes running in your current terminal. As you can see below, the first column contains the PID.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ ps
|
||||||
|
PID TTY TIME CMD
|
||||||
|
23989 pts/0 00:00:00 bash
|
||||||
|
24148 pts/0 00:00:00 ps
|
||||||
|
```
|
||||||
|
|
||||||
|
I'd like to view the Nginx process I started earlier. To do this, I tell ps to show me every running process ( **-e** ) and a full listing ( **-f** ).
|
||||||
|
```
|
||||||
|
alan@workstation:~$ ps -ef
|
||||||
|
UID PID PPID C STIME TTY TIME CMD
|
||||||
|
root 1 0 0 Aug18 ? 00:00:10 /sbin/init splash
|
||||||
|
root 2 0 0 Aug18 ? 00:00:00 [kthreadd]
|
||||||
|
root 4 2 0 Aug18 ? 00:00:00 [kworker/0:0H]
|
||||||
|
root 6 2 0 Aug18 ? 00:00:00 [mm_percpu_wq]
|
||||||
|
root 7 2 0 Aug18 ? 00:00:00 [ksoftirqd/0]
|
||||||
|
root 8 2 0 Aug18 ? 00:00:20 [rcu_sched]
|
||||||
|
root 9 2 0 Aug18 ? 00:00:00 [rcu_bh]
|
||||||
|
root 10 2 0 Aug18 ? 00:00:00 [migration/0]
|
||||||
|
root 11 2 0 Aug18 ? 00:00:00 [watchdog/0]
|
||||||
|
root 12 2 0 Aug18 ? 00:00:00 [cpuhp/0]
|
||||||
|
root 13 2 0 Aug18 ? 00:00:00 [cpuhp/1]
|
||||||
|
root 14 2 0 Aug18 ? 00:00:00 [watchdog/1]
|
||||||
|
root 15 2 0 Aug18 ? 00:00:00 [migration/1]
|
||||||
|
root 16 2 0 Aug18 ? 00:00:00 [ksoftirqd/1]
|
||||||
|
alan 20506 20496 0 10:39 pts/0 00:00:00 bash
|
||||||
|
alan 20520 1454 0 10:39 ? 00:00:00 nginx: master process nginx
|
||||||
|
alan 20521 20520 0 10:39 ? 00:00:00 nginx: worker process
|
||||||
|
alan 20526 20506 0 10:39 pts/0 00:00:00 man ps
|
||||||
|
alan 20536 20526 0 10:39 pts/0 00:00:00 pager
|
||||||
|
alan 20564 20496 0 10:40 pts/1 00:00:00 bash
|
||||||
|
```
|
||||||
|
|
||||||
|
You can see the Nginx processes in the output of the ps command above. The command displayed almost 300 lines, but I shortened it for this illustration. As you can imagine, trying to handle 300 lines of process information is a bit messy. We can pipe this output to grep to filter out nginx.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ ps -ef |grep nginx
|
||||||
|
alan 20520 1454 0 10:39 ? 00:00:00 nginx: master process nginx
|
||||||
|
alan 20521 20520 0 10:39 ? 00:00:00 nginx: worker process
|
||||||
|
```
|
||||||
|
|
||||||
|
That's better. We can quickly see that Nginx has PIDs of 20520 and 20521.
|
||||||
|
|
||||||
|
#### PGREP
|
||||||
|
|
||||||
|
The pgrep command was created to further simplify things by removing the need to call grep separately.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ pgrep nginx
|
||||||
|
20520
|
||||||
|
20521
|
||||||
|
```
|
||||||
|
|
||||||
|
Suppose you are in a hosting environment where multiple users are running several different instances of Nginx. You can exclude others from the output with the **-u** option.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ pgrep -u alan nginx
|
||||||
|
20520
|
||||||
|
20521
|
||||||
|
```
|
||||||
|
|
||||||
|
#### PIDOF
|
||||||
|
|
||||||
|
Another nifty one is pidof. This command will check the PID of a specific binary even if another process with the same name is running. To set up an example, I copied my Nginx to a second directory and started it with the prefix set accordingly. In real life, this instance could be in a different location, such as a directory owned by a different user. If I run both Nginx instances, the **ps -ef** output shows all their processes.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ ps -ef |grep nginx
|
||||||
|
alan 20881 1454 0 11:18 ? 00:00:00 nginx: master process ./nginx -p /home/alan/web/prod/nginxsec
|
||||||
|
alan 20882 20881 0 11:18 ? 00:00:00 nginx: worker process
|
||||||
|
alan 20895 1454 0 11:19 ? 00:00:00 nginx: master process nginx
|
||||||
|
alan 20896 20895 0 11:19 ? 00:00:00 nginx: worker process
|
||||||
|
```
|
||||||
|
|
||||||
|
Using grep or pgrep will show PID numbers, but we may not be able to discern which instance is which.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ pgrep nginx
|
||||||
|
20881
|
||||||
|
20882
|
||||||
|
20895
|
||||||
|
20896
|
||||||
|
```
|
||||||
|
|
||||||
|
The pidof command can be used to determine the PID of each specific Nginx instance.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ pidof /home/alan/web/prod/nginxsec/sbin/nginx
|
||||||
|
20882 20881
|
||||||
|
|
||||||
|
alan@workstation:~$ pidof /home/alan/web/prod/nginx/sbin/nginx
|
||||||
|
20896 20895
|
||||||
|
```
|
||||||
|
|
||||||
|
#### TOP
|
||||||
|
|
||||||
|
The top command has been around a long time and is very useful for viewing details of running processes and quickly identifying issues such as memory hogs. Its default view is shown below.
|
||||||
|
```
|
||||||
|
top - 11:56:28 up 1 day, 13:37, 1 user, load average: 0.09, 0.04, 0.03
|
||||||
|
Tasks: 292 total, 3 running, 225 sleeping, 0 stopped, 0 zombie
|
||||||
|
%Cpu(s): 0.1 us, 0.2 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
|
||||||
|
KiB Mem : 16387132 total, 10854648 free, 1859036 used, 3673448 buff/cache
|
||||||
|
KiB Swap: 0 total, 0 free, 0 used. 14176540 avail Mem
|
||||||
|
|
||||||
|
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||||
|
17270 alan 20 0 3930764 247288 98992 R 0.7 1.5 5:58.22 gnome-shell
|
||||||
|
20496 alan 20 0 816144 45416 29844 S 0.5 0.3 0:22.16 gnome-terminal-
|
||||||
|
21110 alan 20 0 41940 3988 3188 R 0.1 0.0 0:00.17 top
|
||||||
|
1 root 20 0 225564 9416 6768 S 0.0 0.1 0:10.72 systemd
|
||||||
|
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
|
||||||
|
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H
|
||||||
|
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
|
||||||
|
7 root 20 0 0 0 0 S 0.0 0.0 0:00.08 ksoftirqd/0
|
||||||
|
```
|
||||||
|
|
||||||
|
The update interval can be changed by typing the letter **s** followed by the number of seconds you prefer for updates. To make it easier to monitor our example Nginx processes, we can call top and pass the PID(s) using the **-p** option. This output is much cleaner.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ top -p20881 -p20882 -p20895 -p20896
|
||||||
|
|
||||||
|
Tasks: 4 total, 0 running, 4 sleeping, 0 stopped, 0 zombie
|
||||||
|
%Cpu(s): 2.8 us, 1.3 sy, 0.0 ni, 95.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
|
||||||
|
KiB Mem : 16387132 total, 10856008 free, 1857648 used, 3673476 buff/cache
|
||||||
|
KiB Swap: 0 total, 0 free, 0 used. 14177928 avail Mem
|
||||||
|
|
||||||
|
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||||
|
20881 alan 20 0 12016 348 0 S 0.0 0.0 0:00.00 nginx
|
||||||
|
20882 alan 20 0 12460 1644 932 S 0.0 0.0 0:00.00 nginx
|
||||||
|
20895 alan 20 0 12016 352 0 S 0.0 0.0 0:00.00 nginx
|
||||||
|
20896 alan 20 0 12460 1628 912 S 0.0 0.0 0:00.00 nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
It is important to correctly determine the PID when managing processes, particularly stopping one. Also, if using top in this manner, any time one of these processes is stopped or a new one is started, top will need to be informed of the new ones.
|
||||||
|
|
||||||
|
### Stopping a process
|
||||||
|
|
||||||
|
#### KILL
|
||||||
|
|
||||||
|
Interestingly, there is no stop command. In Linux, there is the kill command. Kill is used to send a signal to a process. The most commonly used signal is "terminate" (SIGTERM) or "kill" (SIGKILL). However, there are many more. Below are some examples. The full list can be shown with **kill -L**.
|
||||||
|
```
|
||||||
|
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
|
||||||
|
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
|
||||||
|
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice signal number nine is SIGKILL. Usually, we issue a command such as **kill -9 20896**. The default signal is 15, which is SIGTERM. Keep in mind that many applications have their own method for stopping. Nginx uses a **-s** option for passing a signal such as "stop" or "reload." Generally, I prefer to use an application's specific method to stop an operation. However, I'll demonstrate the kill command to stop Nginx process 20896 and then confirm it is stopped with pgrep. The PID 20896 no longer appears.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ kill -9 20896
|
||||||
|
|
||||||
|
alan@workstation:~$ pgrep nginx
|
||||||
|
20881
|
||||||
|
20882
|
||||||
|
20895
|
||||||
|
22123
|
||||||
|
```
|
||||||
|
|
||||||
|
#### PKILL
|
||||||
|
|
||||||
|
The command pkill is similar to pgrep in that it can search by name. This means you have to be very careful when using pkill. In my example with Nginx, I might not choose to use it if I only want to kill one Nginx instance. I can pass the Nginx option **-s** **stop** to a specific instance to kill it, or I need to use grep to filter on the full ps output.
|
||||||
|
```
|
||||||
|
/home/alan/web/prod/nginx/sbin/nginx -s stop
|
||||||
|
|
||||||
|
/home/alan/web/prod/nginxsec/sbin/nginx -s stop
|
||||||
|
```
|
||||||
|
|
||||||
|
If I want to use pkill, I can include the **-f** option to ask pkill to filter across the full command line argument. This of course also applies to pgrep. So, first I can check with **pgrep -a** before issuing the **pkill -f**.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ pgrep -a nginx
|
||||||
|
20881 nginx: master process ./nginx -p /home/alan/web/prod/nginxsec
|
||||||
|
20882 nginx: worker process
|
||||||
|
20895 nginx: master process nginx
|
||||||
|
20896 nginx: worker process
|
||||||
|
```
|
||||||
|
|
||||||
|
I can also narrow down my result with **pgrep -f**. The same argument used with pkill stops the process.
|
||||||
|
```
|
||||||
|
alan@workstation:~$ pgrep -f nginxsec
|
||||||
|
20881
|
||||||
|
|
||||||
|
alan@workstation:~$ pkill -f nginxsec
|
||||||
|
```
|
||||||
|
|
||||||
|
The key thing to remember with pgrep (and especially pkill) is that you must always be sure that your search result is accurate so you aren't unintentionally affecting the wrong processes.
|
||||||
|
|
||||||
|
Most of these commands have many command line options, so I always recommend reading the [man page][1] on each one. While most of these exist across platforms such as Linux, Solaris, and BSD, there are a few differences. Always test and be ready to correct as needed when working at the command line or writing scripts.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/18/9/linux-commands-process-management
|
||||||
|
|
||||||
|
作者:[Alan Formy-Duval][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://opensource.com/users/alanfdoss
|
||||||
|
[1]: https://www.kernel.org/doc/man-pages/
|
@ -1,3 +1,5 @@
|
|||||||
|
translating---geekpi
|
||||||
|
|
||||||
Why I love Xonsh
|
Why I love Xonsh
|
||||||
======
|
======
|
||||||
|
|
||||||
|
290
sources/tech/20180905 5 tips to improve productivity with zsh.md
Normal file
290
sources/tech/20180905 5 tips to improve productivity with zsh.md
Normal file
@ -0,0 +1,290 @@
|
|||||||
|
5 tips to improve productivity with zsh
|
||||||
|
======
|
||||||
|
|
||||||
|
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/features_solutions_command_data.png?itok=4_VQN3RK)
|
||||||
|
|
||||||
|
The Z shell known as [zsh][1] is a [shell][2] for Linux/Unix-like operating systems. It has similarities to other shells in the `sh` (Bourne shell) family, such as as `bash` and `ksh`, but it provides many advanced features and powerful command line editing options, such as enhanced Tab completion.
|
||||||
|
|
||||||
|
It would be impossible to cover all the options of zsh here; there are literally hundreds of pages [documenting][3] its many features. In this article, I'll present five tips to make you more productive using the command line with zsh.
|
||||||
|
|
||||||
|
### 1\. Themes and plugins
|
||||||
|
|
||||||
|
Through the years, the open source community has developed countless themes and plugins for zsh. A theme is a predefined prompt configuration, while a plugin is a set of useful aliases and functions that make it easier to use a specific command or programming language.
|
||||||
|
|
||||||
|
The quickest way to get started using themes and plugins is to use a zsh configuration framework. There are many available, but the most popular is [Oh My Zsh][4]. By default, it enables some sensible zsh configuration options and it comes loaded with hundreds of themes and plugins.
|
||||||
|
|
||||||
|
A theme makes you more productive as it adds useful information to your prompt, such as the status of your Git repository or Python virtualenv in use. Having this information at a glance saves you from typing the equivalent commands to obtain it, and it's a cool look. Here's an example of [Powerlevel9k][5], my theme of choice:
|
||||||
|
|
||||||
|
![zsh Powerlevel9K theme][7]
|
||||||
|
|
||||||
|
The Powerlevel9k theme for zsh
|
||||||
|
|
||||||
|
In addition to themes, Oh My Zsh bundles tons of useful plugins for zsh. For example, enabling the Git plugin gives you access to a number of useful aliases, such as:
|
||||||
|
```
|
||||||
|
$ alias | grep -i git | sort -R | head -10
|
||||||
|
g=git
|
||||||
|
ga='git add'
|
||||||
|
gapa='git add --patch'
|
||||||
|
gap='git apply'
|
||||||
|
gdt='git diff-tree --no-commit-id --name-only -r'
|
||||||
|
gau='git add --update'
|
||||||
|
gstp='git stash pop'
|
||||||
|
gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
|
||||||
|
gcs='git commit -S'
|
||||||
|
glg='git log --stat'
|
||||||
|
```
|
||||||
|
|
||||||
|
There are plugins available for many programming languages, packaging systems, and other tools you commonly use on the command line. Here's a list of plugins I use in my Fedora workstation:
|
||||||
|
```
|
||||||
|
git golang fedora docker oc sudo vi-mode virtualenvwrapper
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2\. Clever aliases
|
||||||
|
|
||||||
|
Aliases are very useful in zsh. Defining aliases for your most-used commands saves you a lot of typing. Oh My Zsh configures several useful aliases by default, including aliases to navigate directories and replacements for common commands with additional options such as:
|
||||||
|
```
|
||||||
|
ls='ls --color=tty'
|
||||||
|
grep='grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}'
|
||||||
|
```
|
||||||
|
|
||||||
|
In addition to command aliases, zsh enables two additional useful alias types: the suffix alias and the global alias.
|
||||||
|
|
||||||
|
A suffix alias allows you to open the file you type in the command line using the specified program based on the file extension. For example, to open YAML files using vim, define the following alias:
|
||||||
|
```
|
||||||
|
alias -s {yml,yaml}=vim
|
||||||
|
```
|
||||||
|
|
||||||
|
Now if you type any file name ending with `yml` or `yaml` in the command line, zsh opens that file using vim:
|
||||||
|
```
|
||||||
|
$ playbook.yml
|
||||||
|
# Opens file playbook.yml using vim
|
||||||
|
```
|
||||||
|
|
||||||
|
A global alias enables you to create an alias that is expanded anywhere in the command line, not just at the beginning. This is very useful to replace common filenames or piped commands. For example:
|
||||||
|
```
|
||||||
|
alias -g G='| grep -i'
|
||||||
|
```
|
||||||
|
|
||||||
|
To use this alias, type `G` anywhere you would type the piped command:
|
||||||
|
```
|
||||||
|
$ ls -l G do
|
||||||
|
drwxr-xr-x. 5 rgerardi rgerardi 4096 Aug 7 14:08 Documents
|
||||||
|
drwxr-xr-x. 6 rgerardi rgerardi 4096 Aug 24 14:51 Downloads
|
||||||
|
```
|
||||||
|
|
||||||
|
Next, let's see how zsh helps to navigate the filesystem.
|
||||||
|
|
||||||
|
### 3\. Easy directory navigation
|
||||||
|
|
||||||
|
When you're using the command line, navigating across different directories is one of the most common tasks. Zsh makes this easier by providing some useful directory navigation features. These features are enabled with Oh My Zsh, but you can enable them by using this command:
|
||||||
|
```
|
||||||
|
setopt autocd autopushd \ pushdignoredups
|
||||||
|
```
|
||||||
|
|
||||||
|
With these options set, you don't need to type `cd` to change directories. Just type the directory name, and zsh switches to it:
|
||||||
|
```
|
||||||
|
$ pwd
|
||||||
|
/home/rgerardi
|
||||||
|
$ /tmp
|
||||||
|
$ pwd
|
||||||
|
/tmp
|
||||||
|
```
|
||||||
|
|
||||||
|
To move back, type `-`:
|
||||||
|
|
||||||
|
Zsh keeps the history of directories you visited so you can quickly switch to any of them. To see the list, type `dirs -v`:
|
||||||
|
```
|
||||||
|
$ dirs -v
|
||||||
|
0 ~
|
||||||
|
1 /var/log
|
||||||
|
2 /var/opt
|
||||||
|
3 /usr/bin
|
||||||
|
4 /usr/local
|
||||||
|
5 /usr/lib
|
||||||
|
6 /tmp
|
||||||
|
7 ~/Projects/Opensource.com/zsh-5tips
|
||||||
|
8 ~/Projects
|
||||||
|
9 ~/Projects/ansible
|
||||||
|
10 ~/Documents
|
||||||
|
```
|
||||||
|
|
||||||
|
Switch to any directory in this list by typing `~#` where # is the number of the directory in the list. For example:
|
||||||
|
```
|
||||||
|
$ pwd
|
||||||
|
/home/rgerardi
|
||||||
|
$ ~4
|
||||||
|
$ pwd
|
||||||
|
/usr/local
|
||||||
|
```
|
||||||
|
|
||||||
|
Combine these with aliases to make it even easier to navigate:
|
||||||
|
```
|
||||||
|
d='dirs -v | head -10'
|
||||||
|
1='cd -'
|
||||||
|
2='cd -2'
|
||||||
|
3='cd -3'
|
||||||
|
4='cd -4'
|
||||||
|
5='cd -5'
|
||||||
|
6='cd -6'
|
||||||
|
7='cd -7'
|
||||||
|
8='cd -8'
|
||||||
|
9='cd -9'
|
||||||
|
```
|
||||||
|
|
||||||
|
Now you can type `d` to see the first ten items in the list and the number to switch to it:
|
||||||
|
```
|
||||||
|
$ d
|
||||||
|
0 /usr/local
|
||||||
|
1 ~
|
||||||
|
2 /var/log
|
||||||
|
3 /var/opt
|
||||||
|
4 /usr/bin
|
||||||
|
5 /usr/lib
|
||||||
|
6 /tmp
|
||||||
|
7 ~/Projects/Opensource.com/zsh-5tips
|
||||||
|
8 ~/Projects
|
||||||
|
9 ~/Projects/ansible
|
||||||
|
$ pwd
|
||||||
|
/usr/local
|
||||||
|
$ 6
|
||||||
|
/tmp
|
||||||
|
$ pwd
|
||||||
|
/tmp
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally, zsh automatically expands directory names with Tab completion. Type the first letters of the directory names and `TAB` to use it:
|
||||||
|
```
|
||||||
|
$ pwd
|
||||||
|
/home/rgerardi
|
||||||
|
$ p/o/z (TAB)
|
||||||
|
$ Projects/Opensource.com/zsh-5tips/
|
||||||
|
```
|
||||||
|
|
||||||
|
This is just one of the features enabled by zsh's powerful Tab completion system. Let's look at some more.
|
||||||
|
|
||||||
|
### 4\. Advanced Tab completion
|
||||||
|
|
||||||
|
Zsh's powerful completion system is one of its hallmarks. For simplification, I call it Tab completion, but under the hood, more than one thing is happening. There's usually expansion and command completion. I'll discuss them together here. For details, check this [User's Guide][8].
|
||||||
|
|
||||||
|
Command completion is enabled by default with Oh My Zsh. To enable it, add the following lines to your `.zshrc` file:
|
||||||
|
```
|
||||||
|
autoload -U compinit
|
||||||
|
compinit
|
||||||
|
```
|
||||||
|
|
||||||
|
Zsh's completion system is smart. It tries to suggest only items that can be used in certain contexts—for example, if you type `cd` and `TAB`, zsh suggests only directory names as it knows `cd` does not work with anything else.
|
||||||
|
|
||||||
|
Conversely, it suggests usernames when running user-related commands or hostnames when using `ssh` or `ping`, for example.
|
||||||
|
|
||||||
|
It has a vast completion library and understands many different commands. For example, if you're using the `tar` command, you can press Tab to see a list of files available in the package as candidates for extraction:
|
||||||
|
```
|
||||||
|
$ tar -xzvf test1.tar.gz test1/file1 (TAB)
|
||||||
|
file1 file2
|
||||||
|
```
|
||||||
|
|
||||||
|
Here's a more advanced example, using `git`. In this example, when typing `TAB`, zsh automatically completes the name of the only file in the repository that can be staged:
|
||||||
|
```
|
||||||
|
$ ls
|
||||||
|
original plan.txt zsh-5tips.md zsh_theme_small.png
|
||||||
|
$ git status
|
||||||
|
On branch master
|
||||||
|
Your branch is up to date with 'origin/master'.
|
||||||
|
|
||||||
|
Changes not staged for commit:
|
||||||
|
(use "git add <file>..." to update what will be committed)
|
||||||
|
(use "git checkout -- <file>..." to discard changes in working directory)
|
||||||
|
|
||||||
|
modified: zsh-5tips.md
|
||||||
|
|
||||||
|
no changes added to commit (use "git add" and/or "git commit -a")
|
||||||
|
$ git add (TAB)
|
||||||
|
$ git add zsh-5tips.md
|
||||||
|
```
|
||||||
|
|
||||||
|
It also understands command line options and suggests only the ones that are relevant to the subcommand selected:
|
||||||
|
```
|
||||||
|
$ git commit - (TAB)
|
||||||
|
--all -a -- stage all modified and deleted paths
|
||||||
|
--allow-empty -- allow recording an empty commit
|
||||||
|
--allow-empty-message -- allow recording a commit with an empty message
|
||||||
|
--amend -- amend the tip of the current branch
|
||||||
|
--author -- override the author name used in the commit
|
||||||
|
--branch -- show branch information
|
||||||
|
--cleanup -- specify how the commit message should be cleaned up
|
||||||
|
--date -- override the author date used in the commit
|
||||||
|
--dry-run -- only show the list of paths that are to be committed or not, and any untracked
|
||||||
|
--edit -e -- edit the commit message before committing
|
||||||
|
--file -F -- read commit message from given file
|
||||||
|
--gpg-sign -S -- GPG-sign the commit
|
||||||
|
--include -i -- update the given files and commit the whole index
|
||||||
|
--interactive -- interactively update paths in the index file
|
||||||
|
--message -m -- use the given message as the commit message
|
||||||
|
... TRUNCATED ...
|
||||||
|
```
|
||||||
|
|
||||||
|
After typing `TAB`, you can use the arrow keys to navigate the options list and select the one you need. Now you don't need to memorize all those Git options.
|
||||||
|
|
||||||
|
There are many options available. The best way to find what is most helpful to you is by using it.
|
||||||
|
|
||||||
|
### 5\. Command line editing and history
|
||||||
|
|
||||||
|
Zsh's command line editing capabilities are also useful. By default, it emulates emacs. If, like me, you prefer vi/vim, enable vi bindings with the following command:
|
||||||
|
```
|
||||||
|
$ bindkey -v
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're using Oh My Zsh, the `vi-mode` plugin enables additional bindings and a mode indicator on your prompt—very useful.
|
||||||
|
|
||||||
|
After enabling vi bindings, you can edit the command line using vi commands. For example, press `ESC+/` to search the command line history. While searching, pressing `n` brings the next matching line, and `N` the previous one. Most common vi commands work after pressing `ESC` such as `0` to jump to the start of the line, `$` to jump to the end, `i` to insert, `a` to append, etc. Even commands followed by motion work, such as `cw` to change a word.
|
||||||
|
|
||||||
|
In addition to command line editing, zsh provides several useful command line history features if you want to fix or re-execute previous used commands. For example, if you made a mistake, typing `fc` brings the last command in your favorite editor to fix it. It respects the `$EDITOR` variable and by default uses vi.
|
||||||
|
|
||||||
|
Another useful command is `r`, which re-executes the last command; and `r <WORD>`, which executes the last command that contains the string `WORD`.
|
||||||
|
|
||||||
|
Finally, typing double bangs (`!!`) brings back the last command anywhere in the line. This is useful, for instance, if you forgot to type `sudo` to execute commands that require elevated privileges:
|
||||||
|
```
|
||||||
|
$ less /var/log/dnf.log
|
||||||
|
/var/log/dnf.log: Permission denied
|
||||||
|
$ sudo !!
|
||||||
|
$ sudo less /var/log/dnf.log
|
||||||
|
```
|
||||||
|
|
||||||
|
These features make it easier to find and re-use previously typed commands.
|
||||||
|
|
||||||
|
### Where to go from here?
|
||||||
|
|
||||||
|
These are just a few of the zsh features that can make you more productive; there are many more. For additional information, consult the following resources:
|
||||||
|
|
||||||
|
[An Introduction to the Z Shell][9]
|
||||||
|
|
||||||
|
[A User's Guide to ZSH][10]
|
||||||
|
|
||||||
|
[Archlinux Wiki][11]
|
||||||
|
|
||||||
|
[zsh-lovers][12]
|
||||||
|
|
||||||
|
Do you have any zsh productivity tips to share? I would love to hear about them in the comments below.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/18/9/tips-productivity-zsh
|
||||||
|
|
||||||
|
作者:[Ricardo Gerardi][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://opensource.com/users/rgerardi
|
||||||
|
[1]: http://www.zsh.org/
|
||||||
|
[2]: https://en.wikipedia.org/wiki/Shell_(computing)
|
||||||
|
[3]: http://zsh.sourceforge.net/Doc/Release/zsh_toc.html
|
||||||
|
[4]: https://ohmyz.sh/
|
||||||
|
[5]: https://github.com/bhilburn/powerlevel9k
|
||||||
|
[7]: https://opensource.com/sites/default/files/uploads/zsh_theme_small.png (zsh Powerlevel9K theme)
|
||||||
|
[8]: http://zsh.sourceforge.net/Guide/zshguide06.html#l144
|
||||||
|
[9]: http://zsh.sourceforge.net/Intro/intro_toc.html
|
||||||
|
[10]: http://zsh.sourceforge.net/Guide/
|
||||||
|
[11]: https://wiki.archlinux.org/index.php/zsh
|
||||||
|
[12]: https://grml.org/zsh/
|
@ -0,0 +1,66 @@
|
|||||||
|
8 great Python libraries for side projects
|
||||||
|
======
|
||||||
|
|
||||||
|
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/python-programming-code-keyboard.png?itok=fxiSpmnd)
|
||||||
|
|
||||||
|
We have a saying in the Python/Django world: We came for the language and stayed for the community. That is true for most of us, but something else that has kept us in the Python world is how easy it is to have an idea and quickly work through it over lunch or in a few hours at night.
|
||||||
|
|
||||||
|
This month we're diving into Python libraries we love to use to quickly scratch those side-project or lunchtime itches.
|
||||||
|
|
||||||
|
### To save data in a database on the fly: Dataset
|
||||||
|
|
||||||
|
[Dataset][1] is our go-to library when we quickly want to collect data and save it into a database before we know what our final database tables will look like. Dataset has a simple, yet powerful API that makes it easy to put data in and sort it out later.
|
||||||
|
|
||||||
|
Dataset is built on top of SQLAlchemy, so extending it will feel familiar. The underlying database models are a breeze to import into Django using Django's built-in [inspectdb][2] management command. This makes working with existing databases pretty painless.
|
||||||
|
|
||||||
|
### To scrape data from web pages: Beautiful Soup
|
||||||
|
|
||||||
|
[Beautiful Soup][3] (BS4 as of this writing) makes extracting information out of HTML pages easy. It's our go-to anytime we need to turn unstructured or loosely structured HTML into structured data. It's also great for working with XML data that might otherwise not be readable.
|
||||||
|
|
||||||
|
### To work with HTTP content: Requests
|
||||||
|
|
||||||
|
[Requests][4] is arguably one of the gold standard libraries for working with HTTP content. Anytime we need to consume an HTML page or even an API, Requests has us covered. It's also very well documented.
|
||||||
|
|
||||||
|
### To write command-line utilities: Click
|
||||||
|
|
||||||
|
When we need to write a native Python script, [Click][5] is our favorite library for writing command-line utilities. The API is straightforward, well thought out, and there are only a few patterns to remember. The docs are great, which makes looking up advanced features easy.
|
||||||
|
|
||||||
|
### To name things: Python Slugify
|
||||||
|
|
||||||
|
As we all know, naming things is hard. [Python Slugify][6] is a useful library for turning a title or description into a unique(ish) identifier. If you are working on a web project and you want to use SEO-friendly URLs, Python Slugify makes this easier.
|
||||||
|
|
||||||
|
### To work with plugins: Pluggy
|
||||||
|
|
||||||
|
[Pluggy][7] is relatively new, but it's also one of the best and easiest ways to add a plugin system to your existing application. If you have ever worked with pytest, you have used pluggy without knowing it.
|
||||||
|
|
||||||
|
### To convert CSV files into APIs: Datasette
|
||||||
|
|
||||||
|
[Datasette][8], not to be confused with Dataset, is an amazing tool for easily turning CSV files into full-featured read-only REST JSON APIs. Datasette has tons of features, including charting and geo (for creating interactive maps), and it's easy to deploy via a container or third-party web host.
|
||||||
|
|
||||||
|
### To handle environment variables and more: Envparse
|
||||||
|
|
||||||
|
If you need to parse environment variables because you don't want to save API keys, database credentials, or other sensitive information in your source code, then [envparse][9] is one of your best bets. Envparse handles environment variables, ENV files, variable types, and even pre- and post-processors (in case you want to ensure that a variable is always upper or lower case, for instance).
|
||||||
|
|
||||||
|
Do you have a favorite Python library for side projects that's not on this list? Please share it in the comments.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://opensource.com/article/18/9/python-libraries-side-projects
|
||||||
|
|
||||||
|
作者:[Jeff Triplett][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://opensource.com/users/laceynwilliams
|
||||||
|
[1]: https://dataset.readthedocs.io/en/latest/
|
||||||
|
[2]: https://docs.djangoproject.com/en/2.1/ref/django-admin/#django-admin-inspectdb
|
||||||
|
[3]: https://www.crummy.com/software/BeautifulSoup/
|
||||||
|
[4]: http://docs.python-requests.org/
|
||||||
|
[5]: http://click.pocoo.org/5/
|
||||||
|
[6]: https://github.com/un33k/python-slugify
|
||||||
|
[7]: https://pluggy.readthedocs.io/en/latest/
|
||||||
|
[8]: https://github.com/simonw/datasette
|
||||||
|
[9]: https://github.com/rconradharris/envparse
|
@ -0,0 +1,108 @@
|
|||||||
|
Find your systems easily on a LAN with mDNS
|
||||||
|
======
|
||||||
|
|
||||||
|
![](https://fedoramagazine.org/wp-content/uploads/2018/09/mDNS-816x345.jpg)
|
||||||
|
|
||||||
|
Multicast DNS, or mDNS, lets systems broadcast queries on a local network to find other resources by name. Fedora users often own multiple Linux systems on a router without sophisticated name services. In that case, mDNS lets you talk to your multiple systems by name — without touching the router in most cases. You also don’t have to keep files like /etc/hosts in sync on all the local systems. This article shows you how to set it up.
|
||||||
|
|
||||||
|
mDNS is a zero-configuration networking service that’s been around for quite a while. Fedora ships Avahi, a zero-configuration stack that includes mDNS, as part of Workstation. (mDNS is also part of Bonjour, found on Mac OS.)
|
||||||
|
|
||||||
|
This article assumes you have two systems running supported versions of Fedora (27 or 28). Their host names are meant to be castor and pollux.
|
||||||
|
|
||||||
|
### Installing packages
|
||||||
|
|
||||||
|
Make sure the nss-mdns and avahi packages are installed on your system. You might have a different version, which is fine:
|
||||||
|
```
|
||||||
|
$ rpm -q nss-mdns avahi
|
||||||
|
nss-mdns-0.14.1-1.fc28.x86_64
|
||||||
|
avahi-0.7-13.fc28.x86_64
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Fedora Workstation provides both of these packages by default. If not present, install them:
|
||||||
|
```
|
||||||
|
$ sudo dnf install nss-mdns avahi
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure the avahi-daemon.service unit is enabled and running. Again, this is the default on Fedora Workstation.
|
||||||
|
```
|
||||||
|
$ sudo systemctl enable --now avahi-daemon.service
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Although optional, you might also want to install the avahi-tools package. This package includes a number of handy utilities for checking how well the zero-configuration services on your system are working. Use this sudo command:
|
||||||
|
```
|
||||||
|
$ sudo dnf install avahi-tools
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The /etc/nsswitch.conf file controls which services your system uses to resolve services, and in what order. You should see a line like this in that file:
|
||||||
|
```
|
||||||
|
hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice the commands mdns4_minimal [NOTFOUND=return]. They tell your system to use the multicast DNS resolver to resolve a hostname to an IP address. Even if that service works, the remaining services are tried if the name doesn’t resolve.
|
||||||
|
|
||||||
|
If you don’t see a configuration similar to this, you can edit it (as the root user). However, the nss-mdns package handles this for you. Remove and reinstall that package to fix the file, if you’re uncomfortable editing it yourself.
|
||||||
|
|
||||||
|
Follow the steps above for **both systems**.
|
||||||
|
|
||||||
|
### Setting host name and testing
|
||||||
|
|
||||||
|
Now that you’ve done the common configuration work, set up each host’s name in one of these ways:
|
||||||
|
|
||||||
|
1. If you’re using Fedora Workstation, [you can use this procedure][1].
|
||||||
|
|
||||||
|
2. If not, use hostnamectl to do the honors. Do this for the first box:
|
||||||
|
```
|
||||||
|
$ hostnamectl set-hostname castor
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
3. You can also edit the /etc/avahi/avahi-daemon.conf file, remove the comment on the host-name setting line, and set the name there. By default, though, Avahi uses the system provided host name, so you **shouldn’t** need this method.
|
||||||
|
|
||||||
|
Next, restart the Avahi daemon so it picks up changes:
|
||||||
|
```
|
||||||
|
$ sudo systemctl restart avahi-daemon.service
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set your other box properly:
|
||||||
|
```
|
||||||
|
$ hostnamectl set-hostname pollux
|
||||||
|
$ sudo systemctl restart avahi-daemon.service
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
As long as your network router is not disallowing mDNS traffic, you should now be able to login to castor and ping the other box. You should use the default .local domain name so resolution works correctly:
|
||||||
|
```
|
||||||
|
$ ping pollux.local
|
||||||
|
PING pollux.local (192.168.0.1) 56(84) bytes of data.
|
||||||
|
64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=1 ttl=64 time=3.17 ms
|
||||||
|
64 bytes from 192.168.0.1 (192.168.0.1): icmp_seq=2 ttl=64 time=1.24 ms
|
||||||
|
...
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The same trick should also work from pollux if you ping castor.local. It’s much more convenient now to access your systems around the network!
|
||||||
|
|
||||||
|
Moreover, don’t be surprised if your router advertises services. Modern WiFi and wired routers often provide these services to make life easier for consumers.
|
||||||
|
|
||||||
|
This process works for most systems. However, if you run into trouble, use avahi-browse and other tools from the avahi-tools package to see what services are available.
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://fedoramagazine.org/find-systems-easily-lan-mdns/
|
||||||
|
|
||||||
|
作者:[Paul W. Frields][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://fedoramagazine.org/author/pfrields/
|
||||||
|
[1]: https://fedoramagazine.org/set-hostname-fedora/
|
@ -0,0 +1,253 @@
|
|||||||
|
How To Run MS-DOS Games And Programs In Linux
|
||||||
|
======
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/dosbox-720x340.png)
|
||||||
|
|
||||||
|
If you ever wanted to try some good-old MS-DOS games and defunct C++ compilers like Turbo C++ in Linux? Good! This tutorial will teach you how to run MS-DOS games and programs under Linux environment using **DOSBox**. It is an x86 PC DOS-emulator that can be used to run classic DOS games or programs. DOSBox emulates an Intel x86 PC with sound, graphics, mouse, joystick, and modem etc., that allows you to run many old MS-DOS games and programs that simply cannot be run on any modern PCs and operating systems, such as Microsoft Windows XP and later, Linux and FreeBSD. It is free, written using C++ programming language and distributed under GPL.
|
||||||
|
|
||||||
|
### Install DOSBox In Linux
|
||||||
|
|
||||||
|
DOSBox is available in the default repositories of most Linux distributions.
|
||||||
|
|
||||||
|
On Arch Linux and its variants like Antergos, Manjaro Linux:
|
||||||
|
```
|
||||||
|
$ sudo pacman -S dosbox
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
On Debian, Ubuntu, Linux Mint:
|
||||||
|
```
|
||||||
|
$ sudo apt-get install dosbox
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
On Fedora:
|
||||||
|
```
|
||||||
|
$ sudo dnf install dosbox
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configure DOSBox
|
||||||
|
|
||||||
|
There is no initial configuration required to use DOSBox and it just works out of the box. The default configuration file named `dosbox-x.xx.conf` exists in your **`~/.dosbox`** folder. In this configuration file, you can edit/modify various settings, such as starting DOSBox in fullscreen mode, use double buffering in fullscreen, set preferred resolution to use for fullscreen, mouse sensitivity, enable or disable sound, speaker, joystick and a lot more. As I mentioned earlier, the default settings will work just fine. You need not to make any changes.
|
||||||
|
|
||||||
|
### Run MS-DOS Games And Programs In Linux
|
||||||
|
|
||||||
|
To launch DOSBox, run the following command from the Terminal:
|
||||||
|
```
|
||||||
|
$ dosbox
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
This is how DOSBox interface looks like.
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt.png)
|
||||||
|
|
||||||
|
As you can see, DOSBox comes with its own DOS-like command prompt with a virtual `Z:\` Drive, so if you’re familiar with MS-DOS, you wouldn’t find any difficulties to work in DOSBox environment.
|
||||||
|
|
||||||
|
Here is the output of `dir`command (Equivalent of `ls` command in Linux) output:
|
||||||
|
|
||||||
|
![](http://www.ostechnix.com/wp-content/uploads/2018/09/dir-command-output.png)
|
||||||
|
|
||||||
|
If you’re a new user and it is the first time you use DOSBox, you can view the short introduction about DOSBox by entering the following command in DOSBox prompt:
|
||||||
|
```
|
||||||
|
intro
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Press ENTER to go through next page of the introduction section.
|
||||||
|
|
||||||
|
To view the list of most often used commands in DOS, use this command:
|
||||||
|
```
|
||||||
|
help
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
To view list of all supported commands in DOSBox, type:
|
||||||
|
```
|
||||||
|
help /all
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Remember, these commands should be used in the DOSBox prompt, not in your Linux Terminal.
|
||||||
|
|
||||||
|
DOSBox also supports a good set of keyboard bindings. Here is the default keyboard shortcuts to effectively use DOSBox.
|
||||||
|
|
||||||
|
![](http://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-keyboard-shortcuts.png)
|
||||||
|
|
||||||
|
To exit from DOSBox, simply type and hit ENTER:
|
||||||
|
```
|
||||||
|
exit
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, DOSBox starts with a normal window-sized screen like above.
|
||||||
|
|
||||||
|
To start dosbox directly in fullscreen, edit your `dosbox-x.xx.conf` file and set the value of **fullscreen** variable as **enable**. Now, DosBox will start in fullscreen mode. To go back to normal screen, press **ALT+ENTER**.
|
||||||
|
|
||||||
|
Hope you get the basic usage of DOSBox.
|
||||||
|
|
||||||
|
Let us go ahead and install some DOS programs and games.
|
||||||
|
|
||||||
|
First, we need to create directories to save the programs and games in our Linux system. I am going to create two directories named **`~/dosprograms`** and **`~/dosgames`** , the first one for storing programs and latter for storing games.
|
||||||
|
```
|
||||||
|
$ mkdir ~/dosprograms ~/dosgames
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
For the purpose of this guide, I will show you how to install **Turbo C++** program and Mario game. First, we will see how to install Turbo.
|
||||||
|
|
||||||
|
Download the latest Turbo C++ compiler, extract it and save the contents file in **`~/dosprograms`** directory. I have save the contents turbo c++ in my **~/dosprograms/TC/** directory.
|
||||||
|
```
|
||||||
|
$ ls dosprograms/tc/
|
||||||
|
BGI BIN CLASSLIB DOC EXAMPLES FILELIST.DOC INCLUDE LIB README README.COM
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Start Dosbox:
|
||||||
|
```
|
||||||
|
$ dosbox
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
And mount the **`~/dosprograms`** directory as virtual drive **C:\** in DOSBox.
|
||||||
|
```
|
||||||
|
Z:\>mount c ~/dosprograms
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
You will see an output something like below.
|
||||||
|
```
|
||||||
|
Drive C is mounted as local directory /home/sk/dosprograms.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-1.png)
|
||||||
|
|
||||||
|
Now, change to the C drive using command:
|
||||||
|
```
|
||||||
|
Z:\>c:
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
And then, switch to **tc/bin** directory:
|
||||||
|
```
|
||||||
|
Z:\>cd tc/bin
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally, run turbo c++ executable file:
|
||||||
|
```
|
||||||
|
Z:\>tc.exe
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note:** Just type first few letters and hit ENTER to autocomplete the file name.
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-4.png)
|
||||||
|
|
||||||
|
You will now be in Turbo C++ console.
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-5.png)
|
||||||
|
|
||||||
|
Create new file (ATL+F) and start coding:
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-6.png)
|
||||||
|
|
||||||
|
Similarly, you can install and run other classic DOS programs.
|
||||||
|
|
||||||
|
**Troubleshooting:**
|
||||||
|
|
||||||
|
You might be encountered with following error while running turbo c++ or any other dos programs:
|
||||||
|
```
|
||||||
|
DOSBox switched to max cycles, because of the setting: cycles=auto. If the game runs too fast try a fixed cycles amount in DOSBox's options. Exit to error: DRC64:Unhandled memory reference
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
To fix this, edit your **~/.dosbox/dosbox-x.xx.conf** file:
|
||||||
|
```
|
||||||
|
$ nano ~/.dosbox/dosbox-0.74.conf
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Find the following variable and change its value from:
|
||||||
|
```
|
||||||
|
core=auto
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
to
|
||||||
|
```
|
||||||
|
core=normal
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Save and close the file. Now you can be able to run the dos programs without any problems.
|
||||||
|
|
||||||
|
Now, let us see how to run a dos-based game, for example **Mario Bros VGA**.
|
||||||
|
|
||||||
|
Download Mario game from [**here**][1] and extract the contents in **~/dosgames** directory in your Linux machine.
|
||||||
|
|
||||||
|
Start DOSBox:
|
||||||
|
```
|
||||||
|
$ dosbox
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
We have used virtual drive **c:** for dos programs. For games, let us use **d:** as virtual drive.
|
||||||
|
|
||||||
|
At the DOSBox prompt, run the following command to mount **~/dosgames** directory as virtuald drive **d**.
|
||||||
|
```
|
||||||
|
Z:\>mount d ~/dosgames
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Switch to D: drive:
|
||||||
|
```
|
||||||
|
Z:\>d:
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
And then go to mario game directory and run the **mario.exe** file to launch the game.
|
||||||
|
```
|
||||||
|
Z:\>cd mario
|
||||||
|
|
||||||
|
Z:\>mario.exe
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/Dosbox-prompt-7.png)
|
||||||
|
|
||||||
|
Start playing the game:
|
||||||
|
|
||||||
|
![](https://www.ostechnix.com/wp-content/uploads/2018/09/Mario-game-in-dosbox.png)
|
||||||
|
|
||||||
|
Similarly, you can run any dos-based games as described above. You can view the complete list of supported games that can be run using DOSBox [**here**][2].
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
Even though DOSBOX is not a complete replacement for MS-DOS and it lacks many of the features found in MS-DOS, it is just enough to install and run most DOS games and programs.
|
||||||
|
|
||||||
|
For more details, refer the official [**DOSBox manual**][3].
|
||||||
|
|
||||||
|
And, that’s all for now. Hope this was useful. More good stuffs to come. Stay tuned!
|
||||||
|
|
||||||
|
Cheers!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://www.ostechnix.com/how-to-run-ms-dos-games-and-programs-in-linux/
|
||||||
|
|
||||||
|
作者:[SK][a]
|
||||||
|
选题:[lujun9972](https://github.com/lujun9972)
|
||||||
|
译者:[译者ID](https://github.com/译者ID)
|
||||||
|
校对:[校对者ID](https://github.com/校对者ID)
|
||||||
|
|
||||||
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
||||||
|
[a]: https://www.ostechnix.com/author/sk/
|
||||||
|
[1]: https://www.dosgames.com/game/mario-bros-vga
|
||||||
|
[2]: https://www.dosbox.com/comp_list.php
|
||||||
|
[3]: https://www.dosbox.com/DOSBoxManual.html
|
@ -1,58 +0,0 @@
|
|||||||
Linxu 虚拟机 vs Linux 实体机
|
|
||||||
======
|
|
||||||
首先我得承认,我非常倾向于频繁尝试新的[ linux 发行版本 ][1],我的目标是为了解决每一个 Linux 发行版的依赖,所以我用一些方法来测试它们。在一些文章中,我们将会看到两种运行 Linux 的模式,虚拟机或实体机。每一种方式都存在优势,但是有一些障碍会伴随着这两种方式。
|
|
||||||
|
|
||||||
### 第一时间测试一个新的 Linux 发行版
|
|
||||||
|
|
||||||
为了第一时间去做 Linux 发型版本的依赖测试,我把它们运行在我目前所拥有的所有类型的 PC 上。如果我用我的台式机,我将运行一个 Linux 虚拟机做测试。使用这种方法的原因是,不仅仅是生活环境下我可以下载测并测试发行版,但也会用稳定的生产环境安装。
|
|
||||||
|
|
||||||
在另一方面,如果我在工作中我的PC不具备强力的硬件条件的,在一个虚拟机上测试 Linux 发型版本的时候将会产生相反的效果。老实的讲,我会将电脑性能压榨到极限,如果在经济条件服务的情况下我会使用实体机运行 Linux 镜像替代虚拟机
|
|
||||||
|
|
||||||
### 在一个新的 Linux 发行版本上运行旅游软件
|
|
||||||
|
|
||||||
如果你有兴趣查看发行版本的桌面环境或购买软件,你不能因为发行版本的一个实时图片而诽谤它。一个生活环境提供给你希望的鸟瞰全局的视角,如何使用户体验更好是由应用程序提供的。
|
|
||||||
|
|
||||||
公平的说,一个虚拟化安装你也可以做同样的事,但是它有点不好,如果这么做你将要消除硬件上的许多数据。毕竟这是一个简单的发行版。记得我说过在第一部分-我做测试喜欢在虚拟机上运行 Linux 。这个方式我就能看见如何去安装它,使用镜像安装时你讲看不见有区别的操作和其他工作原理。
|
|
||||||
|
|
||||||
通常你仅能看见一个关于发行版本的简短介绍,关于功能用最少的阻力和时间投入,是解决这个问题的好办法。
|
|
||||||
|
|
||||||
### 随身携带一个
|
|
||||||
|
|
||||||
这个话题虽然不像几年前那样普遍,使用 Linux 发行版的能力可能是许多用户所顾虑的。明显,适合他们自己携带的系统,虚拟机是无法提供的。无论如何,一个 Linux 发行版本的镜像是具有可移植性的。一个镜像能够轻松的写入到 DVD 或者 Flash 存储设备中。
|
|
||||||
|
|
||||||
在 Linux 可移植性的概念上花费时间,这有益于在一个朋友的电脑上使用 Flash 存储设备安装镜像版 Linux 。这个授权使你能证明 Linux 能充实他们的生活,虽然在他们的 PC 上运行一个虚拟机是不可靠的。在喜爱使用镜像的用户哪里,它是双赢的。
|
|
||||||
|
|
||||||
### 选择做双系统 Linux
|
|
||||||
|
|
||||||
这是一个巨大的项目。考虑一些事,例如你在使用 Windows .你喜欢玩 Linux ,但是宁可不获取插件。在一些出状况或考虑你不是拥有单独分区,双系统将是一个问题。不管什么样的情况,同时使用 Linux 虚拟机和镜像系统都对于你是一个很好的选择。
|
|
||||||
|
|
||||||
现在,我在一些事物上采取奇怪的立场。长期运行 Linux 镜像在 Flash 存储或虚拟机,我知道你将为了更多的价值走更远。对于这个说法有两个原因。第一个,在 Windows 中安装一个虚拟机 VS 真正的运行的 Linux 。第二,用一个持续的存储设备你的 Flash 存储,安装 Linux 和你的数据。
|
|
||||||
|
|
||||||
我知道你会说用一个虚拟机运行 Linux 也是如此,无论如何你都无法升级到用镜像安装的地步。为什么?你不会更新你的宿主系统或者客户系统。记住,有一些发行 Linux 发行版本被设定为只能在持久存储中运行。Puppy Linux 就是一个非常好的例子。它仅能运行在个人 PC 上,否则它将进入死循环或被丢弃,它允许你永远不被单调的系统省级困扰,由于发行版会安全的处理这些更新。它不是一个正常的 Linux 发行版,有一个持久的免费镜像这样的方式用一堵墙个离开,多么可怕。
|
|
||||||
|
|
||||||
### Linux 虚拟机是一个绝好的选择
|
|
||||||
|
|
||||||
我就讲到这里,这篇文章是时候结束了。Virtual Box 绝对是一个非常不错的运行 Linux 虚拟机的虚拟化产品。
|
|
||||||
|
|
||||||
例如,我制作了一个录像,里面介绍和评论了许多 Linux 发行版。硬件安装或者虚拟机安装一个从 Linux 发行版镜像库获得的镜像,一个实时的操作我们需要通过屏幕去捕获它。很明显,虚拟机运行 Linux 和 镜像安装更适合。
|
|
||||||
|
|
||||||
一旦你需要在音频资料中采集到混音,这没有问题,那如果你用软件去采集你的信息,为了一个合理的采集环境,你将需要一个本地安装的系统,这里面包含了所有的基本要求。在一次,用一个硬件安装方式,但是这开销可能很大,如果你仅仅是用与视频和音频操作,这需要花费一部分时间。
|
|
||||||
|
|
||||||
### Linux 虚拟机 VS Linux 镜像
|
|
||||||
|
|
||||||
你最喜欢尝试新发行版的方式是那些?也许,你会格式化磁盘,然后豁出去了,因此,不需要任何理由
|
|
||||||
|
|
||||||
大多数人告诉我他们喜欢上面的方法,但是我很像知道哪种方式更加适合你。点击评论,让我知道在 Linux 发行世界最伟大和最新的版本时,您更喜欢哪种方法。
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://www.datamation.com/open-source/linux-virtual-machines-vs-linux-live-images.html
|
|
||||||
|
|
||||||
作者:[Matt Hartley][a]
|
|
||||||
译者:[sober-wang](https://github.com/译者ID)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]:https://www.datamation.com/author/Matt-Hartley-3080.html
|
|
||||||
[1]:https://www.datamation.com/open-source/best-linux-distro.html
|
|
@ -1,336 +0,0 @@
|
|||||||
如何在 Ubuntu 系统中添加一个辅助 IP 地址
|
|
||||||
======
|
|
||||||
|
|
||||||
Linux 管理员应该意识到这一点,因为这是一项例行任务。很多人想知道为什么我们需要在服务器中添加多个 IP 地址,以及为什么我们需要将它添加到单块网卡中?我说的对吗?
|
|
||||||
|
|
||||||
你可能也会有类似的问题:在 Linux 中如何为单块网卡分配多个 IP 地址?在本文中,你可以得到答案。
|
|
||||||
|
|
||||||
当我们对一个新服务器进行设置时,理想情况下它将有一个 IP 地址,即服务器主 IP 地址,它与服务器主机名对应。
|
|
||||||
|
|
||||||
我们不应在服务器主 IP 地址上托管任何应用程序,这是不可取的。如果要在服务器上托管任何应用程序,我们应该为此添加辅助 IP。
|
|
||||||
|
|
||||||
这是业界的最佳实践,它允许用户安装 SSL 证书。大多数系统都配有单块网卡,这足以添加额外的 IP 地址。
|
|
||||||
|
|
||||||
**建议阅读:**
|
|
||||||
**(#)** [在 Linux 命令行中 9 种方法检查公共 IP 地址][1]
|
|
||||||
**(#)** [在 Linux 终端中 3 种简单的方式来检查 DNS(域名服务器)记录][2]
|
|
||||||
**(#)** [在 Linux 上使用 Dig 命令检查 DNS(域名服务器)记录][3]
|
|
||||||
**(#)** [在 Linux 上使用 Nslookup 命令检查 DNS(域名服务器)记录][4]
|
|
||||||
**(#)** [在 Linux 上使用 Host 命令检查 DNS(域名服务器)记录][5]
|
|
||||||
|
|
||||||
我们可以在同一个接口上添加 IP 地址,或者在同一设备上创建子接口,然后在其中添加 IP。默认情况下,一直到 Ubuntu 14.04 LTS,接口给名称为 `ethX (eth0)`,但是从 Ubuntu 15.10 之后网络接口名称已从 `ethX` 更改为 `enXXXXX`(对于服务器是 ens33,桌面版是 enp0s3)。
|
|
||||||
|
|
||||||
在本文中,我们将教你如何在 Ubuntu 上执行此操作,并且衍生到其它发行版(to 校正:这句自己加的)。
|
|
||||||
|
|
||||||
**`注意:`**别在 DNS 详细信息后添加 IP 地址。如果是这样,DNS 将无法正常工作。
|
|
||||||
|
|
||||||
### 如何在 Ubuntu 14.04 LTS 中添加临时辅助 IP 地址
|
|
||||||
|
|
||||||
在系统中添加 IP 地址之前,运行以下任一命令即可验证服务器主 IP 地址:
|
|
||||||
```
|
|
||||||
# ifconfig
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
# ip addr
|
|
||||||
|
|
||||||
eth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36
|
|
||||||
inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0
|
|
||||||
inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link
|
|
||||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
|
||||||
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
|
|
||||||
TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
|
|
||||||
collisions:0 txqueuelen:1000
|
|
||||||
RX bytes:902 (902.0 B) TX bytes:16423 (16.4 KB)
|
|
||||||
|
|
||||||
eth1 Link encap:Ethernet HWaddr 08:00:27:6a:cf:d3
|
|
||||||
inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0
|
|
||||||
inet6 addr: fe80::a00:27ff:fe6a:cfd3/64 Scope:Link
|
|
||||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
|
||||||
RX packets:80 errors:0 dropped:0 overruns:0 frame:0
|
|
||||||
TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
|
|
||||||
collisions:0 txqueuelen:1000
|
|
||||||
RX bytes:8698 (8.6 KB) TX bytes:17047 (17.0 KB)
|
|
||||||
|
|
||||||
lo Link encap:Local Loopback
|
|
||||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
|
||||||
inet6 addr: ::1/128 Scope:Host
|
|
||||||
UP LOOPBACK RUNNING MTU:65536 Metric:1
|
|
||||||
RX packets:25 errors:0 dropped:0 overruns:0 frame:0
|
|
||||||
TX packets:25 errors:0 dropped:0 overruns:0 carrier:0
|
|
||||||
collisions:0 txqueuelen:1
|
|
||||||
RX bytes:1730 (1.7 KB) TX bytes:1730 (1.7 KB)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
如我所见,服务器主 IP 地址是 `192.168.56.150`,我将下一个 IP `192.168.56.151` 作为辅助 IP,使用以下方法完成:
|
|
||||||
```
|
|
||||||
# ip addr add 192.168.56.151/24 broadcast 192.168.56.255 dev eth0 label eth0:1
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
输入以下命令以检查新添加的 IP 地址。如果你重新启动服务器,那么新添加的 IP 地址会消失,因为我们的 IP 是临时添加的。
|
|
||||||
```
|
|
||||||
# ip addr
|
|
||||||
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
|
|
||||||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
|
||||||
inet 127.0.0.1/8 scope host lo
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet6 ::1/128 scope host
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
|
||||||
link/ether 08:00:27:98:b7:36 brd ff:ff:ff:ff:ff:ff
|
|
||||||
inet 192.168.56.150/24 brd 192.168.56.255 scope global eth0
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet 192.168.56.151/24 brd 192.168.56.255 scope global secondary eth0:1
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet6 fe80::a00:27ff:fe98:b736/64 scope link
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
3: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
|
||||||
link/ether 08:00:27:6a:cf:d3 brd ff:ff:ff:ff:ff:ff
|
|
||||||
inet 10.0.3.15/24 brd 10.0.3.255 scope global eth1
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet6 fe80::a00:27ff:fe6a:cfd3/64 scope link
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### 如何在 Ubuntu 14.04 LTS 中添加永久辅助 IP 地址
|
|
||||||
|
|
||||||
要在 Ubuntu 系统上添加永久辅助 IP 地址,只需编辑 `/etc/network/interfaces` 文件并添加所需的 IP 详细信息。
|
|
||||||
```
|
|
||||||
# vi /etc/network/interfaces
|
|
||||||
|
|
||||||
# The loopback network interface
|
|
||||||
auto lo
|
|
||||||
iface lo inet loopback
|
|
||||||
|
|
||||||
# The primary network interface
|
|
||||||
auto eth0
|
|
||||||
iface eth0 inet static
|
|
||||||
address 192.168.56.150
|
|
||||||
netmask 255.255.255.0
|
|
||||||
network 192.168.56.0
|
|
||||||
broadcast 192.168.56.255
|
|
||||||
gateway 192.168.56.1
|
|
||||||
|
|
||||||
auto eth0:1
|
|
||||||
iface eth0:1 inet static
|
|
||||||
address 192.168.56.151
|
|
||||||
netmask 255.255.255.0
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
保存并关闭文件,然后重启网络接口服务。
|
|
||||||
```
|
|
||||||
# service networking restart
|
|
||||||
or
|
|
||||||
# ifdown eth0:1 && ifup eth0:1
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
验证新添加的 IP 地址:
|
|
||||||
```
|
|
||||||
# ifconfig
|
|
||||||
eth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36
|
|
||||||
inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0
|
|
||||||
inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link
|
|
||||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
|
||||||
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
|
|
||||||
TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
|
|
||||||
collisions:0 txqueuelen:1000
|
|
||||||
RX bytes:962 (962.0 B) TX bytes:11905 (11.9 KB)
|
|
||||||
|
|
||||||
eth0:1 Link encap:Ethernet HWaddr 08:00:27:98:b7:36
|
|
||||||
inet addr:192.168.56.151 Bcast:192.168.56.255 Mask:255.255.255.0
|
|
||||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
|
||||||
|
|
||||||
eth1 Link encap:Ethernet HWaddr 08:00:27:6a:cf:d3
|
|
||||||
inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0
|
|
||||||
inet6 addr: fe80::a00:27ff:fe6a:cfd3/64 Scope:Link
|
|
||||||
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
|
||||||
RX packets:4924 errors:0 dropped:0 overruns:0 frame:0
|
|
||||||
TX packets:3185 errors:0 dropped:0 overruns:0 carrier:0
|
|
||||||
collisions:0 txqueuelen:1000
|
|
||||||
RX bytes:4037636 (4.0 MB) TX bytes:422516 (422.5 KB)
|
|
||||||
|
|
||||||
lo Link encap:Local Loopback
|
|
||||||
inet addr:127.0.0.1 Mask:255.0.0.0
|
|
||||||
inet6 addr: ::1/128 Scope:Host
|
|
||||||
UP LOOPBACK RUNNING MTU:65536 Metric:1
|
|
||||||
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
|
|
||||||
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
|
|
||||||
collisions:0 txqueuelen:1
|
|
||||||
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### 如何在 Ubuntu 16.04 LTS 中临时添加辅助 IP 地址
|
|
||||||
|
|
||||||
正如本文开头所述,网络接口名称从 Ubuntu 15.10 就开始从 ‘ethX’ 更改为 ‘enXXXX’ (enp0s3),所以,替换你的接口名称。
|
|
||||||
|
|
||||||
在执行此操作之前,先检查系统上的 IP 信息:
|
|
||||||
```
|
|
||||||
# ifconfig
|
|
||||||
or
|
|
||||||
# ip addr
|
|
||||||
|
|
||||||
enp0s3: flags=4163 mtu 1500
|
|
||||||
inet 192.168.56.201 netmask 255.255.255.0 broadcast 192.168.56.255
|
|
||||||
inet6 fe80::a00:27ff:fe97:132e prefixlen 64 scopeid 0x20
|
|
||||||
ether 08:00:27:97:13:2e txqueuelen 1000 (Ethernet)
|
|
||||||
RX packets 7 bytes 420 (420.0 B)
|
|
||||||
RX errors 0 dropped 0 overruns 0 frame 0
|
|
||||||
TX packets 294 bytes 24747 (24.7 KB)
|
|
||||||
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
|
||||||
|
|
||||||
enp0s8: flags=4163 mtu 1500
|
|
||||||
inet 10.0.3.15 netmask 255.255.255.0 broadcast 10.0.3.255
|
|
||||||
inet6 fe80::344b:6259:4dbe:eabb prefixlen 64 scopeid 0x20
|
|
||||||
ether 08:00:27:12:e8:c1 txqueuelen 1000 (Ethernet)
|
|
||||||
RX packets 1 bytes 590 (590.0 B)
|
|
||||||
RX errors 0 dropped 0 overruns 0 frame 0
|
|
||||||
TX packets 97 bytes 10209 (10.2 KB)
|
|
||||||
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
|
||||||
|
|
||||||
lo: flags=73 mtu 65536
|
|
||||||
inet 127.0.0.1 netmask 255.0.0.0
|
|
||||||
inet6 ::1 prefixlen 128 scopeid 0x10
|
|
||||||
loop txqueuelen 1000 (Local Loopback)
|
|
||||||
RX packets 325 bytes 24046 (24.0 KB)
|
|
||||||
RX errors 0 dropped 0 overruns 0 frame 0
|
|
||||||
TX packets 325 bytes 24046 (24.0 KB)
|
|
||||||
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
如我所见,服务器主 IP 地址是 `192.168.56.201`,所以,我将下一个 IP `192.168.56.202` 作为辅助 IP,使用以下命令完成。
|
|
||||||
```
|
|
||||||
# ip addr add 192.168.56.202/24 broadcast 192.168.56.255 dev enp0s3
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
运行以下命令来检查是否已分配了新的 IP。当你重启机器时,它会消失。
|
|
||||||
```
|
|
||||||
# ip addr
|
|
||||||
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
|
|
||||||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
|
||||||
inet 127.0.0.1/8 scope host lo
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet6 ::1/128 scope host
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
|
||||||
link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff
|
|
||||||
inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet6 fe80::a00:27ff:fe97:132e/64 scope link
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
|
||||||
link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff
|
|
||||||
inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8
|
|
||||||
valid_lft 86353sec preferred_lft 86353sec
|
|
||||||
inet6 fe80::344b:6259:4dbe:eabb/64 scope link
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### 如何在 Ubuntu 16.04 LTS 中添加永久辅助 IP 地址
|
|
||||||
|
|
||||||
要在 Ubuntu 系统上添加永久辅助 IP 地址,只需编辑 `/etc/network/interfaces` 文件并添加所需 IP 的详细信息。
|
|
||||||
|
|
||||||
我们不应该在 dns-nameservers 之后添加辅助 IP 地址,因为它不会起作用,应该以下面的格式添加 IP 详情。
|
|
||||||
|
|
||||||
此外,我们不需要添加子接口(我们之前在 Ubuntu 14.04 LTS 中的做法):
|
|
||||||
```
|
|
||||||
# vi /etc/network/interfaces
|
|
||||||
|
|
||||||
# interfaces(5) file used by ifup(8) and ifdown(8)
|
|
||||||
auto lo
|
|
||||||
iface lo inet loopback
|
|
||||||
|
|
||||||
# The primary network interface
|
|
||||||
auto enp0s3
|
|
||||||
iface enp0s3 inet static
|
|
||||||
address 192.168.56.201
|
|
||||||
netmask 255.255.255.0
|
|
||||||
|
|
||||||
iface enp0s3 inet static
|
|
||||||
address 192.168.56.202
|
|
||||||
netmask 255.255.255.0
|
|
||||||
|
|
||||||
gateway 192.168.56.1
|
|
||||||
network 192.168.56.0
|
|
||||||
broadcast 192.168.56.255
|
|
||||||
dns-nameservers 8.8.8.8 8.8.4.4
|
|
||||||
dns-search 2daygeek.local
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
保存并关闭文件,然后重启网络接口服务:
|
|
||||||
```
|
|
||||||
# systemctl restart networking
|
|
||||||
or
|
|
||||||
# ifdown enp0s3 && ifup enp0s3
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
运行以下命令来检查是否已经分配了新的 IP:
|
|
||||||
```
|
|
||||||
# ip addr
|
|
||||||
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
|
|
||||||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
|
|
||||||
inet 127.0.0.1/8 scope host lo
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet6 ::1/128 scope host
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
|
||||||
link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff
|
|
||||||
inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
inet6 fe80::a00:27ff:fe97:132e/64 scope link
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
|
|
||||||
link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff
|
|
||||||
inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8
|
|
||||||
valid_lft 86353sec preferred_lft 86353sec
|
|
||||||
inet6 fe80::344b:6259:4dbe:eabb/64 scope link
|
|
||||||
valid_lft forever preferred_lft forever
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
让我来 ping 一下新 IP 地址:
|
|
||||||
```
|
|
||||||
# ping 192.168.56.202 -c 4
|
|
||||||
PING 192.168.56.202 (192.168.56.202) 56(84) bytes of data.
|
|
||||||
64 bytes from 192.168.56.202: icmp_seq=1 ttl=64 time=0.019 ms
|
|
||||||
64 bytes from 192.168.56.202: icmp_seq=2 ttl=64 time=0.087 ms
|
|
||||||
64 bytes from 192.168.56.202: icmp_seq=3 ttl=64 time=0.034 ms
|
|
||||||
64 bytes from 192.168.56.202: icmp_seq=4 ttl=64 time=0.042 ms
|
|
||||||
|
|
||||||
--- 192.168.56.202 ping statistics ---
|
|
||||||
4 packets transmitted, 4 received, 0% packet loss, time 3068ms
|
|
||||||
rtt min/avg/max/mdev = 0.019/0.045/0.087/0.026 ms
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
via: https://www.2daygeek.com/how-to-add-additional-ip-secondary-ip-in-ubuntu-debian-system/
|
|
||||||
|
|
||||||
作者:[Prakash Subramanian][a]
|
|
||||||
选题:[lujun9972](https://github.com/lujun9972)
|
|
||||||
译者:[MjSeven](https://github.com/MjSeven)
|
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
||||||
|
|
||||||
[a]:https://www.2daygeek.com/author/prakash/
|
|
||||||
[1]:https://www.2daygeek.com/check-find-server-public-ip-address-linux/
|
|
||||||
[2]:https://www.2daygeek.com/check-find-dns-records-of-domain-in-linux-terminal/
|
|
||||||
[3]:https://www.2daygeek.com/dig-command-check-find-dns-records-lookup-linux/
|
|
||||||
[4]:https://www.2daygeek.com/nslookup-command-check-find-dns-records-lookup-linux/
|
|
||||||
[5]:https://www.2daygeek.com/host-command-check-find-dns-records-lookup-linux/
|
|
Loading…
Reference in New Issue
Block a user